Skip to content

Commit

Permalink
Win8で他IME OFF切替してもON切替になる現象回避のため、OFFキー送付前にwaitを入れる設定を追加。
Browse files Browse the repository at this point in the history
  • Loading branch information
deton committed Feb 25, 2014
1 parent 19bcf07 commit 3848308
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 18 deletions.
1 change: 1 addition & 0 deletions common/configxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ LPCWSTR SectionBehavior = L"behavior";

LPCWSTR ValueOtherIme1 = L"otherime1";
LPCWSTR ValueOtherIme2 = L"otherime2";
LPCWSTR ValueOtherImeOffWait = L"otherimeoffwait";

//preservedkey section

Expand Down
1 change: 1 addition & 0 deletions common/configxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern LPCWSTR SectionBehavior;

extern LPCWSTR ValueOtherIme1;
extern LPCWSTR ValueOtherIme2;
extern LPCWSTR ValueOtherImeOffWait;

//preservedkey section

Expand Down
3 changes: 3 additions & 0 deletions imcrvtip/FnConfigure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions imcrvtip/KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion imcrvtip/TextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "TextService.h"

CTextService::CTextService()
: vihandler(this)
: vihandler(this), c_otherimeoffwait(0)
{
DllAddRef();

Expand Down
1 change: 1 addition & 0 deletions imcrvtip/TextService.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
57 changes: 44 additions & 13 deletions imcrvtip/ViKeyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void ViKeyHandler::_QueueEndOfSelfSendKey(vector<INPUT> *inputs)
}
}

void ViKeyHandler::_SendInputs(vector<INPUT> *inputs)
void ViKeyHandler::_SendInputs(vector<INPUT> *inputs, vector<INPUT> *inputs2, int waitms)
{
// cf. deleter.UnsetModifiers()
mozc::win32::KeyboardStatus keyboard_state;
Expand All @@ -399,27 +399,46 @@ void ViKeyHandler::_SendInputs(vector<INPUT> *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))
{
controlPressed = true;
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)
Expand Down Expand Up @@ -494,21 +513,33 @@ static HRESULT _QueueKeyForOtherIme(vector<INPUT> *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<INPUT> 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<INPUT> alnuminputs;
// 切り替えた後のIMEを英数モードにする。
_QueueKey(&alnuminputs, VK_OEM_ATTN); // VK_DBE_ALPHANUMERIC
_SendInputs(&inputs, &alnuminputs, otherimeoffwait);
}

void ViKeyHandler::_ViOp(vector<INPUT> *inputs)
Expand Down
4 changes: 2 additions & 2 deletions imcrvtip/ViKeyHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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);

private:
void _HandleFunc(TfEditCookie ec, ITfContext *pContext, WCHAR ch);
void _QueueEndOfSelfSendKey(std::vector<INPUT> *inputs);
void _SendInputs(std::vector<INPUT> *inputs);
void _SendInputs(std::vector<INPUT> *inputs, vector<INPUT> *inputs2 = NULL, int waitms = 0);
void _SendKey(UINT vk, int count = 1);
void _SendKeyWithControl(UINT vk);
void _ViOp(std::vector<INPUT> *inputs);
Expand Down
20 changes: 20 additions & 0 deletions imvimcnf/DlgProcBehavior2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Binary file modified imvimcnf/imvimcnf.rc
Binary file not shown.
1 change: 1 addition & 0 deletions imvimcnf/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#define IDC_COMBO_OTHERIME1 1206
#define IDC_COMBO_OTHERIME2 1207
#define IDC_EDIT_OTHERIMEOFFWAIT 1208

#define IDC_LIST_PRSRVKEY 1701
#define IDC_EDIT_PRSRVKEY_VKEY 1702
Expand Down

0 comments on commit 3848308

Please sign in to comment.