My editing steps:
- Type some Chinese words in insert mode.
- Press
<esc>back to normal mode. - Press
<shift>change input method to English. - Press keys in normal mode.
I want implement "Press <esc> back to normal mode and also change input method to English.".
In windows, Xshell have advance option implement just what I want. But after OS update, Xshell does not work right.
I also need this function in Linux. I has a Raspberry pi 4 running Raspbian OS. I use Terminator in Raspbian.
How can I implement this in Win10 and Raspbian?
I found a way to work on windows10. (Have not test other windows os).
In my win10 settings, I only have chinese pinyin input method, no others.
The idea is below.
pynputlisten to<esc>key release.pywin32andctypesto find current focus window.ctypeswithimm32DLL to get current language type.pywin32send message to focus window change language to english if current is chinese.The code puts below.
The difficult part is to get current focus window.
win32gui.FindWindowandwin32gui.FindWindowExcan't search the child windows.win32gui.EnumChildWindowcan do the work, but it's too slow for xshell.GetFocusjust return 0, I don't know why.GetGUIThreadInfoworks well, but not wrapped bypywin32. I found a way to wrap it in this link. This is the method I use.