dotSwitcher
dotSwitcher copied to clipboard
How it works?
I looked on the source code for a loooong time, but i just don't get how it works... I mean, i don't see how it convert words :/ I know that it somehow add inputted chars to list currentword and what it does after it i don't know. Please explait it step by step.
I'm not sure, if the development branch is buildable at all :) try to look at master branch, the whole idea haven't changed since then.
First of all, the app attaches a handler to a WinApi hook:
hookId = LowLevelAdapter.SetHook(LowLevelAdapter.WH_KEYBOARD_LL, keyboardEventHook);
The handler ProcessKeyboardEvent gathers information about the keypress and sends it to a KeyboardHook.KeyboardEvent event handler which is set in the initialization of Switcher class:
kbdHook.KeyboardEvent += ProcessKeyPress;
The magic itself happens inside the method Switcher.OnKeyPress(KeyboardEventArgs evtData) and is pretty straightforward:
- if pressed a letter (or any printable character), then keypress data is added to a list
currentWord. - if detected a switch hotkey, then
- send as many "backspaces" as
currentWord.Countis (to erase the word in a wrong layout) - send
WM_INPUTLANGCHANGEREQUEST(or the current layout switch system hotkey) - re-send all the keypresses recorded in
currentWord
- send as many "backspaces" as
- otherwise (non-printable characters, sys keys, mouse clicks, hotkeys etc.) - empty the
currentWord(begin a new "word")
Convertion of the selected text is performed in a similar way:
- Send
Ctrl+C(as it is the only reliable way to get the selected text) - Convert text to keypresses
- Send
WM_INPUTLANGCHANGEREQUEST - Re-send keypresses
Feel free to ask any further questions and thanks for your time :beers:
THANKS A LOT >.<
Inspired by your project i created my own, see it and say what you think.
That's great! :metal:
Glad you like it.