You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find that we can use luajit ffi to call win32api to control keyboard layout and ime state on Windows, without the burden of a extra binary and another language pack.
I'm not a pro coder yet, so I'm not confident enough to make a good pull request.
Below code is my personal config which doesn't support switching between keyboard-layouts, I think it's doable by similar method.
If a pull request is needed, I can try to read im-select.nvim's source code and make a configurable pull request.
Feel free to use below code with ❤️
-- Reference:-- https://www.cnblogs.com/yf-zhao/p/16018481.html-- https://zhuanlan.zhihu.com/p/425951648localffi=require"ffi"ffi.cdef[[typedefunsignedint UINT, HWND, WPARAM;
typedefunsignedlong LPARAM, LRESULT;
LRESULT SendMessageA(HWNDhWnd, UINTMsg, WPARAMwParam, LPARAMlParam);
HWND ImmGetDefaultIMEWnd(HWNDunnamedParam1);
HWND GetForegroundWindow();
]]localuser32=ffi.load"user32.dll"localimm32=ffi.load"imm32.dll"localime_hwndlocalime_group=vim.api.nvim_create_augroup("ime_toggle", { clear=true })
-- Get ime control's hwnd after InsertEnter or CmdlineEnter-- to ensure getting correct foregroundwindowvim.api.nvim_create_autocmd({ "InsertEnter", "CmdlineEnter" }, {
group=ime_group,
once=true,
desc="Get ime control hwnd attached to nvim window",
callback=function()
ime_hwnd=imm32.ImmGetDefaultIMEWnd(user32.GetForegroundWindow())
end,
})
localWM_IME_CONTROL=0x283localIMC_GETCONVERSIONMODE=0x001localIMC_SETCONVERSIONMODE=0x002-- It's said this value differs on different ime, I'm not surelocalime_mode_ch=1025localime_mode_en=0localfunctionset_ime_mode(mode)
returnuser32.SendMessageA(ime_hwnd, WM_IME_CONTROL, IMC_SETCONVERSIONMODE, mode)
endlocalfunctionget_ime_mode()
returnuser32.SendMessageA(ime_hwnd, WM_IME_CONTROL, IMC_GETCONVERSIONMODE, 0)
endvim.api.nvim_create_autocmd({ "InsertLeave", "CmdlineLeave" }, {
group=ime_group,
desc="Toggle ime to English mode on normal mode",
callback=function()
ifime_mode_ch==get_ime_mode() thenset_ime_mode(ime_mode_en)
endend,
})
The text was updated successfully, but these errors were encountered:
I find that we can use luajit ffi to call win32api to control keyboard layout and ime state on Windows, without the burden of a extra binary and another language pack.
I'm not a pro coder yet, so I'm not confident enough to make a good pull request.
Below code is my personal config which doesn't support switching between keyboard-layouts, I think it's doable by similar method.
If a pull request is needed, I can try to read im-select.nvim's source code and make a configurable pull request.
Feel free to use below code with ❤️
The text was updated successfully, but these errors were encountered: