Skip to content

Commit 3848308

Browse files
committed
Win8で他IME OFF切替してもON切替になる現象回避のため、OFFキー送付前にwaitを入れる設定を追加。
1 parent 19bcf07 commit 3848308

11 files changed

Lines changed: 76 additions & 18 deletions

common/configxml.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ LPCWSTR SectionBehavior = L"behavior";
2424

2525
LPCWSTR ValueOtherIme1 = L"otherime1";
2626
LPCWSTR ValueOtherIme2 = L"otherime2";
27+
LPCWSTR ValueOtherImeOffWait = L"otherimeoffwait";
2728

2829
//preservedkey section
2930

common/configxml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern LPCWSTR SectionBehavior;
5555

5656
extern LPCWSTR ValueOtherIme1;
5757
extern LPCWSTR ValueOtherIme2;
58+
extern LPCWSTR ValueOtherImeOffWait;
5859

5960
//preservedkey section
6061

imcrvtip/FnConfigure.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void CTextService::_LoadBehavior()
114114
{
115115
c_otherime2 = 0;
116116
}
117+
118+
ReadValue(pathconfigxml, SectionBehavior, ValueOtherImeOffWait, strxmlval);
119+
c_otherimeoffwait = wcstol(strxmlval.c_str(), NULL, 0);
117120
}
118121
static bool operator ==(const TF_PRESERVEDKEY &a, const TF_PRESERVEDKEY &b)
119122
{

imcrvtip/KeyEventSink.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ STDAPI CTextService::OnPreservedKey(ITfContext *pic, REFGUID rguid, BOOL *pfEate
129129
}
130130
else if(IsEqualGUID(rguid, c_guidPreservedKeyOtherIme))
131131
{
132-
vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, FALSE);
132+
vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, FALSE, c_otherimeoffwait);
133133
_SetKeyboardOpen(FALSE);
134134
*pfEaten = TRUE;
135135
}
136136
else if(IsEqualGUID(rguid, c_guidPreservedKeyOtherImeOff))
137137
{
138-
vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, TRUE);
138+
vihandler.SwitchToOtherIme(c_otherime1, c_otherime2, TRUE, c_otherimeoffwait);
139139
_SetKeyboardOpen(FALSE);
140140
*pfEaten = TRUE;
141141
}

imcrvtip/TextService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "TextService.h"
44

55
CTextService::CTextService()
6-
: vihandler(this)
6+
: vihandler(this), c_otherimeoffwait(0)
77
{
88
DllAddRef();
99

imcrvtip/TextService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class CTextService :
153153
//動作設定
154154
WCHAR c_otherime1; //他IMEへの切替え用に送付するキーシーケンス1
155155
int c_otherime2; //他IMEへの切替え用に送付するキーシーケンス2
156+
int c_otherimeoffwait; //他IME切替後、OFFモード切替送付待ち時間[ms]
156157

157158
//preserved key
158159
TF_PRESERVEDKEY preservedkeynormal[MAX_PRESERVEDKEY];

imcrvtip/ViKeyHandler.cpp

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void ViKeyHandler::_QueueEndOfSelfSendKey(vector<INPUT> *inputs)
383383
}
384384
}
385385

386-
void ViKeyHandler::_SendInputs(vector<INPUT> *inputs)
386+
void ViKeyHandler::_SendInputs(vector<INPUT> *inputs, vector<INPUT> *inputs2, int waitms)
387387
{
388388
// cf. deleter.UnsetModifiers()
389389
mozc::win32::KeyboardStatus keyboard_state;
@@ -399,27 +399,46 @@ void ViKeyHandler::_SendInputs(vector<INPUT> *inputs)
399399
to_be_updated = true;
400400
keyboard_state.SetState(VK_SHIFT, kUnsetState);
401401
_QueueKeyForModifier(inputs, VK_SHIFT, TRUE, TRUE);
402-
// restore modifier
403-
// XXX:SendInput()直後にdeleter.EndDeletion()を呼んでも、
404-
// CTRL-F押下時にVK_NEXT送り付けても動かない
405-
// (おそらくCTRL押下状態になってCTRL-NEXTになるため)
406-
_QueueKeyForModifier(inputs, VK_SHIFT, FALSE);
402+
if (inputs2 == NULL)
403+
{
404+
// restore modifier
405+
// XXX:SendInput()直後にdeleter.EndDeletion()を呼んでも、
406+
// CTRL-F押下時にVK_NEXT送り付けても動かない
407+
// (おそらくCTRL押下状態になってCTRL-NEXTになるため)
408+
_QueueKeyForModifier(inputs, VK_SHIFT, FALSE);
409+
}
407410
}
408411
if (keyboard_state.IsPressed(VK_CONTROL))
409412
{
410413
controlPressed = true;
411414
to_be_updated = true;
412415
keyboard_state.SetState(VK_CONTROL, kUnsetState);
413416
_QueueKeyForModifier(inputs, VK_CONTROL, TRUE, TRUE);
414-
_QueueKeyForModifier(inputs, VK_CONTROL, FALSE);
417+
if (inputs2 == NULL)
418+
{
419+
_QueueKeyForModifier(inputs, VK_CONTROL, FALSE);
420+
}
415421
}
416422
if (to_be_updated)
417423
{
418424
keyboard_->SetKeyboardState(keyboard_state);
419425
}
420426
}
421-
422427
keyboard_->SendInput(*inputs);
428+
429+
if (inputs2 != NULL)
430+
{
431+
if (shiftPressed)
432+
{
433+
_QueueKeyForModifier(inputs2, VK_SHIFT, FALSE);
434+
}
435+
if (controlPressed)
436+
{
437+
_QueueKeyForModifier(inputs2, VK_CONTROL, FALSE);
438+
}
439+
::Sleep(waitms);
440+
keyboard_->SendInput(*inputs2);
441+
}
423442
}
424443

425444
void ViKeyHandler::_SendKey(UINT vk, int count)
@@ -494,21 +513,33 @@ static HRESULT _QueueKeyForOtherIme(vector<INPUT> *inputs, WCHAR method, int par
494513
return S_OK;
495514
}
496515

497-
void ViKeyHandler::SwitchToOtherIme(WCHAR method, int param, BOOL imalnum)
516+
void ViKeyHandler::SwitchToOtherIme(WCHAR method, int param, BOOL imalnum, int otherimeoffwait)
498517
{
499518
vector<INPUT> inputs;
500-
if (_QueueKeyForOtherIme(&inputs, method, param) == S_OK)
519+
if (_QueueKeyForOtherIme(&inputs, method, param) != S_OK)
520+
{
521+
return;
522+
}
523+
// 切り替えた後のIMEをONにする。
524+
// XXX: IMEがVK_KANJIでONになることを想定。(ON/OFFトグルでなく)
525+
_QueueKey(&inputs, VK_KANJI);
526+
if (otherimeoffwait == 0 || !imalnum)
501527
{
502-
// 切り替えた後のIMEをONにする。
503-
// XXX: IMEがVK_KANJIでONになることを想定。(ON/OFFトグルでなく)
504-
_QueueKey(&inputs, VK_KANJI);
505528
if (imalnum)
506529
{
507530
// 切り替えた後のIMEを英数モードにする。
508531
_QueueKey(&inputs, VK_OEM_ATTN); // VK_DBE_ALPHANUMERIC
509532
}
510533
_SendInputs(&inputs);
534+
return;
511535
}
536+
537+
// XXX: Win8だと、imalnumの場合に、1度に送り付けると無視されるので、
538+
// Sleep()を入れて2回に分けて送り付ける
539+
vector<INPUT> alnuminputs;
540+
// 切り替えた後のIMEを英数モードにする。
541+
_QueueKey(&alnuminputs, VK_OEM_ATTN); // VK_DBE_ALPHANUMERIC
542+
_SendInputs(&inputs, &alnuminputs, otherimeoffwait);
512543
}
513544

514545
void ViKeyHandler::_ViOp(vector<INPUT> *inputs)

imcrvtip/ViKeyHandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class ViKeyHandler
1515

1616
void Reset();
1717
void ResetThroughSelfSentKey();
18-
void SwitchToOtherIme(WCHAR method, int param, BOOL imalnum);
18+
void SwitchToOtherIme(WCHAR method, int param, BOOL imalnum, int otherimeoffwait);
1919
BOOL IsThroughSelfSentKey();
2020
BOOL IsWaitingNextKey();
2121
HRESULT HandleKey(TfEditCookie ec, ITfContext *pContext, WCHAR ch, BYTE vk);
2222

2323
private:
2424
void _HandleFunc(TfEditCookie ec, ITfContext *pContext, WCHAR ch);
2525
void _QueueEndOfSelfSendKey(std::vector<INPUT> *inputs);
26-
void _SendInputs(std::vector<INPUT> *inputs);
26+
void _SendInputs(std::vector<INPUT> *inputs, vector<INPUT> *inputs2 = NULL, int waitms = 0);
2727
void _SendKey(UINT vk, int count = 1);
2828
void _SendKeyWithControl(UINT vk);
2929
void _ViOp(std::vector<INPUT> *inputs);

imvimcnf/DlgProcBehavior2.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ static const LPCWSTR otherime2[] =
1212
NULL
1313
};
1414

15+
static LPCWSTR defaultWait = L"0";
16+
1517
INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
1618
{
1719
HWND hwnd;
@@ -80,6 +82,10 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM
8082
}
8183
SendMessage(hwnd, CB_SETCURSEL, (WPARAM)i, 0);
8284

85+
ReadValue(pathconfigxml, SectionBehavior, ValueOtherImeOffWait, strxmlval);
86+
if(strxmlval.empty()) strxmlval = defaultWait;
87+
SetDlgItemTextW(hDlg, IDC_EDIT_OTHERIMEOFFWAIT, strxmlval.c_str());
88+
8389
return TRUE;
8490

8591
case WM_COMMAND:
@@ -97,6 +103,17 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM
97103
}
98104
break;
99105

106+
case IDC_EDIT_OTHERIMEOFFWAIT:
107+
switch(HIWORD(wParam))
108+
{
109+
case EN_CHANGE:
110+
PropSheet_Changed(GetParent(hDlg), hDlg);
111+
return TRUE;
112+
default:
113+
break;
114+
}
115+
break;
116+
100117
default:
101118
break;
102119
}
@@ -129,6 +146,9 @@ INT_PTR CALLBACK DlgProcBehavior2(HWND hDlg, UINT message, WPARAM wParam, LPARAM
129146
i = SendMessage(hwnd, CB_GETCURSEL, 0, 0);
130147
WriterKey(pXmlWriter, ValueOtherIme2, otherime2[i]);
131148

149+
GetDlgItemTextW(hDlg, IDC_EDIT_OTHERIMEOFFWAIT, num, _countof(num));
150+
WriterKey(pXmlWriter, ValueOtherImeOffWait, num);
151+
132152
WriterEndSection(pXmlWriter); //End of SectionBehavior
133153

134154
return TRUE;

imvimcnf/imvimcnf.rc

310 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)