Saved_Key_State := Ime().getStatus() ; 한글 상태일 때 true VIM_Command_Mode := false /** * @author zero-plusplus (https://github.com/zero-plusplus) * @licence MIT * @link https://gist.github.com/zero-plusplus/ad54d19d3e0d34587396c4667fa10079 */ /** * This class provides static methods for getting/setting the state of the [Input Method Editor (IME)](https://en.wikipedia.org/wiki/Input_method). */ class Ime { /** * Get/Set IME status. Enable if `true` IME status, disable if `false`. * @static * @type {boolean} */ status { get { return this.get() } set { return this.set(value) } } /** * Get a boolean value indicating whether the IME is enabled or disabled. * @return {boolean} */ getStatus() { static IMC_GETOPENSTATUS := 0x0005 return !!(this._sendMessage(IMC_GETOPENSTATUS)) } /** * Set the IME status. * @static * @param {boolean} status - Enable if `true`, disable if `false`. * @throws Error - Throw an exception if the state setting fails. */ setStatus(status) { static IMC_SETOPENSTATUS := 0x006 errorCode := this._sendMessage(IMC_SETOPENSTATUS, status) if (0 < errorCode) { ; throw Exception("Failed to set status. code: " errorCode) } } /** * Common process for sending SendMessage. * @private * @static * @param {number} wParam * @param {number} [lParam := 0] */ _sendMessage(wParam, lParam := 0) { static WM_IME_CONTROL := 0x0283 return DllCall( "SendMessage" , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "Uint", WinActive("A")) , "UInt", msg := WM_IME_CONTROL , "Int", wParam , "Int", lParam ) } } #HotIF WinActive("ahk_exe Code.exe") | WinActive("ahk_exe Obsidian.exe") Esc:: { global VIM_Command_Mode global Saved_Key_State bHangul := Ime().getStatus() if bHangul ; 현재 한글키이면, { Send "{vk15sc138}" ; 한/영 변환키 누르기 } Send "{Esc}" ; V2 VIM_Command_Mode := true Saved_Key_State := bHangul return } /* 입력모드로 들어갈 때 이전 한영키로 전환 */ i:: +i:: ; I o:: +o:: ; O a:: +a:: ; A { global VIM_Command_Mode global Saved_Key_State ; MsgBox Format("i - {1}, {2}", VIM_Command_Mode, Saved_Key_State) ; Debugging messsage Send A_ThisHotkey if VIM_Command_Mode { ; Ime().setStatus(Saved_Key_State) if Saved_Key_State ; 편집모드에서 한글 키였으면 { Send "{vk15sc138}" ; 한/영 변환키 누르기 } VIM_Command_Mode := false } return } /* Debugging Stuffs */ #HotIF ; ^1:: ; { ; MsgBox Ime().getStatus() ; } ; ^2:: ; { ; Ime().setStatus(true) ; } ; ^3:: ; { ; Ime().setStatus(false) ; } ; ^4:: ; { ; Send "{vk15sc138}" ; 한/영 변환키 누르기, V2 ; }