From 384830889b91d739fbf301c06c46a5142e7f8480 Mon Sep 17 00:00:00 2001 From: KIHARA Hideto Date: Wed, 26 Feb 2014 08:16:51 +0900 Subject: [PATCH] =?UTF-8?q?Win8=E3=81=A7=E4=BB=96IME=20OFF=E5=88=87?= =?UTF-8?q?=E6=9B=BF=E3=81=97=E3=81=A6=E3=82=82ON=E5=88=87=E6=9B=BF?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=82=8B=E7=8F=BE=E8=B1=A1=E5=9B=9E=E9=81=BF?= =?UTF-8?q?=E3=81=AE=E3=81=9F=E3=82=81=E3=80=81OFF=E3=82=AD=E3=83=BC?= =?UTF-8?q?=E9=80=81=E4=BB=98=E5=89=8D=E3=81=ABwait=E3=82=92=E5=85=A5?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/configxml.cpp | 1 + common/configxml.h | 1 + imcrvtip/FnConfigure.cpp | 3 ++ imcrvtip/KeyEventSink.cpp | 4 +-- imcrvtip/TextService.cpp | 2 +- imcrvtip/TextService.h | 1 + imcrvtip/ViKeyHandler.cpp | 57 ++++++++++++++++++++++++++-------- imcrvtip/ViKeyHandler.h | 4 +-- imvimcnf/DlgProcBehavior2.cpp | 20 ++++++++++++ imvimcnf/imvimcnf.rc | Bin 5868 -> 6178 bytes imvimcnf/resource.h | 1 + 11 files changed, 76 insertions(+), 18 deletions(-) diff --git a/common/configxml.cpp b/common/configxml.cpp index ceabe39..a7b652f 100644 --- a/common/configxml.cpp +++ b/common/configxml.cpp @@ -24,6 +24,7 @@ LPCWSTR SectionBehavior = L"behavior"; LPCWSTR ValueOtherIme1 = L"otherime1"; LPCWSTR ValueOtherIme2 = L"otherime2"; +LPCWSTR ValueOtherImeOffWait = L"otherimeoffwait"; //preservedkey section diff --git a/common/configxml.h b/common/configxml.h index 7b737c2..1843284 100644 --- a/common/configxml.h +++ b/common/configxml.h @@ -55,6 +55,7 @@ extern LPCWSTR SectionBehavior; extern LPCWSTR ValueOtherIme1; extern LPCWSTR ValueOtherIme2; +extern LPCWSTR ValueOtherImeOffWait; //preservedkey section diff --git a/imcrvtip/FnConfigure.cpp b/imcrvtip/FnConfigure.cpp index 097f19e..9edbca4 100644 --- a/imcrvtip/FnConfigure.cpp +++ b/imcrvtip/FnConfigure.cpp @@ -114,6 +114,9 @@ void CTextService::_LoadBehavior() { c_otherime2 = 0; } + + ReadValue(pathconfigxml, SectionBehavior, ValueOtherImeOffWait, strxmlval); + c_otherimeoffwait = wcstol(strxmlval.c_str(), NULL, 0); } static bool operator ==(const TF_PRESERVEDKEY &a, const TF_PRESERVEDKEY &b) { diff --git a/imcrvtip/KeyEventSink.cpp b/imcrvtip/KeyEventSink.cpp index 5851ef4..feefb08 100644 --- a/imcrvtip/KeyEventSink.cpp +++ b/imcrvtip/KeyEventSink.cpp @@ -129,13 +129,13 @@ STDAPI CTextService::OnPreservedKey(ITfContext *pic, REFGUID rguid, BOOL *pfEate } else if(IsEqualGUID(rguid, c_guidPreservedKeyOtherIme)) { - vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, FALSE); + vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, FALSE, c_otherimeoffwait); _SetKeyboardOpen(FALSE); *pfEaten = TRUE; } else if(IsEqualGUID(rguid, c_guidPreservedKeyOtherImeOff)) { - vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, TRUE); + vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, TRUE, c_otherimeoffwait); _SetKeyboardOpen(FALSE); *pfEaten = TRUE; } diff --git a/imcrvtip/TextService.cpp b/imcrvtip/TextService.cpp index 52010f6..abd5714 100644 --- a/imcrvtip/TextService.cpp +++ b/imcrvtip/TextService.cpp @@ -3,7 +3,7 @@ #include "TextService.h" CTextService::CTextService() - : vihandler(this) + : vihandler(this), c_otherimeoffwait(0) { DllAddRef(); diff --git a/imcrvtip/TextService.h b/imcrvtip/TextService.h index 262d1ba..42b5134 100644 --- a/imcrvtip/TextService.h +++ b/imcrvtip/TextService.h @@ -153,6 +153,7 @@ class CTextService : //動作設定 WCHAR c_otherime1; //他IMEへの切替え用に送付するキーシーケンス1 int c_otherime2; //他IMEへの切替え用に送付するキーシーケンス2 + int c_otherimeoffwait; //他IME切替後、OFFモード切替送付待ち時間[ms] //preserved key TF_PRESERVEDKEY preservedkeynormal[MAX_PRESERVEDKEY]; diff --git a/imcrvtip/ViKeyHandler.cpp b/imcrvtip/ViKeyHandler.cpp index 4cdaded..ed46785 100644 --- a/imcrvtip/ViKeyHandler.cpp +++ b/imcrvtip/ViKeyHandler.cpp @@ -383,7 +383,7 @@ void ViKeyHandler::_QueueEndOfSelfSendKey(vector *inputs) } } -void ViKeyHandler::_SendInputs(vector *inputs) +void ViKeyHandler::_SendInputs(vector *inputs, vector *inputs2, int waitms) { // cf. deleter.UnsetModifiers() mozc::win32::KeyboardStatus keyboard_state; @@ -399,11 +399,14 @@ void ViKeyHandler::_SendInputs(vector *inputs) to_be_updated = true; keyboard_state.SetState(VK_SHIFT, kUnsetState); _QueueKeyForModifier(inputs, VK_SHIFT, TRUE, TRUE); - // restore modifier - // XXX:SendInput()直後にdeleter.EndDeletion()を呼んでも、 - // CTRL-F押下時にVK_NEXT送り付けても動かない - // (おそらくCTRL押下状態になってCTRL-NEXTになるため) - _QueueKeyForModifier(inputs, VK_SHIFT, FALSE); + if (inputs2 == NULL) + { + // restore modifier + // XXX:SendInput()直後にdeleter.EndDeletion()を呼んでも、 + // CTRL-F押下時にVK_NEXT送り付けても動かない + // (おそらくCTRL押下状態になってCTRL-NEXTになるため) + _QueueKeyForModifier(inputs, VK_SHIFT, FALSE); + } } if (keyboard_state.IsPressed(VK_CONTROL)) { @@ -411,15 +414,31 @@ void ViKeyHandler::_SendInputs(vector *inputs) to_be_updated = true; keyboard_state.SetState(VK_CONTROL, kUnsetState); _QueueKeyForModifier(inputs, VK_CONTROL, TRUE, TRUE); - _QueueKeyForModifier(inputs, VK_CONTROL, FALSE); + if (inputs2 == NULL) + { + _QueueKeyForModifier(inputs, VK_CONTROL, FALSE); + } } if (to_be_updated) { keyboard_->SetKeyboardState(keyboard_state); } } - keyboard_->SendInput(*inputs); + + if (inputs2 != NULL) + { + if (shiftPressed) + { + _QueueKeyForModifier(inputs2, VK_SHIFT, FALSE); + } + if (controlPressed) + { + _QueueKeyForModifier(inputs2, VK_CONTROL, FALSE); + } + ::Sleep(waitms); + keyboard_->SendInput(*inputs2); + } } void ViKeyHandler::_SendKey(UINT vk, int count) @@ -494,21 +513,33 @@ static HRESULT _QueueKeyForOtherIme(vector *inputs, WCHAR method, int par return S_OK; } -void ViKeyHandler::SwitchToOtherIme(WCHAR method, int param, BOOL imalnum) +void ViKeyHandler::SwitchToOtherIme(WCHAR method, int param, BOOL imalnum, int otherimeoffwait) { vector inputs; - if (_QueueKeyForOtherIme(&inputs, method, param) == S_OK) + if (_QueueKeyForOtherIme(&inputs, method, param) != S_OK) + { + return; + } + // 切り替えた後のIMEをONにする。 + // XXX: IMEがVK_KANJIでONになることを想定。(ON/OFFトグルでなく) + _QueueKey(&inputs, VK_KANJI); + if (otherimeoffwait == 0 || !imalnum) { - // 切り替えた後のIMEをONにする。 - // XXX: IMEがVK_KANJIでONになることを想定。(ON/OFFトグルでなく) - _QueueKey(&inputs, VK_KANJI); if (imalnum) { // 切り替えた後のIMEを英数モードにする。 _QueueKey(&inputs, VK_OEM_ATTN); // VK_DBE_ALPHANUMERIC } _SendInputs(&inputs); + return; } + + // XXX: Win8だと、imalnumの場合に、1度に送り付けると無視されるので、 + // Sleep()を入れて2回に分けて送り付ける + vector alnuminputs; + // 切り替えた後のIMEを英数モードにする。 + _QueueKey(&alnuminputs, VK_OEM_ATTN); // VK_DBE_ALPHANUMERIC + _SendInputs(&inputs, &alnuminputs, otherimeoffwait); } void ViKeyHandler::_ViOp(vector *inputs) diff --git a/imcrvtip/ViKeyHandler.h b/imcrvtip/ViKeyHandler.h index 1c651cd..a5dcecb 100644 --- a/imcrvtip/ViKeyHandler.h +++ b/imcrvtip/ViKeyHandler.h @@ -15,7 +15,7 @@ class ViKeyHandler void Reset(); void ResetThroughSelfSentKey(); - void SwitchToOtherIme(WCHAR method, int param, BOOL imalnum); + void SwitchToOtherIme(WCHAR method, int param, BOOL imalnum, int otherimeoffwait); BOOL IsThroughSelfSentKey(); BOOL IsWaitingNextKey(); HRESULT HandleKey(TfEditCookie ec, ITfContext *pContext, WCHAR ch, BYTE vk); @@ -23,7 +23,7 @@ class ViKeyHandler private: void _HandleFunc(TfEditCookie ec, ITfContext *pContext, WCHAR ch); void _QueueEndOfSelfSendKey(std::vector *inputs); - void _SendInputs(std::vector *inputs); + void _SendInputs(std::vector *inputs, vector *inputs2 = NULL, int waitms = 0); void _SendKey(UINT vk, int count = 1); void _SendKeyWithControl(UINT vk); void _ViOp(std::vector *inputs); diff --git a/imvimcnf/DlgProcBehavior2.cpp b/imvimcnf/DlgProcBehavior2.cpp index 94afafe..4a3dd3b 100644 --- a/imvimcnf/DlgProcBehavior2.cpp +++ b/imvimcnf/DlgProcBehavior2.cpp @@ -12,6 +12,8 @@ static const LPCWSTR otherime2[] = NULL }; +static LPCWSTR defaultWait = L"0"; + INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hwnd; @@ -80,6 +82,10 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM } SendMessage(hwnd, CB_SETCURSEL, (WPARAM)i, 0); + ReadValue(pathconfigxml, SectionBehavior, ValueOtherImeOffWait, strxmlval); + if(strxmlval.empty()) strxmlval = defaultWait; + SetDlgItemTextW(hDlg, IDC_EDIT_OTHERIMEOFFWAIT, strxmlval.c_str()); + return TRUE; case WM_COMMAND: @@ -97,6 +103,17 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM } break; + case IDC_EDIT_OTHERIMEOFFWAIT: + switch(HIWORD(wParam)) + { + case EN_CHANGE: + PropSheet_Changed(GetParent(hDlg), hDlg); + return TRUE; + default: + break; + } + break; + default: break; } @@ -129,6 +146,9 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM i = SendMessage(hwnd, CB_GETCURSEL, 0, 0); WriterKey(pXmlWriter, ValueOtherIme2, otherime2[i]); + GetDlgItemTextW(hDlg, IDC_EDIT_OTHERIMEOFFWAIT, num, _countof(num)); + WriterKey(pXmlWriter, ValueOtherImeOffWait, num); + WriterEndSection(pXmlWriter); //End of SectionBehavior return TRUE; diff --git a/imvimcnf/imvimcnf.rc b/imvimcnf/imvimcnf.rc index b338005629089eaae06a9a80f4d2374b5767c891..b28d3df05bdf0cfd4847ceb0fac14aa4f6519dea 100644 GIT binary patch delta 140 zcmaE(yU1We78fJuWN!iG$!j<`q!k$a8Qg%7J?MWLmmlS2iS Q8EYrsXOrLD#g)VZ09Mu>Z2$lO delta 12 TcmZ2v@J4q-7T4wl+)X?HBvS