---
title: "Discussion on \"Lang Switcher: A Keyboard Layout Switcher With an Undo Key\" | Hashnode"
description: "Discussion on \"Lang Switcher: A Keyboard Layout Switcher With an Undo Key\". Lang Switcher fixes a word typed in the wrong layout when you press Pause — and a second press puts your original text back. Open source, written in Rust."
url: "https://hashnode.com/posts/lang-switcher-keyboard-layout-switcher-undo-key/6af32351cbcd6f3a5ecbe931"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Lang Switcher: A Keyboard Layout Switcher With an Undo Key](https://panda-devblog.hashnode.dev/lang-switcher-keyboard-layout-switcher-undo-key?utm_source=hashnode&utm_medium=feed)

Lang Switcher fixes a word typed in the wrong layout when you press Pause — and a second press puts your original text back. Open source, written in Rust.

Nov 10 · 8 min read · panda-devblog.hashnode.dev  
Read the article

-   [#rust](https://hashnode.com/tag/rust)
-   [#windows](https://hashnode.com/tag/windows)
-   [#open-source](https://hashnode.com/tag/open-source)
-   [#developer-tools](https://hashnode.com/tag/developer-tools)
-   [#productivity](https://hashnode.com/tag/productivity)

## Written by

[Panda Koder](https://hashnode.com/@panda-pishet-kod)

@panda-pishet-kod

  
[View profile](https://hashnode.com/@panda-pishet-kod)

Building Lang Switcher in Rust and Win32: one key fixes text typed in the wrong layout

I’m Panda Koder, a solo developer. I write Windows utilities in Rust right on top of the Win32 API, plus small tools that run in the browser. My main project is Lang Switcher: you type руддщ when you meant hello, press Pause, and it fixes the last word and switches the keyboard layout. It’s open source (MIT or Apache-2.0), sends no telemetry and never writes keystrokes to disk. Here I post notes on Windows input, keyboard layouts and the code behind them.

## Responses 2

Markdown supported · ⌘↵ to post

[c-wind](https://hashnode.com/@c-wind)

[6d ago](https://hashnode.com/posts/lang-switcher-keyboard-layout-switcher-undo-key/6af32351cbcd6f3a5ecbe931/comment/6af466cb852156dd76954b44)

The keystroke-buffer approach is the right one for layout conversion; a character-level table would fall over on Shift+2 immediately, as you show. The part I would tighten is the fail-open on unknown field types: if UI Automation can't tell whether a field is a password, I'd rather treat it as one (no buffer, thud on Pause) than risk keeping keystrokes from a custom password widget. The console rule of never using Ctrl+C to read a selection is the same kind of conservative default, and it fits the rest of the design well.

[Panda Koder](https://hashnode.com/@panda-pishet-kod)

[5d ago](https://hashnode.com/posts/lang-switcher-keyboard-layout-switcher-undo-key/6af32351cbcd6f3a5ecbe931/comment/6af466cb852156dd76954b44#reply-6af57eebb354e8da918b19e4)

Thanks — glad the Shift+2 example made the case.

I'm keeping the default as it is, on purpose. If "unknown" meant "password", the program would fall silent in most Electron apps and web pages, where UI Automation answers slowly — it would stop doing its one job exactly where people type the most.

Your worry about missed password fields was fair, though, and not only in theory. Up to 1.4.4 the program failed to recognise password fields in WinForms programs, and in Edge, Chrome and Firefox when you reached the field with Tab. That wasn't a timeout: the checks gave a wrong answer, so a fail-closed default wouldn't have caught it either. 1.5.0 fixes it — the program now listens to UI Automation focus events as well as asking EM\_GETPASSWORDCHAR. And in a password field, Pause now only switches the layout; it never converts what was typed.

What it keeps in ordinary fields stays in memory only: never written to disk, a log or a crash dump, and overwritten with zeros at every reset. If an app has its own password widget that slips past the checks, put the app on the exclusion list, and nothing typed there is kept at all.
