├── .gitignore ├── LICENSE ├── README.md ├── build.sh └── main.cc /.gitignore: -------------------------------------------------------------------------------- 1 | /zenhan 2 | *.zip 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zenhan 2 | 3 | Switch the mode of input method editor from terminal. This is a tool similar to im-select. 4 | 5 | see https://github.com/VSCodeVim/Vim#input-method 6 | 7 | ## Setting example 8 | 9 | ``` 10 | "vim.autoSwitchInputMethod.enable": true, 11 | "vim.autoSwitchInputMethod.defaultIM": "0", 12 | "vim.autoSwitchInputMethod.obtainIMCmd": "D:\\bin\\zenhan.exe", 13 | "vim.autoSwitchInputMethod.switchIMCmd": "D:\\bin\\zenhan.exe {im}" 14 | ``` 15 | 16 | ## see also 17 | 18 | [Qiita (Japanese)](https://qiita.com/iuchi/items/9ddcfb48063fc5ab626c) 19 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p zenhan/bin64 3 | mkdir -p zenhan/bin32 4 | 5 | out=zenhan/bin64/zenhan.exe 6 | x86_64-w64-mingw32-g++-win32 -std=c++11 -mwindows main.cc -o $out -limm32 7 | x86_64-w64-mingw32-strip $out 8 | 9 | out=zenhan/bin32/zenhan.exe 10 | i686-w64-mingw32-g++-win32 -std=c++11 -mwindows -static-libgcc main.cc -o $out -limm32 11 | i686-w64-mingw32-strip $out 12 | 13 | zip -r9 zenhan.zip zenhan/ 14 | -------------------------------------------------------------------------------- /main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(int argc, char** argv) 7 | { 8 | constexpr LPARAM IMC_GETOPENSTATUS = 5; 9 | constexpr LPARAM IMC_SETOPENSTATUS = 6; 10 | 11 | auto hwnd = GetForegroundWindow(); 12 | if (!hwnd) 13 | return 0; 14 | 15 | auto ime = ImmGetDefaultIMEWnd(hwnd); 16 | if (!ime) 17 | return 0; 18 | 19 | LPARAM stat; 20 | if (argc < 2) { 21 | stat = SendMessage(ime, WM_IME_CONTROL, IMC_GETOPENSTATUS, 0); 22 | } else { 23 | stat = std::atoi(argv[1]); 24 | SendMessage(ime, WM_IME_CONTROL, IMC_SETOPENSTATUS, stat); 25 | } 26 | std::printf("%d\n", stat); 27 | return 0; 28 | } 29 | --------------------------------------------------------------------------------