dotSwitcher icon indicating copy to clipboard operation
dotSwitcher copied to clipboard

How it works?

Open ghost opened this issue 9 years ago • 5 comments
trafficstars

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.

ghost avatar Dec 11 '15 16:12 ghost

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.Count is (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
  • 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:

kurumpa avatar Dec 14 '15 12:12 kurumpa

THANKS A LOT >.<

ghost avatar Dec 16 '15 17:12 ghost

Inspired by your project i created my own, see it and say what you think.

ghost avatar Mar 29 '16 17:03 ghost

That's great! :metal:

kurumpa avatar Mar 30 '16 07:03 kurumpa

Glad you like it.

ghost avatar Mar 31 '16 21:03 ghost