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 static __declspec(thread) HINSTANCE g_hDllInst = NULL;
\r
142 static __declspec(thread) HHOOK g_hHookKeyboard = NULL;
\r
144 extern "C" int APIENTRY
\r
145 DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
\r
147 g_hDllInst = hInstance;
\r
149 // Remove this if you use lpReserved
\r
150 UNREFERENCED_PARAMETER(lpReserved);
\r
152 switch (dwReason) {
\r
153 case DLL_PROCESS_ATTACH:
\r
154 TRACE0("XKEYMACSDLL.DLL Initializing!\n");
\r
156 // Extension DLL one-time initialization
\r
157 if (!AfxInitExtensionModule(XkeymacsdllDLL, hInstance)) {
\r
161 // Insert this DLL into the resource chain
\r
162 // NOTE: If this Extension DLL is being implicitly linked to by
\r
163 // an MFC Regular DLL (such as an ActiveX Control)
\r
164 // instead of an MFC application, then you will want to
\r
165 // remove this line from DllMain and put it in a separate
\r
166 // function exported from this Extension DLL. The Regular DLL
\r
167 // that uses this Extension DLL should then explicitly call that
\r
168 // function to initialize this Extension DLL. Otherwise,
\r
169 // the CDynLinkLibrary object will not be attached to the
\r
170 // Regular DLL's resource chain, and serious problems will
\r
174 new CDynLinkLibrary(XkeymacsdllDLL);
\r
176 catch (CMemoryException* e) {
\r
178 // CUtils::Log("DllMain: 'new' threw an exception");
\r
180 case DLL_THREAD_ATTACH:
\r
181 CXkeymacsDll::SetKeyboardHook();
\r
183 case DLL_PROCESS_DETACH:
\r
184 TRACE0("XKEYMACSDLL.DLL Terminating!\n");
\r
185 // Terminate the library before destructors are called
\r
186 AfxTermExtensionModule(XkeymacsdllDLL);
\r
187 case DLL_THREAD_DETACH:
\r
188 CXkeymacsDll::ReleaseKeyboardHook();
\r
193 //////////////////////////////////////////////////////////////////////
\r
194 // CXkeymacsDll Class
\r
195 //////////////////////////////////////////////////////////////////////
\r
197 #include "xkeymacsDll.h"
\r
198 #pragma data_seg(".xkmcs")
\r
199 BOOL CXkeymacsDll::m_bHookAltRelease = FALSE;
\r
200 BOOL CXkeymacsDll::m_bEnableKeyboardHook = FALSE;
\r
201 HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;
\r
202 HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;
\r
203 HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;
\r
204 HHOOK CXkeymacsDll::m_hHookShell = NULL;
\r
205 BOOL CXkeymacsDll::m_bRightControl = FALSE;
\r
206 BOOL CXkeymacsDll::m_bRightAlt = FALSE;
\r
207 BOOL CXkeymacsDll::m_bRightShift = FALSE;
\r
208 BOOL CXkeymacsDll::m_bHook = TRUE;
\r
209 BOOL CXkeymacsDll::m_bDefiningMacro = FALSE;
\r
210 CList<CClipboardSnap *, CClipboardSnap *> CXkeymacsDll::m_oKillRing;
\r
211 CObList CXkeymacsDll::m_Macro;
\r
212 int CXkeymacsDll::m_nKillRing = 0;
\r
213 int CXkeymacsDll::m_nOriginal[MAX_COMMAND_TYPE][MAX_KEY] = {'\0'};
\r
214 int CXkeymacsDll::m_nApplicationID = 0;
\r
215 int CXkeymacsDll::m_nAccelerate = 0;
\r
216 int CXkeymacsDll::m_nKeyboardSpeed = 31;
\r
217 HCURSOR CXkeymacsDll::m_hCursor[MAX_STATUS] = {'\0'};
\r
218 HCURSOR CXkeymacsDll::m_hCurrentCursor = NULL;
\r
219 BOOL CXkeymacsDll::m_bCursor = FALSE;
\r
220 TCHAR CXkeymacsDll::m_M_xTip[128] = "";
\r
221 CONFIG CXkeymacsDll::m_Config = {0};
\r
224 //////////////////////////////////////////////////////////////////////
\r
225 // Construction/Destruction
\r
226 //////////////////////////////////////////////////////////////////////
\r
228 CXkeymacsDll::CXkeymacsDll()
\r
233 CXkeymacsDll::~CXkeymacsDll()
\r
238 BOOL CXkeymacsDll::SaveConfig()
\r
240 TCHAR szTmp[MAX_PATH];
\r
241 if (!GetTempPath(MAX_PATH, szTmp))
\r
243 if (_tmakepath_s(szTmp, NULL, szTmp, _T("xkeymacs"), _T("tmp")))
\r
245 HANDLE hFile = CreateFile(szTmp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
\r
246 if (hFile == INVALID_HANDLE_VALUE)
\r
249 BOOL res = WriteFile(hFile, &m_Config, sizeof(m_Config), &written, NULL) || written != sizeof(m_Config);
\r
250 CloseHandle(hFile);
\r
254 BOOL CXkeymacsDll::LoadConfig()
\r
256 TCHAR szTmp[MAX_PATH];
\r
257 if (!GetTempPath(MAX_PATH, szTmp))
\r
259 if (_tmakepath_s(szTmp, NULL, szTmp, _T("xkeymacs"), _T("tmp")))
\r
261 HANDLE hFile = CreateFile(szTmp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
\r
262 if (hFile == INVALID_HANDLE_VALUE)
\r
265 BOOL res = ReadFile(hFile, &m_Config, sizeof(m_Config), &read, NULL) && read == sizeof(m_Config);
\r
266 CloseHandle(hFile);
\r
270 void CXkeymacsDll::SetHookAltRelease()
\r
272 m_bHookAltRelease = TRUE;
\r
276 void CXkeymacsDll::SetHooks()
\r
278 m_hHookCallWnd = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, g_hDllInst, 0);
\r
279 m_hHookCallWndRet = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)CallWndRetProc, g_hDllInst, 0);
\r
280 m_hHookGetMessage = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgProc, g_hDllInst, 0);
\r
281 m_hHookShell = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, g_hDllInst, 0);
\r
284 void CXkeymacsDll::EnableKeyboardHook()
\r
286 m_bEnableKeyboardHook = TRUE;
\r
289 void CXkeymacsDll::SetKeyboardHook()
\r
291 if (!g_hHookKeyboard)
\r
292 SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, g_hDllInst, GetCurrentThreadId());
\r
296 void CXkeymacsDll::ReleaseHooks()
\r
298 m_bEnableKeyboardHook = FALSE;
\r
299 if (m_hHookCallWnd)
\r
300 UnhookWindowsHookEx(m_hHookCallWnd);
\r
301 m_hHookCallWnd = NULL;
\r
302 if (m_hHookCallWndRet)
\r
303 UnhookWindowsHookEx(m_hHookCallWndRet);
\r
304 m_hHookCallWndRet = NULL;
\r
305 if (m_hHookGetMessage)
\r
306 UnhookWindowsHookEx(m_hHookGetMessage);
\r
307 m_hHookGetMessage = NULL;
\r
309 UnhookWindowsHookEx(m_hHookShell);
\r
310 m_hHookShell = NULL;
\r
313 void CXkeymacsDll::ReleaseKeyboardHook()
\r
315 if (g_hHookKeyboard)
\r
316 UnhookWindowsHookEx(g_hHookKeyboard);
\r
317 g_hHookKeyboard = NULL;
\r
320 void CXkeymacsDll::SetKeyboardHookFlag(BOOL bFlag)
\r
323 ICONMSG msg = {MAIN_ICON,};
\r
325 if (CCommands::IsTemporarilyDisableXKeymacs()) {
\r
326 msg.nState = STATUS_DISABLE_TMP;
\r
327 m_hCurrentCursor = m_hCursor[STATUS_DISABLE_TMP];
\r
329 msg.nState = STATUS_ENABLE;
\r
330 m_hCurrentCursor = m_hCursor[STATUS_ENABLE];
\r
333 msg.nState = STATUS_DISABLE_WOCQ;
\r
335 if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE
\r
336 || (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))
\r
337 && CUtils::IsDefaultIgnoreApplication())) {
\r
338 msg.nState = STATUS_DISABLE;
\r
339 m_hCurrentCursor = m_hCursor[STATUS_DISABLE];
\r
341 SendIconMessage(&msg, 1);
\r
345 // if be keyboard hook, return TRUE
\r
346 BOOL CXkeymacsDll::IsKeyboardHook()
\r
355 void CXkeymacsDll::LogCallWndProcMessage(WPARAM wParam, LPARAM lParam)
\r
357 CWPSTRUCT &cwps = *(CWPSTRUCT *)lParam;
\r
359 switch (cwps.message) {
\r
360 case WM_PAINT: // 0x000F
\r
361 case WM_MDIGETACTIVE: // 0x0229
\r
368 case WM_CREATE: // 0x0001
\r
369 // CUtils::Log(_T("CallWndProc: cwps.message = WM_CREATE"));
\r
371 case WM_DESTROY: // 0x0002
\r
372 // CUtils::Log(_T("CallWndProc: cwps.message = WM_DESTROY"));
\r
374 case WM_MOVE: // 0x0003
\r
375 // CUtils::Log(_T("CallWndProc: cwps.message = WM_MOVE");)
\r
377 case WM_SIZE: // 0x0005
\r
378 // CUtils::Log(_T("CallWndProc: cwps.message = WM_SIZE"));
\r
380 case WM_GETTEXT: // 0x000D
\r
381 // CUtils::Log(_T("CallWndProc: cwps.message = WM_GETTEXT"));
\r
383 case WM_ERASEBKGND: // 0x0014
\r
384 // CUtils::Log(_T("CallWndProc: cwps.message = WM_ERASEBKGND"));
\r
386 case WM_WINDOWPOSCHANGING: // 0x0046
\r
387 // CUtils::Log(_T("CallWndProc: cwps.message = WM_WINDOWPOSCHANGING"));
\r
389 case WM_WINDOWPOSCHANGED: // 0x0047
\r
390 // CUtils::Log(_T("CallWndProc: cwps.message = WM_WINDOWPOSCHANGED"));
\r
392 case WM_COPYDATA: // 0x004A
\r
393 // CUtils::Log(_T("CallWndProc: cwps.message = WM_COPYDATA"));
\r
395 case WM_NCCREATE: // 0x0081
\r
396 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCCREATE"));
\r
398 case WM_NCDESTROY: // 0x0082
\r
399 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCDESTROY"));
\r
401 case WM_NCCALCSIZE: // 0x0083
\r
402 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCCALCSIZE"));
\r
404 case WM_NCPAINT: // 0x0085
\r
405 // CUtils::Log(_T("CallWndProc: cwps.message = WM_NCPAINT"));
\r
407 case WM_IME_STARTCOMPOSITION: // 0x010D
\r
408 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_STARTCOMPOSITION"));
\r
410 case WM_IME_ENDCOMPOSITION: // 0x010E
\r
411 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_ENDCOMPOSITION"));
\r
413 case WM_IME_KEYLAST: // 0x010F
\r
414 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_KEYLAST"));
\r
416 case WM_COMMAND: // 0x0111
\r
417 // CUtils::Log(_T("CallWndProc: cwps.message = WM_COMMAND"));
\r
419 case WM_CTLCOLOREDIT: // 0x0133
\r
420 // CUtils::Log(_T("CallWndProc: cwps.message = WM_CTLCOLOREDIT"));
\r
422 case WM_POWERBROADCAST: // 0x0218
\r
423 // CUtils::Log(_T("CallWndProc: cwps.message = WM_POWERBROADCAST"));
\r
425 case PBT_APMQUERYSUSPEND: // 0x0000
\r
426 // CUtils::Log(_T("PBT_APMQUERYSUSPEND"));
\r
428 case PBT_APMQUERYSTANDBY: // 0x0001
\r
429 // CUtils::Log(_T("PBT_APMQUERYSTANDBY"));
\r
431 case PBT_APMQUERYSUSPENDFAILED: // 0x0002
\r
432 // CUtils::Log(_T("PBT_APMQUERYSUSPENDFAILED"));
\r
434 case PBT_APMQUERYSTANDBYFAILED: // 0x0003
\r
435 // CUtils::Log(_T("PBT_APMQUERYSTANDBYFAILED"));
\r
437 case PBT_APMSUSPEND: // 0x0004
\r
438 // CUtils::Log(_T("PBT_APMSUSPEND"));
\r
440 case PBT_APMSTANDBY: // 0x0005
\r
441 // CUtils::Log(_T("PBT_APMSTANDBY"));
\r
443 case PBT_APMRESUMECRITICAL: // 0x0006
\r
444 // CUtils::Log(_T("PBT_APMRESUMECRITICAL"));
\r
446 case PBT_APMRESUMESUSPEND: // 0x0007
\r
447 // CUtils::Log(_T("PBT_APMRESUMESUSPEND"));
\r
449 case PBT_APMRESUMESTANDBY: // 0x0008
\r
450 // CUtils::Log(_T("PBT_APMRESUMESTANDBY"));
\r
452 case PBT_APMBATTERYLOW: // 0x0009
\r
453 // CUtils::Log(_T("PBT_APMBATTERYLOW"));
\r
455 case PBT_APMPOWERSTATUSCHANGE: // 0x000A
\r
456 // CUtils::Log(_T("PBT_APMPOWERSTATUSCHANGE"));
\r
458 case PBT_APMOEMEVENT: // 0x000B
\r
459 // CUtils::Log(_T("PBT_APMOEMEVENT"));
\r
461 case PBT_APMRESUMEAUTOMATIC: // 0x0012
\r
462 // CUtils::Log(_T("PBT_APMRESUMEAUTOMATIC"));
\r
465 // CUtils::Log(_T("PBT_OTHERS: %d"), wParam);
\r
469 case WM_IME_NOTIFY: // 0x0282
\r
470 // CUtils::Log(_T("CallWndProc: cwps.message = WM_IME_NOTIFY"));
\r
473 // CUtils::Log(_T("CallWndProc: cwps.message = 0x%04X"), cwps.message);
\r
478 LRESULT CALLBACK CXkeymacsDll::CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
480 // LogCallWndProcMessage(wParam, lParam);
\r
483 CWPSTRUCT &cwps = *(CWPSTRUCT *)lParam;
\r
484 switch (cwps.message) {
\r
485 case WM_IME_STARTCOMPOSITION:
\r
486 InitKeyboardProc(TRUE);
\r
488 case WM_IME_ENDCOMPOSITION:
\r
489 InitKeyboardProc(FALSE);
\r
492 if (cwps.hwnd == GetForegroundWindow()) {
\r
493 InitKeyboardProc(FALSE);
\r
494 SetKeyboardHookFlag(m_bHook);
\r
497 case WM_NCACTIVATE:
\r
499 if (cwps.hwnd == GetForegroundWindow()) {
\r
500 InitKeyboardProc(FALSE);
\r
501 SetKeyboardHookFlag(m_bHook);
\r
505 case WM_POWERBROADCAST:
\r
507 case PBT_APMRESUMECRITICAL: // 0x0006
\r
508 case PBT_APMRESUMESUSPEND: // 0x0007
\r
509 case PBT_APMRESUMESTANDBY: // 0x0008
\r
521 return CallNextHookEx(m_hHookCallWnd, nCode, wParam, lParam);
\r
524 LRESULT CALLBACK CXkeymacsDll::CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
527 CWPRETSTRUCT &cwprets = *(CWPRETSTRUCT *)lParam;
\r
528 switch (cwprets.message) {
\r
530 if (cwprets.hwnd == GetForegroundWindow()) {
\r
531 InitKeyboardProc(FALSE);
\r
541 return CallNextHookEx(m_hHookCallWndRet, nCode, wParam, lParam);
\r
544 LRESULT CALLBACK CXkeymacsDll::GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
546 MSG &msg = (*(MSG *)lParam);
\r
548 switch (msg.message) {
\r
549 case WM_IME_STARTCOMPOSITION:
\r
550 InitKeyboardProc(TRUE);
\r
552 case WM_IME_ENDCOMPOSITION:
\r
553 InitKeyboardProc(FALSE);
\r
556 return CallNextHookEx(m_hHookGetMessage, nCode, wParam, lParam);
\r
559 LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
562 case HSHELL_WINDOWACTIVATED:
\r
564 TCHAR className[256];
\r
565 ::GetClassName((HWND)wParam, className, 255);
\r
566 if (!_tcsicmp(className, _T("ConsoleWindowClass"))) {
\r
567 InitKeyboardProc(FALSE);
\r
568 SetKeyboardHookFlag(m_bHook);
\r
575 return CallNextHookEx( m_hHookShell, nCode, wParam, lParam );
\r
578 // return true if the key is down
\r
579 BOOL CXkeymacsDll::IsDown(BYTE bVk, BOOL bPhysicalKey)
\r
581 if (bPhysicalKey) {
\r
582 return GetKeyState(bVk) < 0;
\r
584 return GetAsyncKeyState(bVk) < 0;
\r
589 void CXkeymacsDll::DoKeybd_event(BYTE bVk, DWORD dwFlags)
\r
591 // Set KEYEVENTF_EXTENDEDKEY if needed
\r
594 if (m_bRightControl) { // Right Ctrl
\r
595 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
600 if (m_bRightAlt) { // Right Alt
\r
601 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
602 // CUtils::Log("Right Alt %d", dwFlags);
\r
604 // CUtils::Log("Left Alt %d", dwFlags);
\r
609 if (m_bRightShift) { // Right Shift
\r
610 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
615 if (IsDown(VK_CONTROL)) { // Break
\r
616 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
632 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
639 // CUtils::Log(_T("b: %x, %x, %x, %#x, %#x"), bVk, dwFlags, GetMessageExtraInfo(), GetKeyState(bVk), GetAsyncKeyState(bVk));
\r
640 keybd_event(bVk, 0, dwFlags, GetMessageExtraInfo());
\r
641 // CUtils::Log(_T("a: %x, %x, %x, %#x, %#x"), bVk, dwFlags, GetMessageExtraInfo(), GetKeyState(bVk), GetAsyncKeyState(bVk));
\r
644 // the key is being depressed
\r
645 void CXkeymacsDll::DepressKey(BYTE bVk, BOOL bOriginal) // bVk is virtual-key code, MSDN said
\r
648 // CUtils::Log(_T("i: %x, %d, %d, %d, %d, %d, %d, %d, %d"), bVk,
\r
649 // IsDown(VK_CONTROL), IsDown(VK_CONTROL, FALSE), IsDepressedModifier(CCommands::C_), IsDepressedModifier(CCommands::C_, FALSE),
\r
650 // IsDown(VK_MENU), IsDown(VK_MENU, FALSE), IsDepressedModifier(CCommands::MetaAlt), IsDepressedModifier(CCommands::MetaAlt, FALSE));
\r
652 int nCommandType = NONE;
\r
653 if (IsDown(VK_CONTROL, FALSE)) {
\r
654 nCommandType |= CONTROL;
\r
656 if (IsDown(VK_MENU, FALSE)) {
\r
657 nCommandType |= META;
\r
659 Original(nCommandType, bVk, 1);
\r
662 DoKeybd_event(bVk, 0);
\r
665 // the key is being released
\r
666 void CXkeymacsDll::ReleaseKey(BYTE bVk) // bVk is virtual-key code, MSDN said
\r
668 DoKeybd_event(bVk, KEYEVENTF_KEYUP);
\r
671 // bVk down, bVk up
\r
672 void CXkeymacsDll::Kdu(BYTE bVk, DWORD n, BOOL bOriginal)
\r
675 DepressKey(bVk, bOriginal);
\r
680 void CXkeymacsDll::InitKeyboardProc(BOOL bImeComposition)
\r
682 if (CUtils::IsFindDialog()) {
\r
683 static BOOL bImeCompositionOld = FALSE;
\r
684 if (!bImeComposition
\r
685 && bImeCompositionOld) {
\r
686 DepressKey(VK_END);
\r
687 ReleaseKey(VK_END);
\r
689 bImeCompositionOld = bImeComposition;
\r
692 CUtils::SetApplicationName(bImeComposition);
\r
694 if (_tcsnicmp(m_Config.szSpecialApp[m_nApplicationID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nApplicationID])) { // PROCESSENTRY32 has only 0xF bytes of Name
\r
695 m_nApplicationID = -1;
\r
697 for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {
\r
698 if (!_tcsnicmp(m_Config.szSpecialApp[nApplicationID], CUtils::GetApplicationName(), 0xF) && IsMatchWindowText(m_Config.szWindowText[nApplicationID])) {
\r
700 if (m_nApplicationID < 0
\r
701 || CUtils::GetWindowTextType(m_Config.szWindowText[m_nApplicationID]) < CUtils::GetWindowTextType(m_Config.szWindowText[nApplicationID])
\r
702 || CUtils::GetWindowTextType(m_Config.szWindowText[m_nApplicationID]) == CUtils::GetWindowTextType(m_Config.szWindowText[nApplicationID])
\r
703 && _tcscmp(m_Config.szWindowText[m_nApplicationID], m_Config.szWindowText[nApplicationID]) <= 0) {
\r
704 m_nApplicationID = nApplicationID;
\r
709 if (m_nApplicationID < 0) {
\r
710 for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {
\r
711 if (!_tcsicmp(m_Config.szSpecialApp[nApplicationID], _T("Default"))) {
\r
712 m_nApplicationID = nApplicationID;
\r
717 if (m_nApplicationID < 0) {
\r
718 m_nApplicationID = 0;
\r
723 if (m_Config.nSettingStyle[m_nApplicationID] != SETTING_DISABLE
\r
724 && (_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default")) || !CUtils::IsDefaultIgnoreApplication())
\r
725 && !bImeComposition
\r
726 && CUtils::IsDialog()) {
\r
727 // Use Dialog Setting
\r
728 if (m_Config.bUseDialogSetting[m_nApplicationID]) {
\r
729 int nOriginalApplicationID = m_nApplicationID;
\r
730 for (m_nApplicationID = 0; m_nApplicationID < MAX_APP; ++m_nApplicationID) {
\r
731 if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Dialog"))) {
\r
735 if (m_nApplicationID == MAX_APP) {
\r
736 m_nApplicationID = nOriginalApplicationID;
\r
742 {CX_ICON, OFF_ICON, ""},
\r
743 {MX_ICON, OFF_ICON, ""},
\r
744 {META_ICON, OFF_ICON, ""}
\r
746 SendIconMessage(msg, 3);
\r
747 CCommands::SetMark(FALSE);
\r
748 CCommands::SetTemporarilyDisableXKeymacs(FALSE);
\r
749 CCommands::Reset();
\r
752 // emulate emacs // cf virtual-key code
\r
753 LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
755 ASSERT(0 <= wParam && wParam <= UCHAR_MAX);
\r
757 int nCommandType = NONE;
\r
758 BYTE nKey = (BYTE)wParam;
\r
760 static BOOL bLocked = FALSE;
\r
761 static const BYTE RECURSIVE_KEY = 0x07;
\r
762 static int (*fCommand)() = NULL;
\r
763 static BYTE nOneShotModifier[MAX_KEY] = {'\0'};
\r
764 static BOOL bCherryOneShotModifier = FALSE;
\r
766 // CUtils::Log(_T("nCode = %#x, nKey = %#x, lParam = %#x"), nCode, nKey, lParam);
\r
768 if (!m_bEnableKeyboardHook)
\r
769 return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);
\r
771 if (nCode < 0 || nCode == HC_NOREMOVE) {
\r
775 if (nKey == RECURSIVE_KEY) {
\r
776 if (lParam & BEING_RELEASED) {
\r
777 goto HOOK_RECURSIVE_KEY;
\r
779 goto RECURSIVE_COMMAND;
\r
784 static BOOL bShift = FALSE;
\r
785 if (IsDepressedShiftKeyOnly(nKey)) {
\r
786 if (lParam & BEING_RELEASED) {
\r
788 CCommands::SetMark(FALSE);
\r
800 if (lParam & EXTENDED_KEY) {
\r
801 nKey = VK_RCONTROL;
\r
803 nKey = VK_LCONTROL;
\r
807 if (lParam & EXTENDED_KEY) {
\r
814 if (lParam & EXTENDED_KEY) {
\r
824 if (lParam & BEING_RELEASED) {
\r
831 if (m_bHookAltRelease) {
\r
832 m_bHookAltRelease = FALSE;
\r
839 for (int i = 0; i < MAX_COMMAND_TYPE; i++) {
\r
840 int (*func)() = Commands[m_Config.nCommandID[m_nApplicationID][i][nKey]].fCommand;
\r
841 if (func && !(bAlt && func == CCommands::MetaAlt))
\r
845 if (nOneShotModifier[nKey]) {
\r
846 ReleaseKey(nOneShotModifier[nKey]);
\r
847 nOneShotModifier[nKey] = 0;
\r
849 if (bCherryOneShotModifier) {
\r
850 bCherryOneShotModifier = FALSE;
\r
857 if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE) {
\r
861 // Do Nothing for Meadow, Mule for Win32, ... if those use default setting.
\r
862 if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))
\r
863 && CUtils::IsDefaultIgnoreApplication()) {
\r
867 switch (IsPassThrough(nKey)) {
\r
868 case GOTO_DO_NOTHING:
\r
879 // set command type
\r
881 nCommandType = NONE;
\r
882 if (IsDown(VK_SHIFT, FALSE)) {
\r
883 nCommandType |= SHIFT;
\r
886 nCommandType |= CONTROL;
\r
889 nCommandType |= META;
\r
891 if (CCommands::bC_x()) {
\r
892 nCommandType |= CONTROLX;
\r
895 // Ignore undefined C-x ?
\r
896 if (nCommandType & CONTROLX) {
\r
897 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL
\r
898 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {
\r
899 if (m_Config.bIgnoreUndefinedC_x[m_nApplicationID]) {
\r
900 CCommands::Reset(GOTO_HOOK);
\r
903 nCommandType &= ~CONTROLX;
\r
907 // Ignore undefined Meta Ctrl+?
\r
908 if (CCommands::bM_() && (nCommandType & CONTROL)) {
\r
909 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL
\r
910 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {
\r
911 if (m_Config.bIgnoreUndefinedMetaCtrl[m_nApplicationID]) {
\r
912 if (Original(CONTROL, nKey)) {
\r
913 Original(CONTROL, nKey, -1);
\r
916 CCommands::Reset(GOTO_HOOK);
\r
919 nCommandType &= ~META;
\r
925 // CUtils::Log(_T("o: %x, %d, %d, %d, %d, %d, %d, %d, %d"), (BYTE)wParam,
\r
926 // IsDown(VK_CONTROL), IsDown(VK_CONTROL, FALSE), IsDepressedModifier(CCommands::C_), IsDepressedModifier(CCommands::C_, FALSE),
\r
927 // IsDown(VK_MENU), IsDown(VK_MENU, FALSE), IsDepressedModifier(CCommands::MetaAlt), IsDepressedModifier(CCommands::MetaAlt, FALSE));
\r
929 BYTE nKey = (BYTE)wParam; // VK_CONTROL is needed instead of VK_RCONTROL and VK_LCONTROL in this block just for Original()
\r
930 int nVirtualCommandType = NONE;
\r
931 if (IsDown(VK_CONTROL) && nKey != VK_CONTROL) {
\r
932 nVirtualCommandType |= CONTROL;
\r
934 if (IsDown(VK_MENU) && nKey != VK_MENU) {
\r
935 nVirtualCommandType |= META;
\r
937 if (Original(nVirtualCommandType, nKey)) {
\r
938 Original(nVirtualCommandType, nKey, -1);
\r
943 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableOrDisableXKeymacs) {
\r
944 SetKeyboardHookFlag(!m_bHook);
\r
947 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableXKeymacs) {
\r
949 SetKeyboardHookFlag(!m_bHook);
\r
953 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DisableXKeymacs) {
\r
955 SetKeyboardHookFlag(!m_bHook);
\r
963 if (CCommands::bM_x()) {
\r
964 static unsigned int index = 0;
\r
965 static TCHAR szPath[MAX_PATH] = {'\0'};
\r
967 if (lParam & BEING_RELEASED) {
\r
969 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BackwardChar) {
\r
974 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BeginningOfLine) {
\r
977 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteBackwardChar) {
\r
980 memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);
\r
984 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteChar) {
\r
985 if (index < _tcslen(szPath)) {
\r
986 memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);
\r
990 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EndOfLine) {
\r
991 index = _tcslen(szPath);
\r
993 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::ForwardChar) {
\r
994 if (index < _tcslen(szPath)) {
\r
998 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::KeyboardQuit) {
\r
999 CCommands::bM_x(FALSE);
\r
1001 memset(szPath, 0, sizeof(szPath));
\r
1003 } else if (nKey == VK_RETURN
\r
1004 || Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::Newline) {
\r
1005 InvokeM_x(szPath);
\r
1007 CCommands::bM_x(FALSE);
\r
1009 memset(szPath, 0, sizeof(szPath));
\r
1011 } else if (index < MAX_PATH - 1) {
\r
1012 const BOOL bIsShiftDown = CXkeymacsDll::IsDown(VK_SHIFT);
\r
1013 for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow
\r
1014 if (nKey != 0 && a2v(nAscii) == nKey && bIsShiftDown == IsShift(nAscii)) {
\r
1015 // CUtils::Log("M-x: %#X (%c), %#X (%c)", nKey, nKey, nAscii, nAscii);
\r
1016 if (index < _tcslen(szPath)) {
\r
1017 memmove(&szPath[index + 1], &szPath[index], __min(_tcslen(szPath) - index, MAX_PATH - (index + 1) - 1));
\r
1019 szPath[index++] = nAscii;
\r
1020 // CUtils::Log("M-x: %c(%#04x)", nAscii, nAscii);
\r
1021 SetM_xTip(szPath);
\r
1028 if (CCommands::bC_u()) {
\r
1029 if ((nCommandType == NONE) && ('0' <= nKey) && (nKey <= '9')) {
\r
1030 CCommands::NumericArgument(nKey - '0');
\r
1033 if ((nCommandType == NONE) && (nKey == 0xBD)) {
\r
1034 CCommands::NumericArgumentMinus();
\r
1039 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrl) {
\r
1040 nOneShotModifier[nKey] = VK_LCONTROL;
\r
1041 DepressKey(nOneShotModifier[nKey]);
\r
1042 bCherryOneShotModifier = TRUE;
\r
1044 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {
\r
1045 nOneShotModifier[nKey] = VK_LCONTROL;
\r
1046 DepressKey(nOneShotModifier[nKey]);
\r
1047 bCherryOneShotModifier = TRUE;
\r
1049 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {
\r
1050 ReleaseKey(nOneShotModifier[nKey]);
\r
1051 bCherryOneShotModifier = FALSE;
\r
1054 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAlt) {
\r
1055 nOneShotModifier[nKey] = VK_LMENU;
\r
1056 DepressKey(nOneShotModifier[nKey]);
\r
1057 bCherryOneShotModifier = TRUE;
\r
1059 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {
\r
1060 nOneShotModifier[nKey] = VK_LMENU;
\r
1061 DepressKey(nOneShotModifier[nKey]);
\r
1062 bCherryOneShotModifier = TRUE;
\r
1064 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {
\r
1065 ReleaseKey(nOneShotModifier[nKey]);
\r
1066 bCherryOneShotModifier = FALSE;
\r
1069 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShift) {
\r
1070 nOneShotModifier[nKey] = VK_SHIFT;
\r
1071 DepressKey(nOneShotModifier[nKey]);
\r
1072 bCherryOneShotModifier = TRUE;
\r
1074 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {
\r
1075 nOneShotModifier[nKey] = VK_SHIFT;
\r
1076 DepressKey(nOneShotModifier[nKey]);
\r
1077 bCherryOneShotModifier = TRUE;
\r
1079 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {
\r
1080 ReleaseKey(nOneShotModifier[nKey]);
\r
1081 bCherryOneShotModifier = FALSE;
\r
1085 for (int i = 0; i < MAX_KEY; ++i) {
\r
1086 if (nOneShotModifier[i] == nKey) {
\r
1090 if (i == MAX_KEY) {
\r
1091 bCherryOneShotModifier = FALSE;
\r
1095 if (0 <= m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]
\r
1096 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < MAX_FUNCTION
\r
1097 && _tcslen(m_Config.szFunctionDefinition[m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]])) {
\r
1098 CallFunction(m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]);
\r
1099 CCommands::Reset(GOTO_HOOK);
\r
1103 if (!Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand) {
\r
1104 if (nKey == VK_CONTROL
\r
1105 || nKey == VK_LCONTROL
\r
1106 || nKey == VK_RCONTROL
\r
1107 || nKey == VK_MENU
\r
1108 || nKey == VK_LMENU
\r
1109 || nKey == VK_RMENU
\r
1110 || nKey == VK_SHIFT
\r
1111 || nKey == VK_LSHIFT
\r
1112 || nKey == VK_RSHIFT) {
\r
1116 if (!(nCommandType & SHIFT)) {
\r
1117 if (CCommands::IsSetMark()) {
\r
1118 if (CCommands::MoveCaret(nKey, nCommandType & CONTROL) != CONTINUE) {
\r
1119 CCommands::ClearNumericArgument();
\r
1122 CCommands::SetMark(FALSE);
\r
1126 if (1 < CCommands::GetNumericArgument()) {
\r
1127 Kdu(nKey, CCommands::GetNumericArgument());
\r
1128 CCommands::ClearNumericArgument();
\r
1135 if (CCommands::IsTemporarilyDisableXKeymacs()
\r
1136 && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand != CCommands::KeyboardQuit) {
\r
1137 CCommands::SetTemporarilyDisableXKeymacs(FALSE);
\r
1141 if (m_Config.bAtIbeamCursorOnly[m_nApplicationID][nCommandType][nKey]) {
\r
1142 CURSORINFO cursorinfo = { sizeof(cursorinfo) };
\r
1143 if (GetCursorInfo(&cursorinfo) && cursorinfo.flags && cursorinfo.hCursor != LoadCursor(NULL, IDC_IBEAM)) {
\r
1148 m_bRightControl = IsDown(VK_RCONTROL);
\r
1149 m_bRightAlt = IsDown(VK_RMENU);
\r
1150 m_bRightShift = IsDown(VK_RSHIFT);
\r
1154 fCommand = Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand;
\r
1155 RECURSIVE_COMMAND:
\r
1156 switch (fCommand()) {
\r
1157 case GOTO_DO_NOTHING:
\r
1163 case GOTO_RECURSIVE:
\r
1168 case GOTO_HOOK0_9:
\r
1177 goto HOOK_RECURSIVE_KEY;
\r
1181 SetModifierIcons();
\r
1183 static BOOL bDefiningMacro = FALSE;
\r
1184 if (m_bDefiningMacro) {
\r
1185 static BOOL bDown[MAX_KEY] = {'\0'};
\r
1187 if (!bDefiningMacro) {
\r
1188 while (m_Macro.GetHeadPosition()) {
\r
1189 void *p = m_Macro.GetAt(m_Macro.GetHeadPosition());
\r
1190 m_Macro.RemoveHead();
\r
1194 memset(bDown, 0, sizeof(bDown));
\r
1197 if ((!(lParam & BEING_RELEASED)) || bDown[wParam]) {
\r
1199 KbdMacro *pKbdMacro = new KbdMacro;
\r
1201 pKbdMacro->nCode = nCode;
\r
1202 pKbdMacro->wParam = wParam;
\r
1203 pKbdMacro->lParam = lParam;
\r
1204 pKbdMacro->bOriginal = TRUE;
\r
1205 m_Macro.AddTail((CObject *)pKbdMacro);
\r
1208 catch (CMemoryException* e) {
\r
1210 // CUtils::Log("KeyboardProc: 'new' threw an exception");
\r
1212 if (!(lParam & BEING_RELEASED)) {
\r
1213 bDown[wParam] = TRUE;
\r
1217 bDefiningMacro = m_bDefiningMacro;
\r
1220 return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);
\r
1223 Kdu(RECURSIVE_KEY, 1, FALSE);
\r
1226 CCommands::SetLastCommand(fCommand);
\r
1229 SetModifierIcons();
\r
1230 HOOK_RECURSIVE_KEY:
\r
1234 void CXkeymacsDll::SetModifierIcons()
\r
1236 #define IconState(x) ((x) ? ON_ICON : OFF_ICON)
\r
1237 ICONMSG msg[6] = {
\r
1238 {MX_ICON, IconState(CCommands::bM_x()), ""},
\r
1239 {CX_ICON, IconState(CCommands::bC_x()), ""},
\r
1240 {META_ICON, IconState(CCommands::bM_()), ""},
\r
1241 {SHIFT_ICON, IconState(IsDown(VK_SHIFT)), ""},
\r
1242 {CTRL_ICON, IconState(IsControl()), ""},
\r
1243 {ALT_ICON, IconState(IsDown(VK_MENU)), ""}
\r
1245 _tcscpy_s(msg[0].szTip, m_M_xTip);
\r
1246 SendIconMessage(msg, 6);
\r
1249 void CXkeymacsDll::SetApplicationName(int nApplicationID, CString szApplicationName)
\r
1251 ZeroMemory(m_Config.szSpecialApp[nApplicationID], CLASS_NAME_LENGTH);
\r
1252 _tcsncpy_s(m_Config.szSpecialApp[nApplicationID], szApplicationName, _TRUNCATE);
\r
1255 void CXkeymacsDll::SetWindowText(int nApplicationID, CString szWindowText)
\r
1257 ZeroMemory(m_Config.szWindowText[nApplicationID], WINDOW_TEXT_LENGTH);
\r
1258 _tcsncpy_s(m_Config.szWindowText[nApplicationID], szWindowText, _TRUNCATE);
\r
1261 void CXkeymacsDll::SetCommandID(int nApplicationID, int nCommandType, int nKey, int nCommandID)
\r
1263 m_Config.nCommandID[nApplicationID][nCommandType][nKey] = nCommandID;
\r
1266 void CXkeymacsDll::SetAtIbeamCursorOnly(int nApplicationID, int nCommandType, int nKey, BOOL bAtIbeamCursorOnly)
\r
1268 m_Config.bAtIbeamCursorOnly[nApplicationID][nCommandType][nKey] = bAtIbeamCursorOnly;
\r
1271 void CXkeymacsDll::SetKillRingMax(int nApplicationID, int nKillRingMax)
\r
1273 m_Config.nKillRingMax[nApplicationID] = nKillRingMax;
\r
1276 void CXkeymacsDll::SetUseDialogSetting(int nApplicationID, BOOL bUseDialogSetting)
\r
1278 m_Config.bUseDialogSetting[nApplicationID] = bUseDialogSetting;
\r
1281 // Clear data of nApplicationID
\r
1282 void CXkeymacsDll::Clear(int nApplicationID)
\r
1284 if (0 <= nApplicationID && nApplicationID < MAX_APP) {
\r
1285 ZeroMemory(m_Config.szSpecialApp[nApplicationID], sizeof(m_Config.szSpecialApp[nApplicationID]));
\r
1286 ZeroMemory(m_Config.nCommandID[nApplicationID], sizeof(m_Config.nCommandID[nApplicationID]));
\r
1287 ZeroMemory(m_Config.bAtIbeamCursorOnly[nApplicationID], sizeof(m_Config.bAtIbeamCursorOnly[nApplicationID]));
\r
1288 m_Config.nKillRingMax[nApplicationID] = 0;
\r
1289 m_Config.bUseDialogSetting[nApplicationID] = FALSE;
\r
1290 m_Config.nSettingStyle[nApplicationID] = 0;
\r
1296 BOOL CXkeymacsDll::IsValidKey(BYTE bVk)
\r
1298 if (bVk == 0xf0) { // 0xf0: Eisu key. GetAsyncKeyState returns the wrong state of Eisu key.
\r
1314 BOOL CXkeymacsDll::IsDepressedModifier(int (__cdecl *Modifier)(void), BOOL bPhysicalKey)
\r
1318 if (IsValidKey(bVk)
\r
1319 && IsDown(bVk, bPhysicalKey)
\r
1320 && Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == Modifier) {
\r
1327 BOOL CXkeymacsDll::IsDepressedShiftKeyOnly(BYTE nKey)
\r
1329 if (nKey != VK_SHIFT
\r
1330 && nKey != VK_LSHIFT
\r
1331 && nKey != VK_RSHIFT) {
\r
1337 if (bVk == VK_SHIFT
\r
1338 || bVk == VK_LSHIFT
\r
1339 || bVk == VK_RSHIFT) {
\r
1343 if (IsDown(bVk)) {
\r
1350 BOOL CXkeymacsDll::IsControl()
\r
1352 return CCommands::bC_() || IsDepressedModifier(CCommands::C_, FALSE);
\r
1355 BOOL CXkeymacsDll::IsMeta()
\r
1357 return CCommands::bM_() || IsDepressedModifier(CCommands::MetaAlt, FALSE);
\r
1360 void CXkeymacsDll::AddKillRing(BOOL bNewData)
\r
1362 if (m_Config.nKillRingMax[m_nApplicationID] == 0) {
\r
1366 CClipboardSnap *pSnap = new CClipboardSnap;
\r
1367 if( !pSnap ) return;
\r
1369 BOOL bCapture = pSnap->Capture();
\r
1370 bCapture = pSnap->Capture(); // for "office drawing shape format". Can CClipboardSnap care this problem?
\r
1374 m_oKillRing.AddHead(pSnap);
\r
1376 if (m_oKillRing.IsEmpty()) {
\r
1377 m_oKillRing.AddHead(pSnap);
\r
1379 for (CClipboardSnap *pParent = m_oKillRing.GetHead(); pParent->GetNext(); pParent = pParent->GetNext()) {
\r
1382 pParent->SetNext(pSnap);
\r
1392 if (m_Config.nKillRingMax[m_nApplicationID] < m_oKillRing.GetCount()) {
\r
1393 CClipboardSnap *pSnap = m_oKillRing.GetTail();
\r
1396 m_oKillRing.RemoveTail();
\r
1400 // Return TRUE if there is another data
\r
1401 // Return FALSE if there is no more data
\r
1402 CClipboardSnap* CXkeymacsDll::GetKillRing(CClipboardSnap* pSnap, BOOL bForce)
\r
1404 if (m_Config.nKillRingMax[m_nApplicationID] == 0) {
\r
1408 if (m_oKillRing.IsEmpty()) {
\r
1412 m_nKillRing %= m_oKillRing.GetCount();
\r
1415 CClipboardSnap oCurrentSnap;
\r
1416 oCurrentSnap.Capture();
\r
1418 CClipboardSnap *pKillRing = m_oKillRing.GetAt(m_oKillRing.FindIndex(m_nKillRing));
\r
1422 for (; pKillRing->GetNext(); pKillRing = pKillRing->GetNext()) {
\r
1425 if (*pKillRing != oCurrentSnap) {
\r
1431 pSnap = m_oKillRing.GetAt(m_oKillRing.FindIndex(m_nKillRing));
\r
1435 return pSnap->GetNext();
\r
1438 void CXkeymacsDll::Original(int nCommandType, BYTE bVk, int nOriginal)
\r
1440 nCommandType &= ~SHIFT;
\r
1444 bVk = VK_LCONTROL;
\r
1456 m_nOriginal[nCommandType][bVk] += nOriginal;
\r
1459 int CXkeymacsDll::Original(int nCommandType, BYTE bVk)
\r
1461 nCommandType &= ~SHIFT;
\r
1465 bVk = VK_LCONTROL;
\r
1477 return m_nOriginal[nCommandType][bVk];
\r
1480 void CXkeymacsDll::IncreaseKillRingIndex(int nKillRing)
\r
1482 m_nKillRing += nKillRing;
\r
1486 int CXkeymacsDll::GetMickey(int nDifferential, int nThreshold1, int nThreshold2, int nAcceleration, int nSpeed)
\r
1488 nDifferential = nDifferential * 10 / nSpeed;
\r
1490 switch (nAcceleration) {
\r
1492 if (nThreshold2 < fabs((double)(nDifferential / 4))) {
\r
1493 nDifferential /= 4;
\r
1496 // Do NOT write break; here.
\r
1498 if (nThreshold1 < fabs((double)(nDifferential / 2))) {
\r
1499 nDifferential /= 2;
\r
1509 return nDifferential;
\r
1512 void CXkeymacsDll::SetSettingStyle(int nApplicationID, int nSettingStyle)
\r
1514 m_Config.nSettingStyle[nApplicationID] = nSettingStyle;
\r
1517 void CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(int nApplicationID, BOOL bIgnoreUndefinedMetaCtrl)
\r
1519 m_Config.bIgnoreUndefinedMetaCtrl[nApplicationID] = bIgnoreUndefinedMetaCtrl;
\r
1522 void CXkeymacsDll::SetIgnoreUndefinedC_x(int nApplicationID, BOOL bIgnoreUndefinedC_x)
\r
1524 m_Config.bIgnoreUndefinedC_x[nApplicationID] = bIgnoreUndefinedC_x;
\r
1527 void CXkeymacsDll::SetEnableCUA(int nApplicationID, BOOL bEnableCUA)
\r
1529 m_Config.bEnableCUA[nApplicationID] = bEnableCUA;
\r
1532 BOOL CXkeymacsDll::GetEnableCUA()
\r
1534 return m_Config.bEnableCUA[m_nApplicationID];
\r
1537 void CXkeymacsDll::DefiningMacro(BOOL bDefiningMacro)
\r
1539 m_bDefiningMacro = bDefiningMacro;
\r
1541 if (bDefiningMacro) { // start-kbd-macro
\r
1542 if (CCommands::bC_u()) {
\r
1543 ReleaseKey(VK_SHIFT);
\r
1546 } else { // end-kbd-macro
\r
1547 while (!m_Macro.IsEmpty()) {
\r
1548 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetTail();
\r
1549 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1552 m_Macro.RemoveTail();
\r
1558 // CUtils::Log(_T("Macro MemMap: start"));
\r
1559 if (!m_Macro.IsEmpty()) {
\r
1560 static HANDLE hMacro = NULL;
\r
1562 hMacro = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 0x3000, _T("macro"));
\r
1565 // CUtils::Log(_T("Macro MemMap: 1"));
\r
1566 PVOID pView = MapViewOfFile(hMacro, FILE_MAP_ALL_ACCESS, 0, 0, 0);
\r
1567 // CUtils::Log(_T("Macro MemMap: 2"));
\r
1569 // CUtils::Log(_T("Macro MemMap: 2.5"));
\r
1570 for (int i = 0; i < m_Macro.GetCount(); ++i) {
\r
1571 // CUtils::Log(_T("Macro MemMap: 3-1 %d"), i);
\r
1572 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetAt(m_Macro.FindIndex(i));
\r
1573 // CUtils::Log(_T("Macro MemMap: 3-2 %d"), i);
\r
1574 memcpy((LPTSTR) pView + i * sizeof(KbdMacro), pKbdMacro, sizeof(KbdMacro));
\r
1575 // CUtils::Log(_T("Macro MemMap: 3-3 %d"), i);
\r
1577 // CUtils::Log(_T("Macro MemMap: 4"));
\r
1578 UnmapViewOfFile(pView);
\r
1579 // CUtils::Log(_T("Macro MemMap: 5"));
\r
1581 // CUtils::Log(_T("Macro MemMpa: error: %d"), GetLastError());
\r
1584 // CUtils::Log(_T("Macro MemMap: 6"));
\r
1591 BOOL CXkeymacsDll::DefiningMacro()
\r
1593 return m_bDefiningMacro;
\r
1597 void CXkeymacsDll::CallMacro()
\r
1599 BOOL bIsCtrlDown = IsDown(VK_CONTROL);
\r
1600 if (bIsCtrlDown) {
\r
1601 ReleaseKey(VK_CONTROL);
\r
1603 BOOL bIsAltDown = IsDown(VK_MENU);
\r
1605 ReleaseKey(VK_MENU);
\r
1607 BOOL bIsShiftDown = IsDown(VK_SHIFT);
\r
1608 if (bIsShiftDown) {
\r
1609 ReleaseKey(VK_SHIFT);
\r
1612 for (POSITION pos = m_Macro.GetHeadPosition(); pos; ) {
\r
1613 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetNext(pos);
\r
1614 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1615 ReleaseKey((BYTE)pKbdMacro->wParam);
\r
1617 DepressKey((BYTE)pKbdMacro->wParam, pKbdMacro->bOriginal);
\r
1621 if (bIsCtrlDown) {
\r
1622 DepressKey(VK_CONTROL);
\r
1625 DepressKey(VK_MENU);
\r
1627 if (bIsShiftDown) {
\r
1628 DepressKey(VK_SHIFT);
\r
1633 void CXkeymacsDll::CallMacro() // for debug
\r
1636 for (POSITION pos = m_Macro.GetHeadPosition(); pos; ) {
\r
1637 KbdMacro_t *pKbdMacro = (KbdMacro_t *)m_Macro.GetNext(pos);
\r
1638 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1640 t.Format(_T("0x%xu "), pKbdMacro->wParam);
\r
1644 t.Format(_T("0x%xd "), pKbdMacro->wParam);
\r
1648 // CUtils::Log(sz);
\r
1652 void CXkeymacsDll::Set106Keyboard(BOOL b106Keyboard)
\r
1654 m_Config.b106Keyboard = b106Keyboard;
\r
1657 BOOL CXkeymacsDll::Is106Keyboard()
\r
1659 return m_Config.b106Keyboard;
\r
1662 int CXkeymacsDll::IsPassThrough(BYTE nKey)
\r
1667 && (Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == CCommands::PassThrough)) {
\r
1668 if (bVk == nKey) {
\r
1672 return GOTO_DO_NOTHING;
\r
1678 void CXkeymacsDll::SetKeyboardHookFlag()
\r
1680 SetKeyboardHookFlag(m_bHook);
\r
1683 void CXkeymacsDll::SetFunctionKey(int nFunctionID, int nApplicationID, int nCommandType, int nKey)
\r
1685 if (nApplicationID < 0 || MAX_APP <= nApplicationID
\r
1686 || nCommandType < 0 || MAX_COMMAND_TYPE <= nCommandType
\r
1687 || nKey < 0 || MAX_KEY <= nKey) {
\r
1691 m_Config.nFunctionID[nApplicationID][nCommandType][nKey] = nFunctionID;
\r
1694 void CXkeymacsDll::ClearFunctionDefinition()
\r
1696 memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID));
\r
1697 memset(m_Config.szFunctionDefinition, 0, sizeof(m_Config.szFunctionDefinition));
\r
1700 void CXkeymacsDll::SetFunctionDefinition(int nFunctionID, CString szDefinition)
\r
1702 if (nFunctionID < 0 || MAX_FUNCTION <= nFunctionID) {
\r
1706 memset(m_Config.szFunctionDefinition[nFunctionID], 0, sizeof(m_Config.szFunctionDefinition[nFunctionID]));
\r
1707 _stprintf_s(m_Config.szFunctionDefinition[nFunctionID], _T("%s"), szDefinition);
\r
1713 // call an original command which is defined in dot.xkeymacs
\r
1714 void CXkeymacsDll::CallFunction(int nFunctionID)
\r
1716 CArray<KeyBind, KeyBind> keybinds;
\r
1718 if (nFunctionID < 0 || MAX_FUNCTION <= nFunctionID || !_tcslen(m_Config.szFunctionDefinition[nFunctionID])) {
\r
1722 BOOL bIsCtrlDown = CXkeymacsDll::IsDown(VK_CONTROL);
\r
1723 BOOL bIsAltDown = CXkeymacsDll::IsDown(VK_MENU);
\r
1724 BOOL bIsShiftDown = CXkeymacsDll::IsDown(VK_SHIFT);
\r
1726 if (m_Config.szFunctionDefinition[nFunctionID][0] == _T('"') && m_Config.szFunctionDefinition[nFunctionID][_tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1] == _T('"')) {
\r
1727 for (unsigned int i = 1; i < _tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1; ++i) { // skip '"'
\r
1728 keybinds.Add(ParseKey(nFunctionID, i));
\r
1730 } else if (m_Config.szFunctionDefinition[nFunctionID][0] == _T('[') && m_Config.szFunctionDefinition[nFunctionID][_tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1] == _T(']')) {
\r
1731 for (unsigned int i = 1; i < _tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1; ++i) { // skip '[' and ']'
\r
1732 if (m_Config.szFunctionDefinition[nFunctionID][i] == _T('?')) { // [?f ?o ?o]
\r
1734 keybinds.Add(ParseKey(nFunctionID, i));
\r
1735 } else { // [ControlCharacter]
\r
1736 for (int nKeyID = 0; nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0]); ++nKeyID) {
\r
1737 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, ControlCharacters[nKeyID].name, _tcslen(ControlCharacters[nKeyID].name))) {
\r
1738 KeyBind keybind = {NONE, ControlCharacters[nKeyID].bVk};
\r
1739 keybinds.Add(keybind);
\r
1740 i += _tcslen(ControlCharacters[nKeyID].name);
\r
1750 BOOL bM_x = FALSE;
\r
1751 TCHAR szPath[MAX_PATH] = {'\0'};
\r
1752 unsigned int index = 0;
\r
1753 BOOL bInitialized = FALSE;
\r
1755 for (int i = 0; i < keybinds.GetSize(); ++i) {
\r
1756 const int nCommandType = keybinds.GetAt(i).nCommandType;
\r
1757 const BYTE bVk = keybinds.GetAt(i).bVk;
\r
1759 if (nCommandType < MAX_COMMAND_TYPE && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand) {
\r
1760 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand == CCommands::ExecuteExtendedCommand) {
\r
1762 } else if (!bInitialized) {
\r
1763 if (bIsCtrlDown) {
\r
1764 CUtils::UpdateKeyboardState(VK_CONTROL, 0);
\r
1765 ReleaseKey(VK_CONTROL);
\r
1769 ReleaseKey(VK_MENU);
\r
1772 if (bIsShiftDown) {
\r
1773 ReleaseKey(VK_SHIFT);
\r
1776 bInitialized = TRUE;
\r
1778 // CUtils::Log("CallFunction: Command Name: %s", Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].szCommandName);
\r
1779 while (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand() == GOTO_RECURSIVE) {
\r
1782 } else if (bM_x) {
\r
1783 if (bVk == VK_RETURN) {
\r
1784 InvokeM_x(szPath);
\r
1786 for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow
\r
1787 if (bVk != 0 && a2v(nAscii) == bVk && ((nCommandType & SHIFT) != 0) == IsShift(nAscii)) {
\r
1788 // CUtils::Log("M-x: %#X (%c), %#X (%c)", bVk, bVk, nAscii, nAscii);
\r
1789 szPath[index++] = nAscii;
\r
1795 if (!bInitialized) {
\r
1796 if (bIsCtrlDown) {
\r
1797 CUtils::UpdateKeyboardState(VK_CONTROL, 0);
\r
1798 ReleaseKey(VK_CONTROL);
\r
1802 ReleaseKey(VK_MENU);
\r
1805 if (bIsShiftDown) {
\r
1806 ReleaseKey(VK_SHIFT);
\r
1809 bInitialized = TRUE;
\r
1811 if (nCommandType & WIN_WIN) {
\r
1812 DepressKey(VK_LWIN);
\r
1814 if (nCommandType & WIN_CTRL) {
\r
1815 DepressKey(VK_CONTROL);
\r
1817 if (nCommandType & WIN_ALT) {
\r
1818 DepressKey(VK_MENU);
\r
1820 if (nCommandType & SHIFT) {
\r
1821 DepressKey(VK_SHIFT);
\r
1826 if (nCommandType & SHIFT && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & SHIFT))) {
\r
1827 ReleaseKey(VK_SHIFT);
\r
1829 if (nCommandType & WIN_ALT && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_ALT))) {
\r
1830 ReleaseKey(VK_MENU);
\r
1832 if (nCommandType & WIN_CTRL && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_CTRL))) {
\r
1833 ReleaseKey(VK_CONTROL);
\r
1835 if (nCommandType & WIN_WIN && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_WIN))) {
\r
1836 ReleaseKey(VK_LWIN);
\r
1841 keybinds.RemoveAll();
\r
1843 if (bInitialized) {
\r
1844 // If these lines are invoked at M-x, a window transition does not work well.
\r
1846 if (bIsShiftDown) {
\r
1847 DepressKey(VK_SHIFT);
\r
1851 DepressKey(VK_MENU);
\r
1854 if (bIsCtrlDown) {
\r
1855 DepressKey(VK_CONTROL);
\r
1856 CUtils::UpdateKeyboardState(VK_CONTROL, 1);
\r
1862 KeyBind CXkeymacsDll::ParseKey(const int nFunctionID, unsigned int &i)
\r
1864 KeyBind keybind = {NONE};
\r
1866 if (m_Config.szFunctionDefinition[nFunctionID][i] == _T('\\')) {
\r
1868 BOOL bFound = FALSE;
\r
1871 for (int ModifierID = 0; ModifierID < sizeof(Modifiers) / sizeof(Modifiers[0]); ++ModifierID) {
\r
1872 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, Modifiers[ModifierID].name, _tcslen(Modifiers[ModifierID].name))
\r
1873 && _tcslen(Modifiers[ModifierID].name) < _tcslen(m_Config.szFunctionDefinition[nFunctionID] + i)) {
\r
1874 keybind.nCommandType |= Modifiers[ModifierID].id;
\r
1875 i+= _tcslen(Modifiers[ModifierID].name);
\r
1881 if (IsShift(m_Config.szFunctionDefinition[nFunctionID][i]) && !(keybind.nCommandType & (WIN_CTRL | WIN_ALT | WIN_WIN))) {
\r
1882 keybind.nCommandType |= SHIFT;
\r
1885 for (int nKeyID = 0; nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0]); ++nKeyID) {
\r
1886 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, ControlCharacters[nKeyID].name, _tcslen(ControlCharacters[nKeyID].name))) {
\r
1887 i += _tcslen(ControlCharacters[nKeyID].name);
\r
1891 if (nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0])) {
\r
1892 keybind.bVk = ControlCharacters[nKeyID].bVk;
\r
1894 keybind.bVk = a2v(m_Config.szFunctionDefinition[nFunctionID][i]);
\r
1900 BOOL CXkeymacsDll::IsShift(TCHAR nAscii)
\r
1913 return m_Config.b106Keyboard;
\r
1923 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
1926 return !m_Config.b106Keyboard;
\r
1932 return m_Config.b106Keyboard;
\r
1937 return !m_Config.b106Keyboard;
\r
1938 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
1939 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
1940 case _T('U'): case _T('V'): case _T('W'): case _T('X'): case _T('Y'): case _T('Z'):
\r
1947 return !m_Config.b106Keyboard;
\r
1951 return m_Config.b106Keyboard;
\r
1952 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
1953 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
1954 case _T('u'): case _T('v'): case _T('w'): case _T('x'): case _T('y'): case _T('z'):
\r
1966 BYTE CXkeymacsDll::a2v(TCHAR nAscii)
\r
1974 return m_Config.b106Keyboard ? '2' : (BYTE) 0xde; // VK_OEM_7
\r
1982 return m_Config.b106Keyboard ? '6' : '7';
\r
1984 return m_Config.b106Keyboard ? '7' : (BYTE) 0xde; // VK_OEM_7
\r
1986 return m_Config.b106Keyboard ? '8' : '9';
\r
1988 return m_Config.b106Keyboard ? '9' : '0';
\r
1990 return m_Config.b106Keyboard ? (BYTE) 0xba : '8'; // VK_OEM_1
\r
1992 return 0xbb; // VK_OEM_PLUS
\r
1994 return 0xbc; // VK_OEM_COMMA
\r
1996 return 0xbd; // VK_OEM_MINUS
\r
1998 return 0xbe; // VK_OEM_PERIOD
\r
2000 return 0xbf; // VK_OEM_2
\r
2001 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
2004 return 0xba; // VK_OEM_1
\r
2006 return m_Config.b106Keyboard ? (BYTE) 0xbb : (BYTE) 0xba; // VK_OEM_PLUS VK_OEM_1
\r
2008 return 0xbc; // VK_OEM_COMMA
\r
2010 return m_Config.b106Keyboard ? (BYTE) 0xbd : (BYTE) 0xbb; // VK_OEM_MINUS VK_OEM_PLUS
\r
2012 return 0xbe; // VK_OEM_PERIOD
\r
2014 return 0xbf; // VK_OEM_2
\r
2016 return m_Config.b106Keyboard ? (BYTE) 0xc0 : '2';
\r
2017 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
2018 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
2019 case _T('U'): case _T('V'): case _T('W'): case _T('X'): case _T('Y'): case _T('Z'):
\r
2022 return 0xdb; // VK_OEM_4
\r
2024 return 0xdc; // VK_OEM_5
\r
2026 return 0xdd; // VK_OEM_6
\r
2028 return m_Config.b106Keyboard ? (BYTE) 0xde : '6'; // VK_OEM_7
\r
2030 return m_Config.b106Keyboard ? (BYTE) 0xe2 : (BYTE) 0xbd; // VK_OEM_102 VK_OEM_MINUS
\r
2032 return 0xc0; // VK_OEM_3
\r
2033 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
2034 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
2035 case _T('u'): case _T('v'): case _T('w'): case _T('x'): case _T('y'): case _T('z'):
\r
2036 return (BYTE) (nAscii - (_T('a') - _T('A')));
\r
2038 return 0xdb; // VK_OEM_4
\r
2040 return 0xdc; // VK_OEM_5
\r
2042 return 0xdd; // VK_OEM_6
\r
2044 return m_Config.b106Keyboard ? (BYTE) 0xde : (BYTE) 0xc0; // VK_OEM_7 VK_OEM_3
\r
2050 BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText)
\r
2052 BOOL bIsMatchWindowText = TRUE;
\r
2054 TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
2055 GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText));
\r
2057 switch (CUtils::GetWindowTextType(szWindowText)) {
\r
2058 case IDS_WINDOW_TEXT_MATCH: // *foo*
\r
2059 szWindowText.Delete(0); // Delete first '*'
\r
2060 szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'
\r
2061 bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText);
\r
2063 case IDS_WINDOW_TEXT_MATCH_FORWARD: // foo*
\r
2064 szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'
\r
2065 bIsMatchWindowText = 0 == CString(szCurrentWindowText).Find(szWindowText);
\r
2067 case IDS_WINDOW_TEXT_MATCH_BACKWARD: // *foo
\r
2068 szWindowText.Delete(0); // Delete first '*'
\r
2069 bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText, CString(szCurrentWindowText).GetLength() - szWindowText.GetLength());
\r
2071 case IDS_WINDOW_TEXT_MATCH_FULL: // foo
\r
2072 bIsMatchWindowText = szWindowText == CString(szCurrentWindowText);
\r
2074 case IDS_WINDOW_TEXT_IGNORE: // *
\r
2075 bIsMatchWindowText = TRUE;
\r
2082 // CUtils::Log(_T("IsMatchWindowText: %d, _%s_, _%s_"), bIsMatchWindowText, szCurrentWindowText, szWindowText);
\r
2083 return bIsMatchWindowText;
\r
2086 void CXkeymacsDll::SetAccelerate(int nAccelerate)
\r
2088 m_nAccelerate = nAccelerate;
\r
2091 int CXkeymacsDll::GetAccelerate()
\r
2093 return m_nAccelerate;
\r
2096 void CXkeymacsDll::SetKeyboardSpeed(int nKeyboardSpeed)
\r
2098 m_nKeyboardSpeed = nKeyboardSpeed;
\r
2101 unsigned int CXkeymacsDll::GetMaxKeyInterval()
\r
2103 // m_nKeyboardSpeed == 0: slowest repeat rate; approximately 2 characters per second
\r
2104 // m_nKeyboardSpeed == 31: fastest repeat rate; approximately 30 characters per second
\r
2105 // 47 ms is max on my machine w/ KeyboardSpeed 31.
\r
2106 // 1000 / 2 + 50 = 550
\r
2107 // 1000 / 30 + 50 = 83
\r
2108 return (unsigned int) (1000.0 / (2.0 + m_nKeyboardSpeed % 32 * 28.0 / 31.0) + 50.0);
\r
2111 void CXkeymacsDll::SetCursorData(HCURSOR hEnable, HCURSOR hDisableTMP, HCURSOR hDisableWOCQ, HICON hDisable, BOOL bEnable)
\r
2113 m_hCursor[STATUS_ENABLE] = hEnable;
\r
2114 m_hCursor[STATUS_DISABLE_TMP] = hDisableTMP;
\r
2115 m_hCursor[STATUS_DISABLE_WOCQ] = hDisableWOCQ;
\r
2116 m_hCursor[STATUS_DISABLE] = hDisable;
\r
2117 m_bCursor = bEnable;
\r
2120 void CXkeymacsDll::DoSetCursor()
\r
2122 if (m_bCursor && m_hCurrentCursor) {
\r
2123 ::SetCursor(m_hCurrentCursor);
\r
2127 void CXkeymacsDll::Set326Compatible(int nApplicationID, BOOL b326Compatible)
\r
2129 m_Config.b326Compatible[nApplicationID] = b326Compatible;
\r
2132 BOOL CXkeymacsDll::Get326Compatible()
\r
2134 return m_Config.b326Compatible[m_nApplicationID];
\r
2137 void CXkeymacsDll::InvokeM_x(const TCHAR *const szPath)
\r
2139 // CUtils::Log("M-x: szPath=_%s_", szPath);
\r
2140 int (*fCommand)() = NULL;
\r
2142 for (int i = 0; i < MAX_COMMAND; ++i) {
\r
2143 if (_tcsicmp(szPath, Commands[i].szCommandName) == 0) {
\r
2144 fCommand = Commands[i].fCommand;
\r
2150 // CUtils::Log("M-x: Command: _%s_", Commands[i].szCommandName);
\r
2153 // CUtils::Log("M-x: Path: _%s_", szPath);
\r
2154 ShellExecute(NULL, NULL, szPath, NULL, NULL, SW_SHOWNORMAL);
\r
2158 void CXkeymacsDll::SetM_xTip(const TCHAR *const szPath)
\r
2160 _tcscpy_s(m_M_xTip, "M-x LED");
\r
2161 if (szPath && _tcslen(szPath) < 128 - 5)
\r
2162 _stprintf_s(m_M_xTip, "M-x %s", szPath);
\r
2165 BOOL CXkeymacsDll::SendIconMessage(ICONMSG *pMsg, DWORD num)
\r
2168 return CallNamedPipe(ICON_PIPE, pMsg, sizeof(ICONMSG) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
\r