1 // xkeymacsdll.cpp : Defines the initialization routines for the DLL.
\r
5 #include "resource.h"
\r
7 #include "Commands.h"
\r
13 #define new DEBUG_NEW
\r
15 static char THIS_FILE[] = __FILE__;
\r
31 static const Modifier Modifiers[] = {
\r
32 // { _T("A-"), ALT },
\r
33 { _T("C-"), CONTROL},
\r
34 // { _T("H-"), HYPER },
\r
36 { _T("S-"), SHIFT },
\r
37 // { _T("s-"), SUPER },
\r
38 { _T("Ctrl+"), WIN_CTRL },
\r
39 { _T("Alt+"), WIN_ALT },
\r
40 { _T("Win+"), WIN_WIN },
\r
43 static const KeyName ControlCharacters[] = {
\r
44 // { VK_LBUTTON, _T("mouse-1") }, // does not work well
\r
45 // { VK_RBUTTON, _T("mouse-3") }, // does not work well
\r
46 { VK_CANCEL, _T("break") },
\r
47 // { VK_MBUTTON, _T("mouse-2") }, // does not work well
\r
48 { VK_BACK, _T("backspace") },
\r
49 { VK_TAB, _T("tab") },
\r
50 { VK_RETURN, _T("return") },
\r
51 { VK_CAPITAL, _T("capslock") },
\r
52 { VK_KANA, _T("kana") },
\r
53 { VK_KANJI, _T("kanji") },
\r
54 { VK_ESCAPE, _T("escape") },
\r
55 { VK_CONVERT, _T("convert") },
\r
56 { VK_NONCONVERT, _T("nonconvert") },
\r
57 // { VK_SPACE, _T("SPC") }, // [? ]
\r
58 { VK_PRIOR, _T("prior") },
\r
59 { VK_NEXT, _T("next") },
\r
60 { VK_END, _T("end") },
\r
61 { VK_HOME, _T("home") },
\r
62 { VK_LEFT, _T("left") },
\r
63 { VK_UP, _T("up") },
\r
64 { VK_RIGHT, _T("right") },
\r
65 { VK_DOWN, _T("down") },
\r
66 { VK_SELECT, _T("select") },
\r
67 { VK_PRINT, _T("print") },
\r
68 { VK_EXECUTE, _T("execute") },
\r
69 { VK_SNAPSHOT, _T("printscreen") }, // work as print
\r
70 { VK_INSERT, _T("insert") },
\r
71 { VK_DELETE, _T("delete") },
\r
72 { VK_LWIN, _T("lwindow") },
\r
73 { VK_RWIN, _T("rwindow") },
\r
74 { VK_APPS, _T("apps") },
\r
75 { VK_SLEEP, _T("sleep") },
\r
76 { VK_NUMPAD0, _T("kp-0") },
\r
77 { VK_NUMPAD1, _T("kp-1") },
\r
78 { VK_NUMPAD2, _T("kp-2") },
\r
79 { VK_NUMPAD3, _T("kp-3") },
\r
80 { VK_NUMPAD4, _T("kp-4") },
\r
81 { VK_NUMPAD5, _T("kp-5") },
\r
82 { VK_NUMPAD6, _T("kp-6") },
\r
83 { VK_NUMPAD7, _T("kp-7") },
\r
84 { VK_NUMPAD8, _T("kp-8") },
\r
85 { VK_NUMPAD9, _T("kp-9") },
\r
86 { VK_MULTIPLY, _T("kp-multiply") },
\r
87 { VK_ADD, _T("kp-add") },
\r
88 { VK_SUBTRACT, _T("kp-subtract") },
\r
89 { VK_DECIMAL, _T("kp-decimal") },
\r
90 { VK_DIVIDE, _T("kp-divide") },
\r
91 // { VK_F1, _T("f1") }, // FIXME
\r
92 // { VK_F2, _T("f2") }, // Move at the end of definition of funcgtion keys to keep away confliction f1/f2 and f1?/f2? by _tcsncmp() i.e. strncmp()
\r
93 { VK_F3, _T("f3") },
\r
94 { VK_F4, _T("f4") },
\r
95 { VK_F5, _T("f5") },
\r
96 { VK_F6, _T("f6") },
\r
97 { VK_F7, _T("f7") },
\r
98 { VK_F8, _T("f8") },
\r
99 { VK_F9, _T("f9") },
\r
100 { VK_F10, _T("f10") },
\r
101 { VK_F11, _T("f11") },
\r
102 { VK_F12, _T("f12") },
\r
103 { VK_F13, _T("f13") },
\r
104 { VK_F14, _T("f14") },
\r
105 { VK_F15, _T("f15") },
\r
106 { VK_F16, _T("f16") },
\r
107 { VK_F17, _T("f17") },
\r
108 { VK_F18, _T("f18") },
\r
109 { VK_F19, _T("f19") },
\r
110 { VK_F20, _T("f20") },
\r
111 { VK_F21, _T("f21") },
\r
112 { VK_F22, _T("f22") },
\r
113 { VK_F23, _T("f23") },
\r
114 { VK_F24, _T("f24") },
\r
115 { VK_F1, _T("f1") },
\r
116 { VK_F2, _T("f2") },
\r
117 { VK_NUMLOCK, _T("kp-numlock") },
\r
118 { VK_SCROLL, _T("scroll") },
\r
119 { 0xa6, _T("browser-back") }, // VK_BROWSER_BACK
\r
120 { 0xa7, _T("browser-forward") }, // VK_BROWSER_FORWARD
\r
121 { 0xa8, _T("browser-refresh") }, // VK_BROWSER_REFRESH
\r
122 { 0xa9, _T("browser-stop") }, // VK_BROWSER_STOP
\r
123 { 0xaa, _T("browser-search") }, // VK_BROWSER_SEARCH
\r
124 { 0xab, _T("browser-favorites") }, // VK_BROWSER_FAVORITES
\r
125 { 0xac, _T("browser-home") }, // VK_BROWSER_HOME
\r
126 { 0xad, _T("volume-mute") }, // VK_VOLUME_MUTE
\r
127 { 0xae, _T("volume-down") }, // VK_VOLUME_DOWN
\r
128 { 0xaf, _T("volume-up") }, // VK_VOLUME_UP
\r
129 { 0xb0, _T("media-next-track") }, // VK_MEDIA_NEXT_TRACK
\r
130 { 0xb1, _T("media-prev-track") }, // VK_MEDIA_PREV_TRACK
\r
131 { 0xb2, _T("media-stop") }, // VK_MEDIA_STOP
\r
132 { 0xb3, _T("media-play-pause") }, // VK_MEDIA_PLAY_PAUSE
\r
133 { 0xb4, _T("launch-mail") }, // VK_LAUNCH_MAIL
\r
134 { 0xb5, _T("launch-media-select") }, // VK_LAUNCH_MEDIA_SELECT
\r
135 { 0xb6, _T("launch-1") }, // VK_LAUNCH_APP1
\r
136 { 0xb7, _T("launch-2") }, // VK_LAUNCH_APP2
\r
139 static AFX_EXTENSION_MODULE XkeymacsdllDLL = { NULL, NULL };
\r
141 HINSTANCE g_hDllInst = NULL;
\r
142 UINT g_ImeManipulationMessage = 0;
\r
143 #pragma data_seg(".xkmcs")
\r
144 HHOOK g_hHookKeyboard = NULL;
\r
145 HHOOK g_hHookDummy = NULL;
\r
148 inline bool IsWow64(HANDLE mod) {
\r
149 typedef BOOL (WINAPI *pfnIsWow64Process_t)(HANDLE, PBOOL);
\r
150 if (const pfnIsWow64Process_t IsWow64Process = (pfnIsWow64Process_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process")) {
\r
152 return IsWow64Process(mod, &b) && b;
\r
157 inline bool Is64System() {
\r
159 GetNativeSystemInfo(&info);
\r
160 return info.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL;
\r
163 inline bool Is64Process(HANDLE mod) {
\r
164 return Is64System() && !IsWow64(mod);
\r
167 const bool IsDll64 = sizeof(void *) == 8;
\r
169 inline bool Is64ProcessHwnd(HWND hwnd) {
\r
171 GetWindowThreadProcessId(hwnd, &pid);
\r
172 HANDLE hmod = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
\r
173 bool b = Is64Process(hmod);
\r
178 extern "C" int APIENTRY
\r
179 DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
\r
181 g_hDllInst = hInstance;
\r
183 // Remove this if you use lpReserved
\r
184 UNREFERENCED_PARAMETER(lpReserved);
\r
186 switch (dwReason) {
\r
187 case DLL_PROCESS_ATTACH:
\r
188 TRACE0("XKEYMACSDLL.DLL Initializing!\n");
\r
189 g_ImeManipulationMessage = RegisterWindowMessage(_T("XkManipulateIME"));
\r
191 // Extension DLL one-time initialization
\r
192 if (!AfxInitExtensionModule(XkeymacsdllDLL, hInstance)) {
\r
196 // Insert this DLL into the resource chain
\r
197 // NOTE: If this Extension DLL is being implicitly linked to by
\r
198 // an MFC Regular DLL (such as an ActiveX Control)
\r
199 // instead of an MFC application, then you will want to
\r
200 // remove this line from DllMain and put it in a separate
\r
201 // function exported from this Extension DLL. The Regular DLL
\r
202 // that uses this Extension DLL should then explicitly call that
\r
203 // function to initialize this Extension DLL. Otherwise,
\r
204 // the CDynLinkLibrary object will not be attached to the
\r
205 // Regular DLL's resource chain, and serious problems will
\r
209 new CDynLinkLibrary(XkeymacsdllDLL);
\r
211 catch (CMemoryException* e) {
\r
213 // CUtils::Log("DllMain: 'new' threw an exception");
\r
216 case DLL_PROCESS_DETACH:
\r
217 TRACE0("XKEYMACSDLL.DLL Terminating!\n");
\r
218 // Terminate the library before destructors are called
\r
219 AfxTermExtensionModule(XkeymacsdllDLL);
\r
225 //////////////////////////////////////////////////////////////////////
\r
226 // CXkeymacsDll Class
\r
227 //////////////////////////////////////////////////////////////////////
\r
229 #include "xkeymacsDll.h"
\r
230 #pragma data_seg(".xkmcs")
\r
231 BOOL CXkeymacsDll::m_bHookAltRelease = FALSE;
\r
232 HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;
\r
233 HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;
\r
234 HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;
\r
235 HHOOK CXkeymacsDll::m_hHookShell = NULL;
\r
236 BOOL CXkeymacsDll::m_bRightControl = FALSE;
\r
237 BOOL CXkeymacsDll::m_bRightAlt = FALSE;
\r
238 BOOL CXkeymacsDll::m_bRightShift = FALSE;
\r
239 BOOL CXkeymacsDll::m_bHook = TRUE;
\r
240 BOOL CXkeymacsDll::m_bDefiningMacro = FALSE;
\r
241 CList<CClipboardSnap *, CClipboardSnap *> CXkeymacsDll::m_oKillRing;
\r
242 CObList CXkeymacsDll::m_Macro;
\r
243 int CXkeymacsDll::m_nKillRing = 0;
\r
244 int CXkeymacsDll::m_nOriginal[MAX_COMMAND_TYPE][MAX_KEY] = {'\0'};
\r
245 int CXkeymacsDll::m_nApplicationID = 0;
\r
246 int CXkeymacsDll::m_nAccelerate = 0;
\r
247 int CXkeymacsDll::m_nKeyboardSpeed = 31;
\r
248 HCURSOR CXkeymacsDll::m_hCursor[MAX_STATUS] = {'\0'};
\r
249 HCURSOR CXkeymacsDll::m_hCurrentCursor = NULL;
\r
250 BOOL CXkeymacsDll::m_bCursor = FALSE;
\r
251 TCHAR CXkeymacsDll::m_M_xTip[128] = "";
\r
252 CONFIG CXkeymacsDll::m_Config = {0};
\r
255 //////////////////////////////////////////////////////////////////////
\r
256 // Construction/Destruction
\r
257 //////////////////////////////////////////////////////////////////////
\r
259 CXkeymacsDll::CXkeymacsDll()
\r
264 CXkeymacsDll::~CXkeymacsDll()
\r
269 BOOL CXkeymacsDll::SaveConfig()
\r
271 TCHAR szTmp[MAX_PATH];
\r
272 if (!GetTempPath(MAX_PATH, szTmp))
\r
274 if (_tmakepath_s(szTmp, NULL, szTmp, _T("xkeymacs"), _T("tmp")))
\r
276 HANDLE hFile = CreateFile(szTmp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
\r
277 if (hFile == INVALID_HANDLE_VALUE)
\r
280 BOOL res = WriteFile(hFile, &m_Config, sizeof(m_Config), &written, NULL) || written != sizeof(m_Config);
\r
281 CloseHandle(hFile);
\r
285 BOOL CXkeymacsDll::LoadConfig()
\r
287 TCHAR szTmp[MAX_PATH];
\r
288 if (!GetTempPath(MAX_PATH, szTmp))
\r
290 if (_tmakepath_s(szTmp, NULL, szTmp, _T("xkeymacs"), _T("tmp")))
\r
292 HANDLE hFile = CreateFile(szTmp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
\r
293 if (hFile == INVALID_HANDLE_VALUE)
\r
296 BOOL res = ReadFile(hFile, &m_Config, sizeof(m_Config), &read, NULL) && read == sizeof(m_Config);
\r
297 CloseHandle(hFile);
\r
302 LRESULT WINAPI DummyProc(int code, WPARAM wp, LPARAM lp) {
\r
303 return CallNextHookEx(0, code, wp, lp);
\r
306 void CXkeymacsDll::SetHooks()
\r
308 m_hHookCallWnd = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, g_hDllInst, 0);
\r
309 m_hHookCallWndRet = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)CallWndRetProc, g_hDllInst, 0);
\r
310 m_hHookGetMessage = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgProc, g_hDllInst, 0);
\r
311 m_hHookShell = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, g_hDllInst, 0);
\r
312 g_hHookDummy = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)DummyProc, g_hDllInst, 0);
\r
313 g_hHookKeyboard = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, g_hDllInst, 0);
\r
316 inline void unhook(HHOOK &hh) {
\r
318 UnhookWindowsHookEx(hh);
\r
322 void CXkeymacsDll::ResetHooks()
\r
329 void CXkeymacsDll::ReleaseHooks()
\r
331 unhook(m_hHookCallWnd);
\r
332 unhook(m_hHookCallWndRet);
\r
333 unhook(m_hHookGetMessage);
\r
334 unhook(m_hHookShell);
\r
335 unhook(g_hHookKeyboard);
\r
336 unhook(g_hHookDummy);
\r
339 void CXkeymacsDll::SetKeyboardHookFlag(BOOL bFlag)
\r
342 ICONMSG msg = {MAIN_ICON,};
\r
344 if (CCommands::IsTemporarilyDisableXKeymacs()) {
\r
345 msg.nState = STATUS_DISABLE_TMP;
\r
346 m_hCurrentCursor = m_hCursor[STATUS_DISABLE_TMP];
\r
348 msg.nState = STATUS_ENABLE;
\r
349 m_hCurrentCursor = m_hCursor[STATUS_ENABLE];
\r
352 msg.nState = STATUS_DISABLE_WOCQ;
\r
354 if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE
\r
355 || (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))
\r
356 && CUtils::IsDefaultIgnoreApplication())) {
\r
357 msg.nState = STATUS_DISABLE;
\r
358 m_hCurrentCursor = m_hCursor[STATUS_DISABLE];
\r
360 SendIconMessage(&msg, 1);
\r
364 // if be keyboard hook, return TRUE
\r
365 BOOL CXkeymacsDll::IsKeyboardHook()
\r
374 void CXkeymacsDll::LogCallWndProcMessage(WPARAM wParam, LPARAM lParam)
\r
376 CWPSTRUCT &cwps = *(CWPSTRUCT *)lParam;
\r
378 switch (cwps.message) {
\r
379 case WM_PAINT: // 0x000F
\r
380 case WM_MDIGETACTIVE: // 0x0229
\r
387 case WM_CREATE: // 0x0001
\r
388 // CUtils::Log(_T("CallWndProc: cwps.message = WM_CREATE"));
\r
390 case WM_DESTROY: // 0x0002
\r
391 // CUtils::Log(_T("CallWndProc: cwps.message = WM_DESTROY"));
\r
393 case WM_MOVE: // 0x0003
\r
394 // CUtils::Log(_T("CallWndProc: cwps.message = WM_MOVE");)
\r
396 case WM_SIZE: // 0x0005
\r
397 // CUtils::Log(_T("CallWndProc: cwps.message = WM_SIZE"));
\r
399 case WM_GETTEXT: // 0x000D
\r
400 // CUtils::Log(_T("CallWndProc: cwps.message = WM_GETTEXT"));
\r
402 case WM_ERASEBKGND: // 0x0014
\r
403 // CUtils::Log(_T("CallWndProc: cwps.message = WM_ERASEBKGND"));
\r
405 case WM_WINDOWPOSCHANGING: // 0x0046
\r
406 // CUtils::Log(_T("CallWndProc: cwps.message = WM_WINDOWPOSCHANGING"));
\r
408 case WM_WINDOWPOSCHANGED: // 0x0047
\r
409 // CUtils::Log(_T("CallWndProc: cwps.message = WM_WINDOWPOSCHANGED"));
\r
411 case WM_COPYDATA: // 0x004A
\r
412 // CUtils::Log(_T("CallWndProc: cwps.message = WM_COPYDATA"));
\r
414 case WM_NCCREATE: // 0x0081
\r
415 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCCREATE"));
\r
417 case WM_NCDESTROY: // 0x0082
\r
418 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCDESTROY"));
\r
420 case WM_NCCALCSIZE: // 0x0083
\r
421 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCCALCSIZE"));
\r
423 case WM_NCPAINT: // 0x0085
\r
424 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCPAINT"));
\r
426 case WM_IME_STARTCOMPOSITION: // 0x010D
\r
427 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_STARTCOMPOSITION"));
\r
429 case WM_IME_ENDCOMPOSITION: // 0x010E
\r
430 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_ENDCOMPOSITION"));
\r
432 case WM_IME_KEYLAST: // 0x010F
\r
433 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_KEYLAST"));
\r
435 case WM_COMMAND: // 0x0111
\r
436 // CUtils::Log(_T("CallWndProc: cwps.message = WM_COMMAND"));
\r
438 case WM_CTLCOLOREDIT: // 0x0133
\r
439 // CUtils::Log(_T("CallWndProc: cwps.message = WM_CTLCOLOREDIT"));
\r
441 case WM_POWERBROADCAST: // 0x0218
\r
442 // CUtils::Log(_T("CallWndProc: cwps.message = WM_POWERBROADCAST"));
\r
444 case PBT_APMQUERYSUSPEND: // 0x0000
\r
445 // CUtils::Log(_T("PBT_APMQUERYSUSPEND"));
\r
447 case PBT_APMQUERYSTANDBY: // 0x0001
\r
448 // CUtils::Log(_T("PBT_APMQUERYSTANDBY"));
\r
450 case PBT_APMQUERYSUSPENDFAILED: // 0x0002
\r
451 // CUtils::Log(_T("PBT_APMQUERYSUSPENDFAILED"));
\r
453 case PBT_APMQUERYSTANDBYFAILED: // 0x0003
\r
454 // CUtils::Log(_T("PBT_APMQUERYSTANDBYFAILED"));
\r
456 case PBT_APMSUSPEND: // 0x0004
\r
457 // CUtils::Log(_T("PBT_APMSUSPEND"));
\r
459 case PBT_APMSTANDBY: // 0x0005
\r
460 // CUtils::Log(_T("PBT_APMSTANDBY"));
\r
462 case PBT_APMRESUMECRITICAL: // 0x0006
\r
463 // CUtils::Log(_T("PBT_APMRESUMECRITICAL"));
\r
465 case PBT_APMRESUMESUSPEND: // 0x0007
\r
466 // CUtils::Log(_T("PBT_APMRESUMESUSPEND"));
\r
468 case PBT_APMRESUMESTANDBY: // 0x0008
\r
469 // CUtils::Log(_T("PBT_APMRESUMESTANDBY"));
\r
471 case PBT_APMBATTERYLOW: // 0x0009
\r
472 // CUtils::Log(_T("PBT_APMBATTERYLOW"));
\r
474 case PBT_APMPOWERSTATUSCHANGE: // 0x000A
\r
475 // CUtils::Log(_T("PBT_APMPOWERSTATUSCHANGE"));
\r
477 case PBT_APMOEMEVENT: // 0x000B
\r
478 // CUtils::Log(_T("PBT_APMOEMEVENT"));
\r
480 case PBT_APMRESUMEAUTOMATIC: // 0x0012
\r
481 // CUtils::Log(_T("PBT_APMRESUMEAUTOMATIC"));
\r
484 // CUtils::Log(_T("PBT_OTHERS: %d"), wParam);
\r
488 case WM_IME_NOTIFY: // 0x0282
\r
489 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_NOTIFY"));
\r
492 // CUtils::Log(_T("CallWndProc: cwps.message = 0x%04X"), cwps.message);
\r
497 LRESULT CALLBACK CXkeymacsDll::CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
499 // LogCallWndProcMessage(wParam, lParam);
\r
502 CWPSTRUCT &cwps = *(CWPSTRUCT *)lParam;
\r
503 switch (cwps.message) {
\r
504 case WM_IME_STARTCOMPOSITION:
\r
505 InitKeyboardProc(TRUE);
\r
507 case WM_IME_ENDCOMPOSITION:
\r
508 InitKeyboardProc(FALSE);
\r
511 if (cwps.hwnd == GetForegroundWindow()) {
\r
512 InitKeyboardProc(FALSE);
\r
513 SetKeyboardHookFlag(m_bHook);
\r
516 case WM_NCACTIVATE:
\r
518 if (cwps.hwnd == GetForegroundWindow()) {
\r
519 InitKeyboardProc(FALSE);
\r
520 SetKeyboardHookFlag(m_bHook);
\r
524 case WM_POWERBROADCAST:
\r
526 case PBT_APMRESUMECRITICAL: // 0x0006
\r
527 case PBT_APMRESUMESUSPEND: // 0x0007
\r
528 case PBT_APMRESUMESTANDBY: // 0x0008
\r
540 return CallNextHookEx(m_hHookCallWnd, nCode, wParam, lParam);
\r
543 LRESULT CALLBACK CXkeymacsDll::CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
546 CWPRETSTRUCT &cwprets = *(CWPRETSTRUCT *)lParam;
\r
547 switch (cwprets.message) {
\r
549 if (cwprets.hwnd == GetForegroundWindow()) {
\r
550 InitKeyboardProc(FALSE);
\r
560 return CallNextHookEx(m_hHookCallWndRet, nCode, wParam, lParam);
\r
563 LRESULT CALLBACK CXkeymacsDll::GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
565 MSG &msg = (*(MSG *)lParam);
\r
566 if (msg.message == g_ImeManipulationMessage) {
\r
568 CCommands::DoSetInputMethodOpenStatus((INPUT_METHOD_OPEN_STATUS)msg.wParam, msg.lParam);
\r
571 switch (msg.message) {
\r
572 case WM_IME_STARTCOMPOSITION:
\r
573 InitKeyboardProc(TRUE);
\r
575 case WM_IME_ENDCOMPOSITION:
\r
576 InitKeyboardProc(FALSE);
\r
579 return CallNextHookEx(m_hHookGetMessage, nCode, wParam, lParam);
\r
582 LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
585 case HSHELL_WINDOWACTIVATED:
\r
587 TCHAR className[256];
\r
588 ::GetClassName((HWND)wParam, className, 255);
\r
589 if (!_tcsicmp(className, _T("ConsoleWindowClass"))) {
\r
590 InitKeyboardProc(FALSE);
\r
591 SetKeyboardHookFlag(m_bHook);
\r
598 return CallNextHookEx( m_hHookShell, nCode, wParam, lParam );
\r
601 UINT CXkeymacsDll::GetModifierState(BOOL bPhysicalKey)
\r
604 if (IsDown(VK_SHIFT, bPhysicalKey))
\r
606 if (IsDown(VK_CONTROL, bPhysicalKey))
\r
608 if (IsDown(VK_MENU, bPhysicalKey))
\r
613 void CXkeymacsDll::SetModifierState(UINT after, UINT before)
\r
615 if (after & SHIFT && !(before & SHIFT))
\r
616 DepressKey(VK_SHIFT);
\r
617 else if (!(after & SHIFT) && before & SHIFT)
\r
618 ReleaseKey(VK_SHIFT);
\r
620 if (after & CONTROL && !(before & CONTROL)) {
\r
621 UpdateKeyboardState(VK_CONTROL, 1);
\r
622 DepressKey(VK_CONTROL);
\r
623 } else if (!(after & CONTROL) && before & CONTROL) {
\r
624 ReleaseKey(VK_CONTROL);
\r
625 UpdateKeyboardState(VK_CONTROL, 0);
\r
628 if (after & META && !(before & META))
\r
629 DepressKey(VK_MENU);
\r
630 else if (!(after & META) && before & META) {
\r
631 if (CUtils::IsVisualStudio2010())
\r
632 m_bHookAltRelease = TRUE;
\r
633 ReleaseKey(VK_MENU);
\r
637 BOOL CXkeymacsDll::UpdateKeyboardState(BYTE bVk, BYTE bState)
\r
639 BYTE ks[256] = {'\0'};
\r
640 if (!GetKeyboardState(ks))
\r
643 return SetKeyboardState(ks);
\r
646 BOOL CXkeymacsDll::IsDown(BYTE bVk, BOOL bPhysicalKey)
\r
648 return bPhysicalKey ? GetAsyncKeyState(bVk) < 0 : GetKeyState(bVk) < 0;
\r
652 void CXkeymacsDll::DoKeybd_event(BYTE bVk, DWORD dwFlags)
\r
654 // Set KEYEVENTF_EXTENDEDKEY if needed
\r
657 if (m_bRightControl)
\r
658 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
663 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
667 if (m_bRightShift) {
\r
668 if (CUtils::IsXPorLater())
\r
671 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
675 if (IsDown(VK_CONTROL, FALSE)) // Break
\r
676 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
690 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
693 // CUtils::Log(_T("b: %x, %x, %x, %#hx, %#hx"), bVk, dwFlags, GetMessageExtraInfo(), GetKeyState(bVk), GetAsyncKeyState(bVk));
\r
694 keybd_event(bVk, 0, dwFlags, GetMessageExtraInfo());
\r
695 // CUtils::Log(_T("a: %x, %x, %x, %#hx, %#hx"), bVk, dwFlags, GetMessageExtraInfo(), GetKeyState(bVk), GetAsyncKeyState(bVk));
\r
698 // the key is being depressed
\r
699 void CXkeymacsDll::DepressKey(BYTE bVk, BOOL bOriginal) // bVk is virtual-key code, MSDN said
\r
702 // CUtils::Log(_T("i: %x, %d, %d, %d, %d, %d, %d, %d, %d"), bVk,
\r
703 // IsDown(VK_CONTROL), IsDown(VK_CONTROL, FALSE), IsDepressedModifier(CCommands::C_), IsDepressedModifier(CCommands::C_, FALSE),
\r
704 // IsDown(VK_MENU), IsDown(VK_MENU, FALSE), IsDepressedModifier(CCommands::MetaAlt), IsDepressedModifier(CCommands::MetaAlt, FALSE));
\r
705 Original(GetModifierState(), bVk, 1);
\r
707 DoKeybd_event(bVk, 0);
\r
710 // the key is being released
\r
711 void CXkeymacsDll::ReleaseKey(BYTE bVk) // bVk is virtual-key code, MSDN said
\r
713 DoKeybd_event(bVk, KEYEVENTF_KEYUP);
\r
716 // bVk down, bVk up
\r
717 void CXkeymacsDll::Kdu(BYTE bVk, DWORD n, BOOL bOriginal)
\r
720 DepressKey(bVk, bOriginal);
\r
725 void CXkeymacsDll::InitKeyboardProc(BOOL bImeComposition)
\r
727 if (CUtils::IsFindDialog()) {
\r
728 static BOOL bImeCompositionOld = FALSE;
\r
729 if (!bImeComposition
\r
730 && bImeCompositionOld) {
\r
731 DepressKey(VK_END);
\r
732 ReleaseKey(VK_END);
\r
734 bImeCompositionOld = bImeComposition;
\r
737 CUtils::SetApplicationName(bImeComposition);
\r
739 if (_tcsnicmp(m_Config.szSpecialApp[m_nApplicationID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nApplicationID])) { // PROCESSENTRY32 has only 0xF bytes of Name
\r
740 m_nApplicationID = -1;
\r
742 for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {
\r
743 if (!_tcsnicmp(m_Config.szSpecialApp[nApplicationID], CUtils::GetApplicationName(), 0xF) && IsMatchWindowText(m_Config.szWindowText[nApplicationID])) {
\r
745 if (m_nApplicationID < 0
\r
746 || CUtils::GetWindowTextType(m_Config.szWindowText[m_nApplicationID]) < CUtils::GetWindowTextType(m_Config.szWindowText[nApplicationID])
\r
747 || CUtils::GetWindowTextType(m_Config.szWindowText[m_nApplicationID]) == CUtils::GetWindowTextType(m_Config.szWindowText[nApplicationID])
\r
748 && _tcscmp(m_Config.szWindowText[m_nApplicationID], m_Config.szWindowText[nApplicationID]) <= 0) {
\r
749 m_nApplicationID = nApplicationID;
\r
754 if (m_nApplicationID < 0) {
\r
755 for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {
\r
756 if (!_tcsicmp(m_Config.szSpecialApp[nApplicationID], _T("Default"))) {
\r
757 m_nApplicationID = nApplicationID;
\r
762 if (m_nApplicationID < 0) {
\r
763 m_nApplicationID = 0;
\r
768 if (m_Config.nSettingStyle[m_nApplicationID] != SETTING_DISABLE
\r
769 && (_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default")) || !CUtils::IsDefaultIgnoreApplication())
\r
770 && !bImeComposition
\r
771 && CUtils::IsDialog()) {
\r
772 // Use Dialog Setting
\r
773 if (m_Config.bUseDialogSetting[m_nApplicationID]) {
\r
774 int nOriginalApplicationID = m_nApplicationID;
\r
775 for (m_nApplicationID = 0; m_nApplicationID < MAX_APP; ++m_nApplicationID) {
\r
776 if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Dialog"))) {
\r
780 if (m_nApplicationID == MAX_APP) {
\r
781 m_nApplicationID = nOriginalApplicationID;
\r
787 {CX_ICON, OFF_ICON, ""},
\r
788 {MX_ICON, OFF_ICON, ""},
\r
789 {META_ICON, OFF_ICON, ""}
\r
791 SendIconMessage(msg, 3);
\r
792 CCommands::SetMark(FALSE);
\r
793 CCommands::SetTemporarilyDisableXKeymacs(FALSE);
\r
794 CCommands::Reset();
\r
797 // emulate emacs // cf virtual-key code
\r
798 LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
800 ASSERT(0 <= wParam && wParam <= UCHAR_MAX);
\r
802 int nCommandType = NONE;
\r
803 BYTE nKey = (BYTE)wParam;
\r
805 static BOOL bLocked = FALSE;
\r
806 static const BYTE RECURSIVE_KEY = 0x07;
\r
807 static int (*fCommand)() = NULL;
\r
808 static BYTE nOneShotModifier[MAX_KEY] = {'\0'};
\r
809 static BOOL bCherryOneShotModifier = FALSE;
\r
811 // CUtils::Log(_T("nCode = %#x, nKey = %#x, lParam = %p, %d, %d"), nCode, nKey, lParam, IsDll64, Is64ProcessHwnd(GetForegroundWindow()));
\r
813 if (Is64ProcessHwnd(GetForegroundWindow()) != IsDll64 || CUtils::IsXkeymacs())
\r
814 return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);
\r
816 if (nCode < 0 || nCode == HC_NOREMOVE) {
\r
820 if (nKey == RECURSIVE_KEY) {
\r
821 if (lParam & BEING_RELEASED) {
\r
822 goto HOOK_RECURSIVE_KEY;
\r
824 goto RECURSIVE_COMMAND;
\r
829 static BOOL bShift = FALSE;
\r
830 if (IsDepressedShiftKeyOnly(nKey)) {
\r
831 if (lParam & BEING_RELEASED) {
\r
833 CCommands::SetMark(FALSE);
\r
845 if (lParam & EXTENDED_KEY) {
\r
846 nKey = VK_RCONTROL;
\r
848 nKey = VK_LCONTROL;
\r
852 if (lParam & EXTENDED_KEY) {
\r
859 if (lParam & EXTENDED_KEY) {
\r
869 if (lParam & BEING_RELEASED) {
\r
876 if (m_bHookAltRelease) {
\r
877 m_bHookAltRelease = FALSE;
\r
884 for (int i = 0; i < MAX_COMMAND_TYPE; i++) {
\r
885 int (*func)() = Commands[m_Config.nCommandID[m_nApplicationID][i][nKey]].fCommand;
\r
886 if (func && !(bAlt && func == CCommands::MetaAlt))
\r
890 if (nOneShotModifier[nKey]) {
\r
891 ReleaseKey(nOneShotModifier[nKey]);
\r
892 nOneShotModifier[nKey] = 0;
\r
894 if (bCherryOneShotModifier) {
\r
895 bCherryOneShotModifier = FALSE;
\r
902 if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE) {
\r
906 // Do Nothing for Meadow, Mule for Win32, ... if those use default setting.
\r
907 if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))
\r
908 && CUtils::IsDefaultIgnoreApplication()) {
\r
912 switch (IsPassThrough(nKey)) {
\r
913 case GOTO_DO_NOTHING:
\r
924 // set command type
\r
925 nCommandType = IsDown(VK_SHIFT) * SHIFT | IsControl() * CONTROL | IsMeta() * META | CCommands::bC_x() * CONTROLX;
\r
926 // Ignore undefined C-x ?
\r
927 if (nCommandType & CONTROLX) {
\r
928 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL
\r
929 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {
\r
930 if (m_Config.bIgnoreUndefinedC_x[m_nApplicationID]) {
\r
931 CCommands::Reset(GOTO_HOOK);
\r
934 nCommandType &= ~CONTROLX;
\r
937 // Ignore undefined Meta Ctrl+?
\r
938 if (CCommands::bM_() && (nCommandType & CONTROL)) {
\r
939 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL
\r
940 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {
\r
941 if (m_Config.bIgnoreUndefinedMetaCtrl[m_nApplicationID]) {
\r
942 if (Original(CONTROL, nKey)) {
\r
943 Original(CONTROL, nKey, -1);
\r
946 CCommands::Reset(GOTO_HOOK);
\r
949 nCommandType &= ~META;
\r
954 BYTE nKey = (BYTE)wParam; // VK_CONTROL is needed instead of VK_RCONTROL and VK_LCONTROL in this block just for Original()
\r
955 int nVirtualCommandType = GetModifierState(FALSE);
\r
956 if (nKey == VK_CONTROL)
\r
957 nVirtualCommandType &= ~CONTROL;
\r
958 if (nKey == VK_MENU)
\r
959 nVirtualCommandType &= ~META;
\r
960 if (Original(nVirtualCommandType, nKey)) {
\r
961 Original(nVirtualCommandType, nKey, -1);
\r
966 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableOrDisableXKeymacs) {
\r
967 SetKeyboardHookFlag(!m_bHook);
\r
970 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableXKeymacs) {
\r
972 SetKeyboardHookFlag(!m_bHook);
\r
976 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DisableXKeymacs) {
\r
978 SetKeyboardHookFlag(!m_bHook);
\r
986 if (CCommands::bM_x()) {
\r
987 static unsigned int index = 0;
\r
988 static TCHAR szPath[MAX_PATH] = {'\0'};
\r
990 if (lParam & BEING_RELEASED) {
\r
992 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BackwardChar) {
\r
997 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BeginningOfLine) {
\r
1000 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteBackwardChar) {
\r
1003 memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);
\r
1004 SetM_xTip(szPath);
\r
1007 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteChar) {
\r
1008 if (index < _tcslen(szPath)) {
\r
1009 memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);
\r
1010 SetM_xTip(szPath);
\r
1013 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EndOfLine) {
\r
1014 index = _tcslen(szPath);
\r
1016 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::ForwardChar) {
\r
1017 if (index < _tcslen(szPath)) {
\r
1021 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::KeyboardQuit) {
\r
1022 CCommands::bM_x(FALSE);
\r
1024 memset(szPath, 0, sizeof(szPath));
\r
1026 } else if (nKey == VK_RETURN
\r
1027 || Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::Newline) {
\r
1028 InvokeM_x(szPath);
\r
1030 CCommands::bM_x(FALSE);
\r
1032 memset(szPath, 0, sizeof(szPath));
\r
1034 } else if (index < MAX_PATH - 1) {
\r
1035 const BOOL bIsShiftDown = IsDown(VK_SHIFT, FALSE);
\r
1036 for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow
\r
1037 if (nKey != 0 && a2v(nAscii) == nKey && bIsShiftDown == IsShift(nAscii)) {
\r
1038 // CUtils::Log("M-x: %#X (%c), %#X (%c)", nKey, nKey, nAscii, nAscii);
\r
1039 if (index < _tcslen(szPath)) {
\r
1040 memmove(&szPath[index + 1], &szPath[index], __min(_tcslen(szPath) - index, MAX_PATH - (index + 1) - 1));
\r
1042 szPath[index++] = nAscii;
\r
1043 // CUtils::Log("M-x: %c(%#04x)", nAscii, nAscii);
\r
1044 SetM_xTip(szPath);
\r
1051 if (CCommands::bC_u()) {
\r
1052 if ((nCommandType == NONE) && ('0' <= nKey) && (nKey <= '9')) {
\r
1053 CCommands::NumericArgument(nKey - '0');
\r
1056 if ((nCommandType == NONE) && (nKey == 0xBD)) {
\r
1057 CCommands::NumericArgumentMinus();
\r
1062 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrl) {
\r
1063 nOneShotModifier[nKey] = VK_LCONTROL;
\r
1064 DepressKey(nOneShotModifier[nKey]);
\r
1065 bCherryOneShotModifier = TRUE;
\r
1067 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {
\r
1068 nOneShotModifier[nKey] = VK_LCONTROL;
\r
1069 DepressKey(nOneShotModifier[nKey]);
\r
1070 bCherryOneShotModifier = TRUE;
\r
1072 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {
\r
1073 ReleaseKey(nOneShotModifier[nKey]);
\r
1074 bCherryOneShotModifier = FALSE;
\r
1077 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAlt) {
\r
1078 nOneShotModifier[nKey] = VK_LMENU;
\r
1079 DepressKey(nOneShotModifier[nKey]);
\r
1080 bCherryOneShotModifier = TRUE;
\r
1082 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {
\r
1083 nOneShotModifier[nKey] = VK_LMENU;
\r
1084 DepressKey(nOneShotModifier[nKey]);
\r
1085 bCherryOneShotModifier = TRUE;
\r
1087 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {
\r
1088 ReleaseKey(nOneShotModifier[nKey]);
\r
1089 bCherryOneShotModifier = FALSE;
\r
1092 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShift) {
\r
1093 nOneShotModifier[nKey] = VK_SHIFT;
\r
1094 DepressKey(nOneShotModifier[nKey]);
\r
1095 bCherryOneShotModifier = TRUE;
\r
1097 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {
\r
1098 nOneShotModifier[nKey] = VK_SHIFT;
\r
1099 DepressKey(nOneShotModifier[nKey]);
\r
1100 bCherryOneShotModifier = TRUE;
\r
1102 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {
\r
1103 ReleaseKey(nOneShotModifier[nKey]);
\r
1104 bCherryOneShotModifier = FALSE;
\r
1108 for (int i = 0; i < MAX_KEY; ++i) {
\r
1109 if (nOneShotModifier[i] == nKey) {
\r
1113 if (i == MAX_KEY) {
\r
1114 bCherryOneShotModifier = FALSE;
\r
1118 if (0 <= m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]
\r
1119 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < MAX_FUNCTION
\r
1120 && _tcslen(m_Config.szFunctionDefinition[m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]])) {
\r
1121 CallFunction(m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]);
\r
1122 CCommands::Reset(GOTO_HOOK);
\r
1126 if (!Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand) {
\r
1127 if (nKey == VK_CONTROL
\r
1128 || nKey == VK_LCONTROL
\r
1129 || nKey == VK_RCONTROL
\r
1130 || nKey == VK_MENU
\r
1131 || nKey == VK_LMENU
\r
1132 || nKey == VK_RMENU
\r
1133 || nKey == VK_SHIFT
\r
1134 || nKey == VK_LSHIFT
\r
1135 || nKey == VK_RSHIFT) {
\r
1139 if (!(nCommandType & SHIFT)) {
\r
1140 if (CCommands::IsSetMark()) {
\r
1141 if (CCommands::MoveCaret(nKey, nCommandType & CONTROL) != CONTINUE) {
\r
1142 CCommands::ClearNumericArgument();
\r
1145 CCommands::SetMark(FALSE);
\r
1149 if (1 < CCommands::GetNumericArgument()) {
\r
1150 Kdu(nKey, CCommands::GetNumericArgument());
\r
1151 CCommands::ClearNumericArgument();
\r
1158 if (CCommands::IsTemporarilyDisableXKeymacs()
\r
1159 && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand != CCommands::KeyboardQuit) {
\r
1160 CCommands::SetTemporarilyDisableXKeymacs(FALSE);
\r
1164 if (m_Config.bAtIbeamCursorOnly[m_nApplicationID][nCommandType][nKey]) {
\r
1165 CURSORINFO cursorinfo = { sizeof(cursorinfo) };
\r
1166 if (GetCursorInfo(&cursorinfo) && cursorinfo.flags && cursorinfo.hCursor != LoadCursor(NULL, IDC_IBEAM)) {
\r
1171 m_bRightControl = IsDown(VK_RCONTROL, FALSE);
\r
1172 m_bRightAlt = IsDown(VK_RMENU, FALSE);
\r
1173 m_bRightShift = IsDown(VK_RSHIFT, FALSE);
\r
1177 fCommand = Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand;
\r
1178 RECURSIVE_COMMAND:
\r
1179 switch (fCommand()) {
\r
1180 case GOTO_DO_NOTHING:
\r
1186 case GOTO_RECURSIVE:
\r
1191 case GOTO_HOOK0_9:
\r
1200 goto HOOK_RECURSIVE_KEY;
\r
1204 SetModifierIcons();
\r
1206 static BOOL bDefiningMacro = FALSE;
\r
1207 if (m_bDefiningMacro) {
\r
1208 static BOOL bDown[MAX_KEY] = {'\0'};
\r
1210 if (!bDefiningMacro) {
\r
1211 while (m_Macro.GetHeadPosition()) {
\r
1212 void *p = m_Macro.GetAt(m_Macro.GetHeadPosition());
\r
1213 m_Macro.RemoveHead();
\r
1217 memset(bDown, 0, sizeof(bDown));
\r
1220 if ((!(lParam & BEING_RELEASED)) || bDown[wParam]) {
\r
1222 KbdMacro *pKbdMacro = new KbdMacro;
\r
1224 pKbdMacro->nCode = nCode;
\r
1225 pKbdMacro->wParam = wParam;
\r
1226 pKbdMacro->lParam = lParam;
\r
1227 pKbdMacro->bOriginal = TRUE;
\r
1228 m_Macro.AddTail((CObject *)pKbdMacro);
\r
1231 catch (CMemoryException* e) {
\r
1233 // CUtils::Log("KeyboardProc: 'new' threw an exception");
\r
1235 if (!(lParam & BEING_RELEASED)) {
\r
1236 bDown[wParam] = TRUE;
\r
1240 bDefiningMacro = m_bDefiningMacro;
\r
1243 return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);
\r
1246 Kdu(RECURSIVE_KEY, 1, FALSE);
\r
1249 CCommands::SetLastCommand(fCommand);
\r
1252 SetModifierIcons();
\r
1253 HOOK_RECURSIVE_KEY:
\r
1257 void CXkeymacsDll::SetModifierIcons()
\r
1259 #define IconState(x) ((x) ? ON_ICON : OFF_ICON)
\r
1260 ICONMSG msg[6] = {
\r
1261 {MX_ICON, IconState(CCommands::bM_x()), ""},
\r
1262 {CX_ICON, IconState(CCommands::bC_x()), ""},
\r
1263 {META_ICON, IconState(CCommands::bM_()), ""},
\r
1264 {SHIFT_ICON, IconState(IsDown(VK_SHIFT, FALSE)), ""},
\r
1265 {CTRL_ICON, IconState(IsControl()), ""},
\r
1266 {ALT_ICON, IconState(IsDown(VK_MENU, FALSE)), ""}
\r
1268 _tcscpy_s(msg[0].szTip, m_M_xTip);
\r
1269 SendIconMessage(msg, 6);
\r
1272 void CXkeymacsDll::SetApplicationName(int nApplicationID, CString szApplicationName)
\r
1274 ZeroMemory(m_Config.szSpecialApp[nApplicationID], CLASS_NAME_LENGTH);
\r
1275 _tcsncpy_s(m_Config.szSpecialApp[nApplicationID], szApplicationName, _TRUNCATE);
\r
1278 void CXkeymacsDll::SetWindowText(int nApplicationID, CString szWindowText)
\r
1280 ZeroMemory(m_Config.szWindowText[nApplicationID], WINDOW_TEXT_LENGTH);
\r
1281 _tcsncpy_s(m_Config.szWindowText[nApplicationID], szWindowText, _TRUNCATE);
\r
1284 void CXkeymacsDll::SetCommandID(int nApplicationID, int nCommandType, int nKey, int nCommandID)
\r
1286 m_Config.nCommandID[nApplicationID][nCommandType][nKey] = nCommandID;
\r
1289 void CXkeymacsDll::SetAtIbeamCursorOnly(int nApplicationID, int nCommandType, int nKey, BOOL bAtIbeamCursorOnly)
\r
1291 m_Config.bAtIbeamCursorOnly[nApplicationID][nCommandType][nKey] = bAtIbeamCursorOnly;
\r
1294 void CXkeymacsDll::SetKillRingMax(int nApplicationID, int nKillRingMax)
\r
1296 m_Config.nKillRingMax[nApplicationID] = nKillRingMax;
\r
1299 void CXkeymacsDll::SetUseDialogSetting(int nApplicationID, BOOL bUseDialogSetting)
\r
1301 m_Config.bUseDialogSetting[nApplicationID] = bUseDialogSetting;
\r
1304 // Clear data of nApplicationID
\r
1305 void CXkeymacsDll::Clear(int nApplicationID)
\r
1307 if (0 <= nApplicationID && nApplicationID < MAX_APP) {
\r
1308 ZeroMemory(m_Config.szSpecialApp[nApplicationID], sizeof(m_Config.szSpecialApp[nApplicationID]));
\r
1309 ZeroMemory(m_Config.nCommandID[nApplicationID], sizeof(m_Config.nCommandID[nApplicationID]));
\r
1310 ZeroMemory(m_Config.bAtIbeamCursorOnly[nApplicationID], sizeof(m_Config.bAtIbeamCursorOnly[nApplicationID]));
\r
1311 m_Config.nKillRingMax[nApplicationID] = 0;
\r
1312 m_Config.bUseDialogSetting[nApplicationID] = FALSE;
\r
1313 m_Config.nSettingStyle[nApplicationID] = 0;
\r
1319 BOOL CXkeymacsDll::IsValidKey(BYTE bVk)
\r
1321 if (bVk == 0xf0) { // 0xf0: Eisu key. GetAsyncKeyState returns the wrong state of Eisu key.
\r
1337 BOOL CXkeymacsDll::IsDepressedModifier(int (__cdecl *Modifier)(void), BOOL bPhysicalKey)
\r
1341 if (IsValidKey(bVk) && IsDown(bVk, bPhysicalKey) &&
\r
1342 Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == Modifier)
\r
1348 BOOL CXkeymacsDll::IsDepressedShiftKeyOnly(BYTE nKey)
\r
1350 if (nKey != VK_SHIFT
\r
1351 && nKey != VK_LSHIFT
\r
1352 && nKey != VK_RSHIFT) {
\r
1358 if (bVk == VK_SHIFT
\r
1359 || bVk == VK_LSHIFT
\r
1360 || bVk == VK_RSHIFT) {
\r
1364 if (IsDown(bVk, FALSE)) {
\r
1371 BOOL CXkeymacsDll::IsControl()
\r
1373 return CCommands::bC_() || IsDepressedModifier(CCommands::C_);
\r
1376 BOOL CXkeymacsDll::IsMeta()
\r
1378 return CCommands::bM_() || IsDepressedModifier(CCommands::MetaAlt);
\r
1381 void CXkeymacsDll::AddKillRing(BOOL bNewData)
\r
1383 if (m_Config.nKillRingMax[m_nApplicationID] == 0) {
\r
1387 CClipboardSnap *pSnap = new CClipboardSnap;
\r
1388 if( !pSnap ) return;
\r
1390 BOOL bCapture = pSnap->Capture();
\r
1391 bCapture = pSnap->Capture(); // for "office drawing shape format". Can CClipboardSnap care this problem?
\r
1395 m_oKillRing.AddHead(pSnap);
\r
1397 if (m_oKillRing.IsEmpty()) {
\r
1398 m_oKillRing.AddHead(pSnap);
\r
1400 for (CClipboardSnap *pParent = m_oKillRing.GetHead(); pParent->GetNext(); pParent = pParent->GetNext()) {
\r
1403 pParent->SetNext(pSnap);
\r
1413 if (m_Config.nKillRingMax[m_nApplicationID] < m_oKillRing.GetCount()) {
\r
1414 CClipboardSnap *pSnap = m_oKillRing.GetTail();
\r
1417 m_oKillRing.RemoveTail();
\r
1421 // Return TRUE if there is another data
\r
1422 // Return FALSE if there is no more data
\r
1423 CClipboardSnap* CXkeymacsDll::GetKillRing(CClipboardSnap* pSnap, BOOL bForce)
\r
1425 if (m_Config.nKillRingMax[m_nApplicationID] == 0) {
\r
1429 if (m_oKillRing.IsEmpty()) {
\r
1433 m_nKillRing %= m_oKillRing.GetCount();
\r
1436 CClipboardSnap oCurrentSnap;
\r
1437 oCurrentSnap.Capture();
\r
1439 CClipboardSnap *pKillRing = m_oKillRing.GetAt(m_oKillRing.FindIndex(m_nKillRing));
\r
1443 for (; pKillRing->GetNext(); pKillRing = pKillRing->GetNext()) {
\r
1446 if (*pKillRing != oCurrentSnap) {
\r
1452 pSnap = m_oKillRing.GetAt(m_oKillRing.FindIndex(m_nKillRing));
\r
1456 return pSnap->GetNext();
\r
1459 void CXkeymacsDll::Original(int nCommandType, BYTE bVk, int nOriginal)
\r
1461 nCommandType &= ~SHIFT;
\r
1465 bVk = VK_LCONTROL;
\r
1477 m_nOriginal[nCommandType][bVk] += nOriginal;
\r
1480 int CXkeymacsDll::Original(int nCommandType, BYTE bVk)
\r
1482 nCommandType &= ~SHIFT;
\r
1486 bVk = VK_LCONTROL;
\r
1498 return m_nOriginal[nCommandType][bVk];
\r
1501 void CXkeymacsDll::IncreaseKillRingIndex(int nKillRing)
\r
1503 m_nKillRing += nKillRing;
\r
1507 int CXkeymacsDll::GetMickey(int nDifferential, int nThreshold1, int nThreshold2, int nAcceleration, int nSpeed)
\r
1509 nDifferential = nDifferential * 10 / nSpeed;
\r
1511 switch (nAcceleration) {
\r
1513 if (nThreshold2 < fabs((double)(nDifferential / 4))) {
\r
1514 nDifferential /= 4;
\r
1517 // Do NOT write break; here.
\r
1519 if (nThreshold1 < fabs((double)(nDifferential / 2))) {
\r
1520 nDifferential /= 2;
\r
1530 return nDifferential;
\r
1533 void CXkeymacsDll::SetSettingStyle(int nApplicationID, int nSettingStyle)
\r
1535 m_Config.nSettingStyle[nApplicationID] = nSettingStyle;
\r
1538 void CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(int nApplicationID, BOOL bIgnoreUndefinedMetaCtrl)
\r
1540 m_Config.bIgnoreUndefinedMetaCtrl[nApplicationID] = bIgnoreUndefinedMetaCtrl;
\r
1543 void CXkeymacsDll::SetIgnoreUndefinedC_x(int nApplicationID, BOOL bIgnoreUndefinedC_x)
\r
1545 m_Config.bIgnoreUndefinedC_x[nApplicationID] = bIgnoreUndefinedC_x;
\r
1548 void CXkeymacsDll::SetEnableCUA(int nApplicationID, BOOL bEnableCUA)
\r
1550 m_Config.bEnableCUA[nApplicationID] = bEnableCUA;
\r
1553 BOOL CXkeymacsDll::GetEnableCUA()
\r
1555 return m_Config.bEnableCUA[m_nApplicationID];
\r
1558 void CXkeymacsDll::DefiningMacro(BOOL bDefiningMacro)
\r
1560 m_bDefiningMacro = bDefiningMacro;
\r
1562 if (bDefiningMacro) { // start-kbd-macro
\r
1563 if (CCommands::bC_u()) {
\r
1564 ReleaseKey(VK_SHIFT);
\r
1567 } else { // end-kbd-macro
\r
1568 while (!m_Macro.IsEmpty()) {
\r
1569 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetTail();
\r
1570 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1573 m_Macro.RemoveTail();
\r
1579 // CUtils::Log(_T("Macro MemMap: start"));
\r
1580 if (!m_Macro.IsEmpty()) {
\r
1581 static HANDLE hMacro = NULL;
\r
1583 hMacro = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 0x3000, _T("macro"));
\r
1586 // CUtils::Log(_T("Macro MemMap: 1"));
\r
1587 PVOID pView = MapViewOfFile(hMacro, FILE_MAP_ALL_ACCESS, 0, 0, 0);
\r
1588 // CUtils::Log(_T("Macro MemMap: 2"));
\r
1590 // CUtils::Log(_T("Macro MemMap: 2.5"));
\r
1591 for (int i = 0; i < m_Macro.GetCount(); ++i) {
\r
1592 // CUtils::Log(_T("Macro MemMap: 3-1 %d"), i);
\r
1593 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetAt(m_Macro.FindIndex(i));
\r
1594 // CUtils::Log(_T("Macro MemMap: 3-2 %d"), i);
\r
1595 memcpy((LPTSTR) pView + i * sizeof(KbdMacro), pKbdMacro, sizeof(KbdMacro));
\r
1596 // CUtils::Log(_T("Macro MemMap: 3-3 %d"), i);
\r
1598 // CUtils::Log(_T("Macro MemMap: 4"));
\r
1599 UnmapViewOfFile(pView);
\r
1600 // CUtils::Log(_T("Macro MemMap: 5"));
\r
1602 // CUtils::Log(_T("Macro MemMpa: error: %d"), GetLastError());
\r
1605 // CUtils::Log(_T("Macro MemMap: 6"));
\r
1612 BOOL CXkeymacsDll::DefiningMacro()
\r
1614 return m_bDefiningMacro;
\r
1618 void CXkeymacsDll::CallMacro()
\r
1620 UINT before = GetModifierState(FALSE);
\r
1621 SetModifierState(0, before);
\r
1622 for (POSITION pos = m_Macro.GetHeadPosition(); pos; ) {
\r
1623 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetNext(pos);
\r
1624 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1625 ReleaseKey((BYTE)pKbdMacro->wParam);
\r
1627 DepressKey((BYTE)pKbdMacro->wParam, pKbdMacro->bOriginal);
\r
1630 SetModifierState(before, 0);
\r
1634 void CXkeymacsDll::CallMacro() // for debug
\r
1637 for (POSITION pos = m_Macro.GetHeadPosition(); pos; ) {
\r
1638 KbdMacro_t *pKbdMacro = (KbdMacro_t *)m_Macro.GetNext(pos);
\r
1639 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1641 t.Format(_T("0x%xu "), pKbdMacro->wParam);
\r
1645 t.Format(_T("0x%xd "), pKbdMacro->wParam);
\r
1649 // CUtils::Log(sz);
\r
1653 void CXkeymacsDll::Set106Keyboard(BOOL b106Keyboard)
\r
1655 m_Config.b106Keyboard = b106Keyboard;
\r
1658 BOOL CXkeymacsDll::Is106Keyboard()
\r
1660 return m_Config.b106Keyboard;
\r
1663 int CXkeymacsDll::IsPassThrough(BYTE nKey)
\r
1668 && (Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == CCommands::PassThrough)) {
\r
1669 if (bVk == nKey) {
\r
1673 return GOTO_DO_NOTHING;
\r
1679 void CXkeymacsDll::SetKeyboardHookFlag()
\r
1681 SetKeyboardHookFlag(m_bHook);
\r
1684 void CXkeymacsDll::SetFunctionKey(int nFunctionID, int nApplicationID, int nCommandType, int nKey)
\r
1686 if (nApplicationID < 0 || MAX_APP <= nApplicationID
\r
1687 || nCommandType < 0 || MAX_COMMAND_TYPE <= nCommandType
\r
1688 || nKey < 0 || MAX_KEY <= nKey) {
\r
1692 m_Config.nFunctionID[nApplicationID][nCommandType][nKey] = nFunctionID;
\r
1695 void CXkeymacsDll::ClearFunctionDefinition()
\r
1697 memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID));
\r
1698 memset(m_Config.szFunctionDefinition, 0, sizeof(m_Config.szFunctionDefinition));
\r
1701 void CXkeymacsDll::SetFunctionDefinition(int nFunctionID, CString szDefinition)
\r
1703 if (nFunctionID < 0 || MAX_FUNCTION <= nFunctionID) {
\r
1707 memset(m_Config.szFunctionDefinition[nFunctionID], 0, sizeof(m_Config.szFunctionDefinition[nFunctionID]));
\r
1708 _stprintf_s(m_Config.szFunctionDefinition[nFunctionID], _T("%s"), szDefinition);
\r
1714 // call an original command which is defined in dot.xkeymacs
\r
1715 void CXkeymacsDll::CallFunction(int nFunctionID)
\r
1717 CArray<KeyBind, KeyBind> keybinds;
\r
1719 if (nFunctionID < 0 || MAX_FUNCTION <= nFunctionID || !_tcslen(m_Config.szFunctionDefinition[nFunctionID])) {
\r
1723 UINT before = GetModifierState(FALSE);
\r
1725 if (m_Config.szFunctionDefinition[nFunctionID][0] == _T('"') && m_Config.szFunctionDefinition[nFunctionID][_tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1] == _T('"')) {
\r
1726 for (unsigned int i = 1; i < _tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1; ++i) { // skip '"'
\r
1727 keybinds.Add(ParseKey(nFunctionID, i));
\r
1729 } else if (m_Config.szFunctionDefinition[nFunctionID][0] == _T('[') && m_Config.szFunctionDefinition[nFunctionID][_tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1] == _T(']')) {
\r
1730 for (unsigned int i = 1; i < _tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1; ++i) { // skip '[' and ']'
\r
1731 if (m_Config.szFunctionDefinition[nFunctionID][i] == _T('?')) { // [?f ?o ?o]
\r
1733 keybinds.Add(ParseKey(nFunctionID, i));
\r
1734 } else { // [ControlCharacter]
\r
1735 for (int nKeyID = 0; nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0]); ++nKeyID) {
\r
1736 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, ControlCharacters[nKeyID].name, _tcslen(ControlCharacters[nKeyID].name))) {
\r
1737 KeyBind keybind = {NONE, ControlCharacters[nKeyID].bVk};
\r
1738 keybinds.Add(keybind);
\r
1739 i += _tcslen(ControlCharacters[nKeyID].name);
\r
1749 BOOL bM_x = FALSE;
\r
1750 TCHAR szPath[MAX_PATH] = {'\0'};
\r
1751 unsigned int index = 0;
\r
1752 BOOL bInitialized = FALSE;
\r
1754 for (int i = 0; i < keybinds.GetSize(); ++i) {
\r
1755 const int nCommandType = keybinds.GetAt(i).nCommandType;
\r
1756 const BYTE bVk = keybinds.GetAt(i).bVk;
\r
1758 if (nCommandType < MAX_COMMAND_TYPE && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand) {
\r
1759 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand == CCommands::ExecuteExtendedCommand) {
\r
1761 } else if (!bInitialized) {
\r
1762 SetModifierState(0, before);
\r
1763 bInitialized = TRUE;
\r
1765 // CUtils::Log("CallFunction: Command Name: %s", Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].szCommandName);
\r
1766 while (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand() == GOTO_RECURSIVE) {
\r
1769 } else if (bM_x) {
\r
1770 if (bVk == VK_RETURN) {
\r
1771 InvokeM_x(szPath);
\r
1773 for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow
\r
1774 if (bVk != 0 && a2v(nAscii) == bVk && ((nCommandType & SHIFT) != 0) == IsShift(nAscii)) {
\r
1775 // CUtils::Log("M-x: %#X (%c), %#X (%c)", bVk, bVk, nAscii, nAscii);
\r
1776 szPath[index++] = nAscii;
\r
1782 if (!bInitialized) {
\r
1783 SetModifierState(0, before);
\r
1784 bInitialized = TRUE;
\r
1786 if (nCommandType & WIN_WIN)
\r
1787 DepressKey(VK_LWIN);
\r
1788 if (nCommandType & WIN_CTRL)
\r
1789 DepressKey(VK_CONTROL);
\r
1790 if (nCommandType & WIN_ALT)
\r
1791 DepressKey(VK_MENU);
\r
1792 if (nCommandType & SHIFT)
\r
1793 DepressKey(VK_SHIFT);
\r
1797 if (nCommandType & SHIFT && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & SHIFT)))
\r
1798 ReleaseKey(VK_SHIFT);
\r
1799 if (nCommandType & WIN_ALT && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_ALT)))
\r
1800 ReleaseKey(VK_MENU);
\r
1801 if (nCommandType & WIN_CTRL && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_CTRL)))
\r
1802 ReleaseKey(VK_CONTROL);
\r
1803 if (nCommandType & WIN_WIN && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_WIN)))
\r
1804 ReleaseKey(VK_LWIN);
\r
1808 keybinds.RemoveAll();
\r
1811 // If these lines are invoked at M-x, a window transition does not work well.
\r
1812 SetModifierState(before, 0);
\r
1816 KeyBind CXkeymacsDll::ParseKey(const int nFunctionID, unsigned int &i)
\r
1818 KeyBind keybind = {NONE};
\r
1820 if (m_Config.szFunctionDefinition[nFunctionID][i] == _T('\\')) {
\r
1822 BOOL bFound = FALSE;
\r
1825 for (int ModifierID = 0; ModifierID < sizeof(Modifiers) / sizeof(Modifiers[0]); ++ModifierID) {
\r
1826 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, Modifiers[ModifierID].name, _tcslen(Modifiers[ModifierID].name))
\r
1827 && _tcslen(Modifiers[ModifierID].name) < _tcslen(m_Config.szFunctionDefinition[nFunctionID] + i)) {
\r
1828 keybind.nCommandType |= Modifiers[ModifierID].id;
\r
1829 i+= _tcslen(Modifiers[ModifierID].name);
\r
1835 if (IsShift(m_Config.szFunctionDefinition[nFunctionID][i]) && !(keybind.nCommandType & (WIN_CTRL | WIN_ALT | WIN_WIN))) {
\r
1836 keybind.nCommandType |= SHIFT;
\r
1839 for (int nKeyID = 0; nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0]); ++nKeyID) {
\r
1840 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, ControlCharacters[nKeyID].name, _tcslen(ControlCharacters[nKeyID].name))) {
\r
1841 i += _tcslen(ControlCharacters[nKeyID].name);
\r
1845 if (nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0])) {
\r
1846 keybind.bVk = ControlCharacters[nKeyID].bVk;
\r
1848 keybind.bVk = a2v(m_Config.szFunctionDefinition[nFunctionID][i]);
\r
1854 BOOL CXkeymacsDll::IsShift(TCHAR nAscii)
\r
1867 return m_Config.b106Keyboard;
\r
1877 case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'):
\r
1880 return !m_Config.b106Keyboard;
\r
1886 return m_Config.b106Keyboard;
\r
1891 return !m_Config.b106Keyboard;
\r
1892 case _T('A'): case _T('B'): case _T('C'): case _T('D'): case _T('E'): case _T('F'): case _T('G'): case _T('H'): case _T('I'): case _T('J'):
\r
1893 case _T('K'): case _T('L'): case _T('M'): case _T('N'): case _T('O'): case _T('P'): case _T('Q'): case _T('R'): case _T('S'): case _T('T'):
\r
1894 case _T('U'): case _T('V'): case _T('W'): case _T('X'): case _T('Y'): case _T('Z'):
\r
1901 return !m_Config.b106Keyboard;
\r
1905 return m_Config.b106Keyboard;
\r
1906 case _T('a'): case _T('b'): case _T('c'): case _T('d'): case _T('e'): case _T('f'): case _T('g'): case _T('h'): case _T('i'): case _T('j'):
\r
1907 case _T('k'): case _T('l'): case _T('m'): case _T('n'): case _T('o'): case _T('p'): case _T('q'): case _T('r'): case _T('s'): case _T('t'):
\r
1908 case _T('u'): case _T('v'): case _T('w'): case _T('x'): case _T('y'): case _T('z'):
\r
1920 BYTE CXkeymacsDll::a2v(TCHAR nAscii)
\r
1928 return m_Config.b106Keyboard ? '2' : (BYTE) 0xde; // VK_OEM_7
\r
1936 return m_Config.b106Keyboard ? '6' : '7';
\r
1938 return m_Config.b106Keyboard ? '7' : (BYTE) 0xde; // VK_OEM_7
\r
1940 return m_Config.b106Keyboard ? '8' : '9';
\r
1942 return m_Config.b106Keyboard ? '9' : '0';
\r
1944 return m_Config.b106Keyboard ? (BYTE) 0xba : '8'; // VK_OEM_1
\r
1946 return 0xbb; // VK_OEM_PLUS
\r
1948 return 0xbc; // VK_OEM_COMMA
\r
1950 return 0xbd; // VK_OEM_MINUS
\r
1952 return 0xbe; // VK_OEM_PERIOD
\r
1954 return 0xbf; // VK_OEM_2
\r
1955 case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'):
\r
1958 return 0xba; // VK_OEM_1
\r
1960 return m_Config.b106Keyboard ? (BYTE) 0xbb : (BYTE) 0xba; // VK_OEM_PLUS VK_OEM_1
\r
1962 return 0xbc; // VK_OEM_COMMA
\r
1964 return m_Config.b106Keyboard ? (BYTE) 0xbd : (BYTE) 0xbb; // VK_OEM_MINUS VK_OEM_PLUS
\r
1966 return 0xbe; // VK_OEM_PERIOD
\r
1968 return 0xbf; // VK_OEM_2
\r
1970 return m_Config.b106Keyboard ? (BYTE) 0xc0 : '2';
\r
1971 case _T('A'): case _T('B'): case _T('C'): case _T('D'): case _T('E'): case _T('F'): case _T('G'): case _T('H'): case _T('I'): case _T('J'):
\r
1972 case _T('K'): case _T('L'): case _T('M'): case _T('N'): case _T('O'): case _T('P'): case _T('Q'): case _T('R'): case _T('S'): case _T('T'):
\r
1973 case _T('U'): case _T('V'): case _T('W'): case _T('X'): case _T('Y'): case _T('Z'):
\r
1976 return 0xdb; // VK_OEM_4
\r
1978 return 0xdc; // VK_OEM_5
\r
1980 return 0xdd; // VK_OEM_6
\r
1982 return m_Config.b106Keyboard ? (BYTE) 0xde : '6'; // VK_OEM_7
\r
1984 return m_Config.b106Keyboard ? (BYTE) 0xe2 : (BYTE) 0xbd; // VK_OEM_102 VK_OEM_MINUS
\r
1986 return 0xc0; // VK_OEM_3
\r
1987 case _T('a'): case _T('b'): case _T('c'): case _T('d'): case _T('e'): case _T('f'): case _T('g'): case _T('h'): case _T('i'): case _T('j'):
\r
1988 case _T('k'): case _T('l'): case _T('m'): case _T('n'): case _T('o'): case _T('p'): case _T('q'): case _T('r'): case _T('s'): case _T('t'):
\r
1989 case _T('u'): case _T('v'): case _T('w'): case _T('x'): case _T('y'): case _T('z'):
\r
1990 return (BYTE) (nAscii - (_T('a') - _T('A')));
\r
1992 return 0xdb; // VK_OEM_4
\r
1994 return 0xdc; // VK_OEM_5
\r
1996 return 0xdd; // VK_OEM_6
\r
1998 return m_Config.b106Keyboard ? (BYTE) 0xde : (BYTE) 0xc0; // VK_OEM_7 VK_OEM_3
\r
2004 BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText)
\r
2006 BOOL bIsMatchWindowText = TRUE;
\r
2008 TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
2009 GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText));
\r
2011 switch (CUtils::GetWindowTextType(szWindowText)) {
\r
2012 case IDS_WINDOW_TEXT_MATCH: // *foo*
\r
2013 szWindowText.Delete(0); // Delete first '*'
\r
2014 szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'
\r
2015 bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText);
\r
2017 case IDS_WINDOW_TEXT_MATCH_FORWARD: // foo*
\r
2018 szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'
\r
2019 bIsMatchWindowText = 0 == CString(szCurrentWindowText).Find(szWindowText);
\r
2021 case IDS_WINDOW_TEXT_MATCH_BACKWARD: // *foo
\r
2022 szWindowText.Delete(0); // Delete first '*'
\r
2023 bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText, CString(szCurrentWindowText).GetLength() - szWindowText.GetLength());
\r
2025 case IDS_WINDOW_TEXT_MATCH_FULL: // foo
\r
2026 bIsMatchWindowText = szWindowText == CString(szCurrentWindowText);
\r
2028 case IDS_WINDOW_TEXT_IGNORE: // *
\r
2029 bIsMatchWindowText = TRUE;
\r
2036 // CUtils::Log(_T("IsMatchWindowText: %d, _%s_, _%s_"), bIsMatchWindowText, szCurrentWindowText, szWindowText);
\r
2037 return bIsMatchWindowText;
\r
2040 void CXkeymacsDll::SetAccelerate(int nAccelerate)
\r
2042 m_nAccelerate = nAccelerate;
\r
2045 int CXkeymacsDll::GetAccelerate()
\r
2047 return m_nAccelerate;
\r
2050 void CXkeymacsDll::SetKeyboardSpeed(int nKeyboardSpeed)
\r
2052 m_nKeyboardSpeed = nKeyboardSpeed;
\r
2055 unsigned int CXkeymacsDll::GetMaxKeyInterval()
\r
2057 // m_nKeyboardSpeed == 0: slowest repeat rate; approximately 2 characters per second
\r
2058 // m_nKeyboardSpeed == 31: fastest repeat rate; approximately 30 characters per second
\r
2059 // 47 ms is max on my machine w/ KeyboardSpeed 31.
\r
2060 // 1000 / 2 + 50 = 550
\r
2061 // 1000 / 30 + 50 = 83
\r
2062 return (unsigned int) (1000.0 / (2.0 + m_nKeyboardSpeed % 32 * 28.0 / 31.0) + 50.0);
\r
2065 void CXkeymacsDll::SetCursorData(HCURSOR hEnable, HCURSOR hDisableTMP, HCURSOR hDisableWOCQ, HICON hDisable, BOOL bEnable)
\r
2067 m_hCursor[STATUS_ENABLE] = hEnable;
\r
2068 m_hCursor[STATUS_DISABLE_TMP] = hDisableTMP;
\r
2069 m_hCursor[STATUS_DISABLE_WOCQ] = hDisableWOCQ;
\r
2070 m_hCursor[STATUS_DISABLE] = hDisable;
\r
2071 m_bCursor = bEnable;
\r
2074 void CXkeymacsDll::DoSetCursor()
\r
2076 if (m_bCursor && m_hCurrentCursor) {
\r
2077 ::SetCursor(m_hCurrentCursor);
\r
2081 void CXkeymacsDll::Set326Compatible(int nApplicationID, BOOL b326Compatible)
\r
2083 m_Config.b326Compatible[nApplicationID] = b326Compatible;
\r
2086 BOOL CXkeymacsDll::Get326Compatible()
\r
2088 return m_Config.b326Compatible[m_nApplicationID];
\r
2091 void CXkeymacsDll::InvokeM_x(const TCHAR *const szPath)
\r
2093 // CUtils::Log("M-x: szPath=_%s_", szPath);
\r
2094 int (*fCommand)() = NULL;
\r
2096 for (int i = 0; i < MAX_COMMAND; ++i) {
\r
2097 if (_tcsicmp(szPath, Commands[i].szCommandName) == 0) {
\r
2098 fCommand = Commands[i].fCommand;
\r
2104 // CUtils::Log("M-x: Command: _%s_", Commands[i].szCommandName);
\r
2107 // CUtils::Log("M-x: Path: _%s_", szPath);
\r
2108 ShellExecute(NULL, NULL, szPath, NULL, NULL, SW_SHOWNORMAL);
\r
2112 void CXkeymacsDll::SetM_xTip(const TCHAR *const szPath)
\r
2114 _tcscpy_s(m_M_xTip, "M-x LED");
\r
2115 if (szPath && _tcslen(szPath) < 128 - 5)
\r
2116 _stprintf_s(m_M_xTip, "M-x %s", szPath);
\r
2119 BOOL CXkeymacsDll::SendIconMessage(ICONMSG *pMsg, DWORD num)
\r
2122 return CallNamedPipe(ICON_PIPE, pMsg, sizeof(ICONMSG) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
\r