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 DWORD CXkeymacsDll::m_nHookAltRelease = 0;
\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 BOOL bHookApp = CUtils::IsVisualCpp() || CUtils::IsFirefox() || CUtils::IsVisualStudio() || CUtils::IsInternetExplorer();
\r
629 if (after & META && !(before & META)) {
\r
631 m_nHookAltRelease |= HOOK_ALT_LATER;
\r
632 DepressKey(VK_MENU);
\r
633 } else if (!(after & META) && before & META) {
\r
635 m_nHookAltRelease++;
\r
636 ReleaseKey(VK_MENU);
\r
640 BOOL CXkeymacsDll::UpdateKeyboardState(BYTE bVk, BYTE bState)
\r
642 BYTE ks[256] = {'\0'};
\r
643 if (!GetKeyboardState(ks))
\r
646 return SetKeyboardState(ks);
\r
649 BOOL CXkeymacsDll::IsDown(BYTE bVk, BOOL bPhysicalKey)
\r
651 return bPhysicalKey ? GetAsyncKeyState(bVk) < 0 : GetKeyState(bVk) < 0;
\r
655 void CXkeymacsDll::DoKeybd_event(BYTE bVk, DWORD dwFlags)
\r
657 // Set KEYEVENTF_EXTENDEDKEY if needed
\r
660 if (m_bRightControl)
\r
661 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
666 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
670 if (m_bRightShift) {
\r
671 if (CUtils::IsXPorLater())
\r
674 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
678 if (IsDown(VK_CONTROL, FALSE)) // Break
\r
679 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
693 dwFlags |= KEYEVENTF_EXTENDEDKEY;
\r
696 // CUtils::Log(_T("b: %x, %x, %x, %#hx, %#hx"), bVk, dwFlags, GetMessageExtraInfo(), GetKeyState(bVk), GetAsyncKeyState(bVk));
\r
697 keybd_event(bVk, 0, dwFlags, GetMessageExtraInfo());
\r
698 // CUtils::Log(_T("a: %x, %x, %x, %#hx, %#hx"), bVk, dwFlags, GetMessageExtraInfo(), GetKeyState(bVk), GetAsyncKeyState(bVk));
\r
701 // the key is being depressed
\r
702 void CXkeymacsDll::DepressKey(BYTE bVk, BOOL bOriginal) // bVk is virtual-key code, MSDN said
\r
705 // CUtils::Log(_T("i: %x, %d, %d, %d, %d, %d, %d, %d, %d"), bVk,
\r
706 // IsDown(VK_CONTROL), IsDown(VK_CONTROL, FALSE), IsDepressedModifier(CCommands::C_), IsDepressedModifier(CCommands::C_, FALSE),
\r
707 // IsDown(VK_MENU), IsDown(VK_MENU, FALSE), IsDepressedModifier(CCommands::MetaAlt), IsDepressedModifier(CCommands::MetaAlt, FALSE));
\r
708 Original(GetModifierState(), bVk, 1);
\r
710 DoKeybd_event(bVk, 0);
\r
713 // the key is being released
\r
714 void CXkeymacsDll::ReleaseKey(BYTE bVk) // bVk is virtual-key code, MSDN said
\r
716 DoKeybd_event(bVk, KEYEVENTF_KEYUP);
\r
719 // bVk down, bVk up
\r
720 void CXkeymacsDll::Kdu(BYTE bVk, DWORD n, BOOL bOriginal)
\r
723 DepressKey(bVk, bOriginal);
\r
728 void CXkeymacsDll::InitKeyboardProc(BOOL bImeComposition)
\r
730 if (CUtils::IsFindDialog()) {
\r
731 static BOOL bImeCompositionOld = FALSE;
\r
732 if (!bImeComposition
\r
733 && bImeCompositionOld) {
\r
734 DepressKey(VK_END);
\r
735 ReleaseKey(VK_END);
\r
737 bImeCompositionOld = bImeComposition;
\r
740 CUtils::SetApplicationName(bImeComposition);
\r
742 if (_tcsnicmp(m_Config.szSpecialApp[m_nApplicationID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nApplicationID])) { // PROCESSENTRY32 has only 0xF bytes of Name
\r
743 m_nApplicationID = -1;
\r
745 for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {
\r
746 if (!_tcsnicmp(m_Config.szSpecialApp[nApplicationID], CUtils::GetApplicationName(), 0xF) && IsMatchWindowText(m_Config.szWindowText[nApplicationID])) {
\r
748 if (m_nApplicationID < 0
\r
749 || CUtils::GetWindowTextType(m_Config.szWindowText[m_nApplicationID]) < CUtils::GetWindowTextType(m_Config.szWindowText[nApplicationID])
\r
750 || CUtils::GetWindowTextType(m_Config.szWindowText[m_nApplicationID]) == CUtils::GetWindowTextType(m_Config.szWindowText[nApplicationID])
\r
751 && _tcscmp(m_Config.szWindowText[m_nApplicationID], m_Config.szWindowText[nApplicationID]) <= 0) {
\r
752 m_nApplicationID = nApplicationID;
\r
757 if (m_nApplicationID < 0) {
\r
758 for (int nApplicationID = 0; nApplicationID < MAX_APP; ++nApplicationID) {
\r
759 if (!_tcsicmp(m_Config.szSpecialApp[nApplicationID], _T("Default"))) {
\r
760 m_nApplicationID = nApplicationID;
\r
765 if (m_nApplicationID < 0) {
\r
766 m_nApplicationID = 0;
\r
771 if (m_Config.nSettingStyle[m_nApplicationID] != SETTING_DISABLE
\r
772 && (_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default")) || !CUtils::IsDefaultIgnoreApplication())
\r
773 && !bImeComposition
\r
774 && CUtils::IsDialog()) {
\r
775 // Use Dialog Setting
\r
776 if (m_Config.bUseDialogSetting[m_nApplicationID]) {
\r
777 int nOriginalApplicationID = m_nApplicationID;
\r
778 for (m_nApplicationID = 0; m_nApplicationID < MAX_APP; ++m_nApplicationID) {
\r
779 if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Dialog"))) {
\r
783 if (m_nApplicationID == MAX_APP) {
\r
784 m_nApplicationID = nOriginalApplicationID;
\r
790 {CX_ICON, OFF_ICON, ""},
\r
791 {MX_ICON, OFF_ICON, ""},
\r
792 {META_ICON, OFF_ICON, ""}
\r
794 SendIconMessage(msg, 3);
\r
795 CCommands::SetMark(FALSE);
\r
796 CCommands::SetTemporarilyDisableXKeymacs(FALSE);
\r
797 CCommands::Reset();
\r
800 // emulate emacs // cf virtual-key code
\r
801 LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
\r
803 ASSERT(0 <= wParam && wParam <= UCHAR_MAX);
\r
805 int nCommandType = NONE;
\r
806 BYTE nKey = (BYTE)wParam;
\r
808 static BOOL bLocked = FALSE;
\r
809 static const BYTE RECURSIVE_KEY = 0x07;
\r
810 static int (*fCommand)() = NULL;
\r
811 static BYTE nOneShotModifier[MAX_KEY] = {'\0'};
\r
812 static BOOL bCherryOneShotModifier = FALSE;
\r
814 // CUtils::Log(_T("nCode = %#x, nKey = %#x, lParam = %p, %d, %d"), nCode, nKey, lParam, IsDll64, Is64ProcessHwnd(GetForegroundWindow()));
\r
816 if (Is64ProcessHwnd(GetForegroundWindow()) != IsDll64 || CUtils::IsXkeymacs())
\r
817 return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);
\r
819 if (nCode < 0 || nCode == HC_NOREMOVE) {
\r
823 if (nKey == RECURSIVE_KEY) {
\r
824 if (lParam & BEING_RELEASED) {
\r
825 goto HOOK_RECURSIVE_KEY;
\r
827 goto RECURSIVE_COMMAND;
\r
832 static BOOL bShift = FALSE;
\r
833 if (IsDepressedShiftKeyOnly(nKey)) {
\r
834 if (lParam & BEING_RELEASED) {
\r
836 CCommands::SetMark(FALSE);
\r
848 if (lParam & EXTENDED_KEY) {
\r
849 nKey = VK_RCONTROL;
\r
851 nKey = VK_LCONTROL;
\r
855 if (lParam & EXTENDED_KEY) {
\r
862 if (lParam & EXTENDED_KEY) {
\r
872 if (lParam & BEING_RELEASED) {
\r
879 if (m_nHookAltRelease) {
\r
880 if (m_nHookAltRelease & ~HOOK_ALT_LATER)
\r
881 m_nHookAltRelease--;
\r
882 else if (m_nHookAltRelease & HOOK_ALT_LATER)
\r
883 m_nHookAltRelease = 0;
\r
890 for (int i = 0; i < MAX_COMMAND_TYPE; i++) {
\r
891 int (*func)() = Commands[m_Config.nCommandID[m_nApplicationID][i][nKey]].fCommand;
\r
892 if (func && !(bAlt && func == CCommands::MetaAlt))
\r
896 if (nOneShotModifier[nKey]) {
\r
897 ReleaseKey(nOneShotModifier[nKey]);
\r
898 nOneShotModifier[nKey] = 0;
\r
900 if (bCherryOneShotModifier) {
\r
901 bCherryOneShotModifier = FALSE;
\r
908 if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE) {
\r
912 // Do Nothing for Meadow, Mule for Win32, ... if those use default setting.
\r
913 if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))
\r
914 && CUtils::IsDefaultIgnoreApplication()) {
\r
918 switch (IsPassThrough(nKey)) {
\r
919 case GOTO_DO_NOTHING:
\r
930 // set command type
\r
931 nCommandType = IsDown(VK_SHIFT) * SHIFT | IsControl() * CONTROL | IsMeta() * META | CCommands::bC_x() * CONTROLX;
\r
932 // Ignore undefined C-x ?
\r
933 if (nCommandType & CONTROLX) {
\r
934 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL
\r
935 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {
\r
936 if (m_Config.bIgnoreUndefinedC_x[m_nApplicationID]) {
\r
937 CCommands::Reset(GOTO_HOOK);
\r
940 nCommandType &= ~CONTROLX;
\r
943 // Ignore undefined Meta Ctrl+?
\r
944 if (CCommands::bM_() && (nCommandType & CONTROL)) {
\r
945 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL
\r
946 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {
\r
947 if (m_Config.bIgnoreUndefinedMetaCtrl[m_nApplicationID]) {
\r
948 if (Original(CONTROL, nKey)) {
\r
949 Original(CONTROL, nKey, -1);
\r
952 CCommands::Reset(GOTO_HOOK);
\r
955 nCommandType &= ~META;
\r
960 BYTE nKey = (BYTE)wParam; // VK_CONTROL is needed instead of VK_RCONTROL and VK_LCONTROL in this block just for Original()
\r
961 int nVirtualCommandType = GetModifierState(FALSE);
\r
962 if (nKey == VK_CONTROL)
\r
963 nVirtualCommandType &= ~CONTROL;
\r
964 if (nKey == VK_MENU)
\r
965 nVirtualCommandType &= ~META;
\r
966 if (Original(nVirtualCommandType, nKey)) {
\r
967 Original(nVirtualCommandType, nKey, -1);
\r
972 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableOrDisableXKeymacs) {
\r
973 SetKeyboardHookFlag(!m_bHook);
\r
976 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableXKeymacs) {
\r
978 SetKeyboardHookFlag(!m_bHook);
\r
982 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DisableXKeymacs) {
\r
984 SetKeyboardHookFlag(!m_bHook);
\r
992 if (CCommands::bM_x()) {
\r
993 static unsigned int index = 0;
\r
994 static TCHAR szPath[MAX_PATH] = {'\0'};
\r
996 if (lParam & BEING_RELEASED) {
\r
998 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BackwardChar) {
\r
1003 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BeginningOfLine) {
\r
1006 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteBackwardChar) {
\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::DeleteChar) {
\r
1014 if (index < _tcslen(szPath)) {
\r
1015 memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);
\r
1016 SetM_xTip(szPath);
\r
1019 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EndOfLine) {
\r
1020 index = _tcslen(szPath);
\r
1022 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::ForwardChar) {
\r
1023 if (index < _tcslen(szPath)) {
\r
1027 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::KeyboardQuit) {
\r
1028 CCommands::bM_x(FALSE);
\r
1030 memset(szPath, 0, sizeof(szPath));
\r
1032 } else if (nKey == VK_RETURN
\r
1033 || Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::Newline) {
\r
1034 InvokeM_x(szPath);
\r
1036 CCommands::bM_x(FALSE);
\r
1038 memset(szPath, 0, sizeof(szPath));
\r
1040 } else if (index < MAX_PATH - 1) {
\r
1041 const BOOL bIsShiftDown = IsDown(VK_SHIFT, FALSE);
\r
1042 for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow
\r
1043 if (nKey != 0 && a2v(nAscii) == nKey && bIsShiftDown == IsShift(nAscii)) {
\r
1044 // CUtils::Log("M-x: %#X (%c), %#X (%c)", nKey, nKey, nAscii, nAscii);
\r
1045 if (index < _tcslen(szPath)) {
\r
1046 memmove(&szPath[index + 1], &szPath[index], __min(_tcslen(szPath) - index, MAX_PATH - (index + 1) - 1));
\r
1048 szPath[index++] = nAscii;
\r
1049 // CUtils::Log("M-x: %c(%#04x)", nAscii, nAscii);
\r
1050 SetM_xTip(szPath);
\r
1057 if (CCommands::bC_u()) {
\r
1058 if ((nCommandType == NONE) && ('0' <= nKey) && (nKey <= '9')) {
\r
1059 CCommands::NumericArgument(nKey - '0');
\r
1062 if ((nCommandType == NONE) && (nKey == 0xBD)) {
\r
1063 CCommands::NumericArgumentMinus();
\r
1068 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrl) {
\r
1069 nOneShotModifier[nKey] = VK_LCONTROL;
\r
1070 DepressKey(nOneShotModifier[nKey]);
\r
1071 bCherryOneShotModifier = TRUE;
\r
1073 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {
\r
1074 nOneShotModifier[nKey] = VK_LCONTROL;
\r
1075 DepressKey(nOneShotModifier[nKey]);
\r
1076 bCherryOneShotModifier = TRUE;
\r
1078 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {
\r
1079 ReleaseKey(nOneShotModifier[nKey]);
\r
1080 bCherryOneShotModifier = FALSE;
\r
1083 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAlt) {
\r
1084 nOneShotModifier[nKey] = VK_LMENU;
\r
1085 DepressKey(nOneShotModifier[nKey]);
\r
1086 bCherryOneShotModifier = TRUE;
\r
1088 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {
\r
1089 nOneShotModifier[nKey] = VK_LMENU;
\r
1090 DepressKey(nOneShotModifier[nKey]);
\r
1091 bCherryOneShotModifier = TRUE;
\r
1093 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {
\r
1094 ReleaseKey(nOneShotModifier[nKey]);
\r
1095 bCherryOneShotModifier = FALSE;
\r
1098 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShift) {
\r
1099 nOneShotModifier[nKey] = VK_SHIFT;
\r
1100 DepressKey(nOneShotModifier[nKey]);
\r
1101 bCherryOneShotModifier = TRUE;
\r
1103 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {
\r
1104 nOneShotModifier[nKey] = VK_SHIFT;
\r
1105 DepressKey(nOneShotModifier[nKey]);
\r
1106 bCherryOneShotModifier = TRUE;
\r
1108 } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {
\r
1109 ReleaseKey(nOneShotModifier[nKey]);
\r
1110 bCherryOneShotModifier = FALSE;
\r
1114 for (int i = 0; i < MAX_KEY; ++i) {
\r
1115 if (nOneShotModifier[i] == nKey) {
\r
1119 if (i == MAX_KEY) {
\r
1120 bCherryOneShotModifier = FALSE;
\r
1124 if (0 <= m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]
\r
1125 && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < MAX_FUNCTION
\r
1126 && _tcslen(m_Config.szFunctionDefinition[m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]])) {
\r
1127 CallFunction(m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]);
\r
1128 CCommands::Reset(GOTO_HOOK);
\r
1132 if (!Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand) {
\r
1133 if (nKey == VK_CONTROL
\r
1134 || nKey == VK_LCONTROL
\r
1135 || nKey == VK_RCONTROL
\r
1136 || nKey == VK_MENU
\r
1137 || nKey == VK_LMENU
\r
1138 || nKey == VK_RMENU
\r
1139 || nKey == VK_SHIFT
\r
1140 || nKey == VK_LSHIFT
\r
1141 || nKey == VK_RSHIFT) {
\r
1145 if (!(nCommandType & SHIFT)) {
\r
1146 if (CCommands::IsSetMark()) {
\r
1147 if (CCommands::MoveCaret(nKey, nCommandType & CONTROL) != CONTINUE) {
\r
1148 CCommands::ClearNumericArgument();
\r
1151 CCommands::SetMark(FALSE);
\r
1155 if (1 < CCommands::GetNumericArgument()) {
\r
1156 Kdu(nKey, CCommands::GetNumericArgument());
\r
1157 CCommands::ClearNumericArgument();
\r
1164 if (CCommands::IsTemporarilyDisableXKeymacs()
\r
1165 && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand != CCommands::KeyboardQuit) {
\r
1166 CCommands::SetTemporarilyDisableXKeymacs(FALSE);
\r
1170 if (m_Config.bAtIbeamCursorOnly[m_nApplicationID][nCommandType][nKey]) {
\r
1171 CURSORINFO cursorinfo = { sizeof(cursorinfo) };
\r
1172 if (GetCursorInfo(&cursorinfo) && cursorinfo.flags && cursorinfo.hCursor != LoadCursor(NULL, IDC_IBEAM)) {
\r
1177 m_bRightControl = IsDown(VK_RCONTROL, FALSE);
\r
1178 m_bRightAlt = IsDown(VK_RMENU, FALSE);
\r
1179 m_bRightShift = IsDown(VK_RSHIFT, FALSE);
\r
1183 fCommand = Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand;
\r
1184 RECURSIVE_COMMAND:
\r
1185 switch (fCommand()) {
\r
1186 case GOTO_DO_NOTHING:
\r
1192 case GOTO_RECURSIVE:
\r
1197 case GOTO_HOOK0_9:
\r
1206 goto HOOK_RECURSIVE_KEY;
\r
1210 SetModifierIcons();
\r
1212 static BOOL bDefiningMacro = FALSE;
\r
1213 if (m_bDefiningMacro) {
\r
1214 static BOOL bDown[MAX_KEY] = {'\0'};
\r
1216 if (!bDefiningMacro) {
\r
1217 while (m_Macro.GetHeadPosition()) {
\r
1218 void *p = m_Macro.GetAt(m_Macro.GetHeadPosition());
\r
1219 m_Macro.RemoveHead();
\r
1223 memset(bDown, 0, sizeof(bDown));
\r
1226 if ((!(lParam & BEING_RELEASED)) || bDown[wParam]) {
\r
1228 KbdMacro *pKbdMacro = new KbdMacro;
\r
1230 pKbdMacro->nCode = nCode;
\r
1231 pKbdMacro->wParam = wParam;
\r
1232 pKbdMacro->lParam = lParam;
\r
1233 pKbdMacro->bOriginal = TRUE;
\r
1234 m_Macro.AddTail((CObject *)pKbdMacro);
\r
1237 catch (CMemoryException* e) {
\r
1239 // CUtils::Log("KeyboardProc: 'new' threw an exception");
\r
1241 if (!(lParam & BEING_RELEASED)) {
\r
1242 bDown[wParam] = TRUE;
\r
1246 bDefiningMacro = m_bDefiningMacro;
\r
1249 return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);
\r
1252 Kdu(RECURSIVE_KEY, 1, FALSE);
\r
1255 CCommands::SetLastCommand(fCommand);
\r
1258 SetModifierIcons();
\r
1259 HOOK_RECURSIVE_KEY:
\r
1263 void CXkeymacsDll::SetModifierIcons()
\r
1265 #define IconState(x) ((x) ? ON_ICON : OFF_ICON)
\r
1266 ICONMSG msg[6] = {
\r
1267 {MX_ICON, IconState(CCommands::bM_x()), ""},
\r
1268 {CX_ICON, IconState(CCommands::bC_x()), ""},
\r
1269 {META_ICON, IconState(CCommands::bM_()), ""},
\r
1270 {SHIFT_ICON, IconState(IsDown(VK_SHIFT, FALSE)), ""},
\r
1271 {CTRL_ICON, IconState(IsControl()), ""},
\r
1272 {ALT_ICON, IconState(IsDown(VK_MENU, FALSE)), ""}
\r
1274 _tcscpy_s(msg[0].szTip, m_M_xTip);
\r
1275 SendIconMessage(msg, 6);
\r
1278 void CXkeymacsDll::SetApplicationName(int nApplicationID, CString szApplicationName)
\r
1280 ZeroMemory(m_Config.szSpecialApp[nApplicationID], CLASS_NAME_LENGTH);
\r
1281 _tcsncpy_s(m_Config.szSpecialApp[nApplicationID], szApplicationName, _TRUNCATE);
\r
1284 void CXkeymacsDll::SetWindowText(int nApplicationID, CString szWindowText)
\r
1286 ZeroMemory(m_Config.szWindowText[nApplicationID], WINDOW_TEXT_LENGTH);
\r
1287 _tcsncpy_s(m_Config.szWindowText[nApplicationID], szWindowText, _TRUNCATE);
\r
1290 void CXkeymacsDll::SetCommandID(int nApplicationID, int nCommandType, int nKey, int nCommandID)
\r
1292 m_Config.nCommandID[nApplicationID][nCommandType][nKey] = nCommandID;
\r
1295 void CXkeymacsDll::SetAtIbeamCursorOnly(int nApplicationID, int nCommandType, int nKey, BOOL bAtIbeamCursorOnly)
\r
1297 m_Config.bAtIbeamCursorOnly[nApplicationID][nCommandType][nKey] = bAtIbeamCursorOnly;
\r
1300 void CXkeymacsDll::SetKillRingMax(int nApplicationID, int nKillRingMax)
\r
1302 m_Config.nKillRingMax[nApplicationID] = nKillRingMax;
\r
1305 void CXkeymacsDll::SetUseDialogSetting(int nApplicationID, BOOL bUseDialogSetting)
\r
1307 m_Config.bUseDialogSetting[nApplicationID] = bUseDialogSetting;
\r
1310 // Clear data of nApplicationID
\r
1311 void CXkeymacsDll::Clear(int nApplicationID)
\r
1313 if (0 <= nApplicationID && nApplicationID < MAX_APP) {
\r
1314 ZeroMemory(m_Config.szSpecialApp[nApplicationID], sizeof(m_Config.szSpecialApp[nApplicationID]));
\r
1315 ZeroMemory(m_Config.nCommandID[nApplicationID], sizeof(m_Config.nCommandID[nApplicationID]));
\r
1316 ZeroMemory(m_Config.bAtIbeamCursorOnly[nApplicationID], sizeof(m_Config.bAtIbeamCursorOnly[nApplicationID]));
\r
1317 m_Config.nKillRingMax[nApplicationID] = 0;
\r
1318 m_Config.bUseDialogSetting[nApplicationID] = FALSE;
\r
1319 m_Config.nSettingStyle[nApplicationID] = 0;
\r
1325 BOOL CXkeymacsDll::IsValidKey(BYTE bVk)
\r
1327 if (bVk == 0xf0) { // 0xf0: Eisu key. GetAsyncKeyState returns the wrong state of Eisu key.
\r
1343 BOOL CXkeymacsDll::IsDepressedModifier(int (__cdecl *Modifier)(void), BOOL bPhysicalKey)
\r
1347 if (IsValidKey(bVk) && IsDown(bVk, bPhysicalKey) &&
\r
1348 Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == Modifier)
\r
1354 BOOL CXkeymacsDll::IsDepressedShiftKeyOnly(BYTE nKey)
\r
1356 if (nKey != VK_SHIFT
\r
1357 && nKey != VK_LSHIFT
\r
1358 && nKey != VK_RSHIFT) {
\r
1364 if (bVk == VK_SHIFT
\r
1365 || bVk == VK_LSHIFT
\r
1366 || bVk == VK_RSHIFT) {
\r
1370 if (IsDown(bVk, FALSE)) {
\r
1377 BOOL CXkeymacsDll::IsControl()
\r
1379 return CCommands::bC_() || IsDepressedModifier(CCommands::C_);
\r
1382 BOOL CXkeymacsDll::IsMeta()
\r
1384 return CCommands::bM_() || IsDepressedModifier(CCommands::MetaAlt);
\r
1387 void CXkeymacsDll::AddKillRing(BOOL bNewData)
\r
1389 if (m_Config.nKillRingMax[m_nApplicationID] == 0) {
\r
1393 CClipboardSnap *pSnap = new CClipboardSnap;
\r
1394 if( !pSnap ) return;
\r
1396 BOOL bCapture = pSnap->Capture();
\r
1397 bCapture = pSnap->Capture(); // for "office drawing shape format". Can CClipboardSnap care this problem?
\r
1401 m_oKillRing.AddHead(pSnap);
\r
1403 if (m_oKillRing.IsEmpty()) {
\r
1404 m_oKillRing.AddHead(pSnap);
\r
1406 for (CClipboardSnap *pParent = m_oKillRing.GetHead(); pParent->GetNext(); pParent = pParent->GetNext()) {
\r
1409 pParent->SetNext(pSnap);
\r
1419 if (m_Config.nKillRingMax[m_nApplicationID] < m_oKillRing.GetCount()) {
\r
1420 CClipboardSnap *pSnap = m_oKillRing.GetTail();
\r
1423 m_oKillRing.RemoveTail();
\r
1427 // Return TRUE if there is another data
\r
1428 // Return FALSE if there is no more data
\r
1429 CClipboardSnap* CXkeymacsDll::GetKillRing(CClipboardSnap* pSnap, BOOL bForce)
\r
1431 if (m_Config.nKillRingMax[m_nApplicationID] == 0) {
\r
1435 if (m_oKillRing.IsEmpty()) {
\r
1439 m_nKillRing %= m_oKillRing.GetCount();
\r
1442 CClipboardSnap oCurrentSnap;
\r
1443 oCurrentSnap.Capture();
\r
1445 CClipboardSnap *pKillRing = m_oKillRing.GetAt(m_oKillRing.FindIndex(m_nKillRing));
\r
1449 for (; pKillRing->GetNext(); pKillRing = pKillRing->GetNext()) {
\r
1452 if (*pKillRing != oCurrentSnap) {
\r
1458 pSnap = m_oKillRing.GetAt(m_oKillRing.FindIndex(m_nKillRing));
\r
1462 return pSnap->GetNext();
\r
1465 void CXkeymacsDll::Original(int nCommandType, BYTE bVk, int nOriginal)
\r
1467 nCommandType &= ~SHIFT;
\r
1471 bVk = VK_LCONTROL;
\r
1483 m_nOriginal[nCommandType][bVk] += nOriginal;
\r
1486 int CXkeymacsDll::Original(int nCommandType, BYTE bVk)
\r
1488 nCommandType &= ~SHIFT;
\r
1492 bVk = VK_LCONTROL;
\r
1504 return m_nOriginal[nCommandType][bVk];
\r
1507 void CXkeymacsDll::IncreaseKillRingIndex(int nKillRing)
\r
1509 m_nKillRing += nKillRing;
\r
1513 int CXkeymacsDll::GetMickey(int nDifferential, int nThreshold1, int nThreshold2, int nAcceleration, int nSpeed)
\r
1515 nDifferential = nDifferential * 10 / nSpeed;
\r
1517 switch (nAcceleration) {
\r
1519 if (nThreshold2 < fabs((double)(nDifferential / 4))) {
\r
1520 nDifferential /= 4;
\r
1523 // Do NOT write break; here.
\r
1525 if (nThreshold1 < fabs((double)(nDifferential / 2))) {
\r
1526 nDifferential /= 2;
\r
1536 return nDifferential;
\r
1539 void CXkeymacsDll::SetSettingStyle(int nApplicationID, int nSettingStyle)
\r
1541 m_Config.nSettingStyle[nApplicationID] = nSettingStyle;
\r
1544 void CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(int nApplicationID, BOOL bIgnoreUndefinedMetaCtrl)
\r
1546 m_Config.bIgnoreUndefinedMetaCtrl[nApplicationID] = bIgnoreUndefinedMetaCtrl;
\r
1549 void CXkeymacsDll::SetIgnoreUndefinedC_x(int nApplicationID, BOOL bIgnoreUndefinedC_x)
\r
1551 m_Config.bIgnoreUndefinedC_x[nApplicationID] = bIgnoreUndefinedC_x;
\r
1554 void CXkeymacsDll::SetEnableCUA(int nApplicationID, BOOL bEnableCUA)
\r
1556 m_Config.bEnableCUA[nApplicationID] = bEnableCUA;
\r
1559 BOOL CXkeymacsDll::GetEnableCUA()
\r
1561 return m_Config.bEnableCUA[m_nApplicationID];
\r
1564 void CXkeymacsDll::DefiningMacro(BOOL bDefiningMacro)
\r
1566 m_bDefiningMacro = bDefiningMacro;
\r
1568 if (bDefiningMacro) { // start-kbd-macro
\r
1569 if (CCommands::bC_u()) {
\r
1570 ReleaseKey(VK_SHIFT);
\r
1573 } else { // end-kbd-macro
\r
1574 while (!m_Macro.IsEmpty()) {
\r
1575 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetTail();
\r
1576 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1579 m_Macro.RemoveTail();
\r
1585 // CUtils::Log(_T("Macro MemMap: start"));
\r
1586 if (!m_Macro.IsEmpty()) {
\r
1587 static HANDLE hMacro = NULL;
\r
1589 hMacro = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 0x3000, _T("macro"));
\r
1592 // CUtils::Log(_T("Macro MemMap: 1"));
\r
1593 PVOID pView = MapViewOfFile(hMacro, FILE_MAP_ALL_ACCESS, 0, 0, 0);
\r
1594 // CUtils::Log(_T("Macro MemMap: 2"));
\r
1596 // CUtils::Log(_T("Macro MemMap: 2.5"));
\r
1597 for (int i = 0; i < m_Macro.GetCount(); ++i) {
\r
1598 // CUtils::Log(_T("Macro MemMap: 3-1 %d"), i);
\r
1599 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetAt(m_Macro.FindIndex(i));
\r
1600 // CUtils::Log(_T("Macro MemMap: 3-2 %d"), i);
\r
1601 memcpy((LPTSTR) pView + i * sizeof(KbdMacro), pKbdMacro, sizeof(KbdMacro));
\r
1602 // CUtils::Log(_T("Macro MemMap: 3-3 %d"), i);
\r
1604 // CUtils::Log(_T("Macro MemMap: 4"));
\r
1605 UnmapViewOfFile(pView);
\r
1606 // CUtils::Log(_T("Macro MemMap: 5"));
\r
1608 // CUtils::Log(_T("Macro MemMpa: error: %d"), GetLastError());
\r
1611 // CUtils::Log(_T("Macro MemMap: 6"));
\r
1618 BOOL CXkeymacsDll::DefiningMacro()
\r
1620 return m_bDefiningMacro;
\r
1624 void CXkeymacsDll::CallMacro()
\r
1626 UINT before = GetModifierState(FALSE);
\r
1627 SetModifierState(0, before);
\r
1628 for (POSITION pos = m_Macro.GetHeadPosition(); pos; ) {
\r
1629 KbdMacro *pKbdMacro = (KbdMacro *)m_Macro.GetNext(pos);
\r
1630 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1631 ReleaseKey((BYTE)pKbdMacro->wParam);
\r
1633 DepressKey((BYTE)pKbdMacro->wParam, pKbdMacro->bOriginal);
\r
1636 SetModifierState(before, 0);
\r
1640 void CXkeymacsDll::CallMacro() // for debug
\r
1643 for (POSITION pos = m_Macro.GetHeadPosition(); pos; ) {
\r
1644 KbdMacro_t *pKbdMacro = (KbdMacro_t *)m_Macro.GetNext(pos);
\r
1645 if (pKbdMacro->lParam & BEING_RELEASED) {
\r
1647 t.Format(_T("0x%xu "), pKbdMacro->wParam);
\r
1651 t.Format(_T("0x%xd "), pKbdMacro->wParam);
\r
1655 // CUtils::Log(sz);
\r
1659 void CXkeymacsDll::Set106Keyboard(BOOL b106Keyboard)
\r
1661 m_Config.b106Keyboard = b106Keyboard;
\r
1664 BOOL CXkeymacsDll::Is106Keyboard()
\r
1666 return m_Config.b106Keyboard;
\r
1669 int CXkeymacsDll::IsPassThrough(BYTE nKey)
\r
1674 && (Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == CCommands::PassThrough)) {
\r
1675 if (bVk == nKey) {
\r
1679 return GOTO_DO_NOTHING;
\r
1685 void CXkeymacsDll::SetKeyboardHookFlag()
\r
1687 SetKeyboardHookFlag(m_bHook);
\r
1690 void CXkeymacsDll::SetFunctionKey(int nFunctionID, int nApplicationID, int nCommandType, int nKey)
\r
1692 if (nApplicationID < 0 || MAX_APP <= nApplicationID
\r
1693 || nCommandType < 0 || MAX_COMMAND_TYPE <= nCommandType
\r
1694 || nKey < 0 || MAX_KEY <= nKey) {
\r
1698 m_Config.nFunctionID[nApplicationID][nCommandType][nKey] = nFunctionID;
\r
1701 void CXkeymacsDll::ClearFunctionDefinition()
\r
1703 memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID));
\r
1704 memset(m_Config.szFunctionDefinition, 0, sizeof(m_Config.szFunctionDefinition));
\r
1707 void CXkeymacsDll::SetFunctionDefinition(int nFunctionID, CString szDefinition)
\r
1709 if (nFunctionID < 0 || MAX_FUNCTION <= nFunctionID) {
\r
1713 memset(m_Config.szFunctionDefinition[nFunctionID], 0, sizeof(m_Config.szFunctionDefinition[nFunctionID]));
\r
1714 _stprintf_s(m_Config.szFunctionDefinition[nFunctionID], _T("%s"), szDefinition);
\r
1720 // call an original command which is defined in dot.xkeymacs
\r
1721 void CXkeymacsDll::CallFunction(int nFunctionID)
\r
1723 CArray<KeyBind, KeyBind> keybinds;
\r
1725 if (nFunctionID < 0 || MAX_FUNCTION <= nFunctionID || !_tcslen(m_Config.szFunctionDefinition[nFunctionID])) {
\r
1729 UINT before = GetModifierState(FALSE);
\r
1731 if (m_Config.szFunctionDefinition[nFunctionID][0] == _T('"') && m_Config.szFunctionDefinition[nFunctionID][_tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1] == _T('"')) {
\r
1732 for (unsigned int i = 1; i < _tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1; ++i) { // skip '"'
\r
1733 keybinds.Add(ParseKey(nFunctionID, i));
\r
1735 } else if (m_Config.szFunctionDefinition[nFunctionID][0] == _T('[') && m_Config.szFunctionDefinition[nFunctionID][_tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1] == _T(']')) {
\r
1736 for (unsigned int i = 1; i < _tcslen(m_Config.szFunctionDefinition[nFunctionID]) - 1; ++i) { // skip '[' and ']'
\r
1737 if (m_Config.szFunctionDefinition[nFunctionID][i] == _T('?')) { // [?f ?o ?o]
\r
1739 keybinds.Add(ParseKey(nFunctionID, i));
\r
1740 } else { // [ControlCharacter]
\r
1741 for (int nKeyID = 0; nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0]); ++nKeyID) {
\r
1742 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, ControlCharacters[nKeyID].name, _tcslen(ControlCharacters[nKeyID].name))) {
\r
1743 KeyBind keybind = {NONE, ControlCharacters[nKeyID].bVk};
\r
1744 keybinds.Add(keybind);
\r
1745 i += _tcslen(ControlCharacters[nKeyID].name);
\r
1755 BOOL bM_x = FALSE;
\r
1756 TCHAR szPath[MAX_PATH] = {'\0'};
\r
1757 unsigned int index = 0;
\r
1758 BOOL bInitialized = FALSE;
\r
1760 for (int i = 0; i < keybinds.GetSize(); ++i) {
\r
1761 const int nCommandType = keybinds.GetAt(i).nCommandType;
\r
1762 const BYTE bVk = keybinds.GetAt(i).bVk;
\r
1764 if (nCommandType < MAX_COMMAND_TYPE && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand) {
\r
1765 if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand == CCommands::ExecuteExtendedCommand) {
\r
1767 } else if (!bInitialized) {
\r
1768 SetModifierState(0, before);
\r
1769 bInitialized = TRUE;
\r
1771 // CUtils::Log("CallFunction: Command Name: %s", Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].szCommandName);
\r
1772 while (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand() == GOTO_RECURSIVE) {
\r
1775 } else if (bM_x) {
\r
1776 if (bVk == VK_RETURN) {
\r
1777 InvokeM_x(szPath);
\r
1779 for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow
\r
1780 if (bVk != 0 && a2v(nAscii) == bVk && ((nCommandType & SHIFT) != 0) == IsShift(nAscii)) {
\r
1781 // CUtils::Log("M-x: %#X (%c), %#X (%c)", bVk, bVk, nAscii, nAscii);
\r
1782 szPath[index++] = nAscii;
\r
1788 if (!bInitialized) {
\r
1789 SetModifierState(0, before);
\r
1790 bInitialized = TRUE;
\r
1792 if (nCommandType & WIN_WIN)
\r
1793 DepressKey(VK_LWIN);
\r
1794 if (nCommandType & WIN_CTRL)
\r
1795 DepressKey(VK_CONTROL);
\r
1796 if (nCommandType & WIN_ALT)
\r
1797 DepressKey(VK_MENU);
\r
1798 if (nCommandType & SHIFT)
\r
1799 DepressKey(VK_SHIFT);
\r
1803 if (nCommandType & SHIFT && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & SHIFT)))
\r
1804 ReleaseKey(VK_SHIFT);
\r
1805 if (nCommandType & WIN_ALT && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_ALT)))
\r
1806 ReleaseKey(VK_MENU);
\r
1807 if (nCommandType & WIN_CTRL && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_CTRL)))
\r
1808 ReleaseKey(VK_CONTROL);
\r
1809 if (nCommandType & WIN_WIN && (keybinds.GetSize() <= i + 1 || !(keybinds.GetAt(i + 1).nCommandType & WIN_WIN)))
\r
1810 ReleaseKey(VK_LWIN);
\r
1814 keybinds.RemoveAll();
\r
1817 // If these lines are invoked at M-x, a window transition does not work well.
\r
1818 SetModifierState(before, 0);
\r
1822 KeyBind CXkeymacsDll::ParseKey(const int nFunctionID, unsigned int &i)
\r
1824 KeyBind keybind = {NONE};
\r
1826 if (m_Config.szFunctionDefinition[nFunctionID][i] == _T('\\')) {
\r
1828 BOOL bFound = FALSE;
\r
1831 for (int ModifierID = 0; ModifierID < sizeof(Modifiers) / sizeof(Modifiers[0]); ++ModifierID) {
\r
1832 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, Modifiers[ModifierID].name, _tcslen(Modifiers[ModifierID].name))
\r
1833 && _tcslen(Modifiers[ModifierID].name) < _tcslen(m_Config.szFunctionDefinition[nFunctionID] + i)) {
\r
1834 keybind.nCommandType |= Modifiers[ModifierID].id;
\r
1835 i+= _tcslen(Modifiers[ModifierID].name);
\r
1841 if (IsShift(m_Config.szFunctionDefinition[nFunctionID][i]) && !(keybind.nCommandType & (WIN_CTRL | WIN_ALT | WIN_WIN))) {
\r
1842 keybind.nCommandType |= SHIFT;
\r
1845 for (int nKeyID = 0; nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0]); ++nKeyID) {
\r
1846 if (!_tcsncmp(m_Config.szFunctionDefinition[nFunctionID] + i, ControlCharacters[nKeyID].name, _tcslen(ControlCharacters[nKeyID].name))) {
\r
1847 i += _tcslen(ControlCharacters[nKeyID].name);
\r
1851 if (nKeyID < sizeof(ControlCharacters) / sizeof(ControlCharacters[0])) {
\r
1852 keybind.bVk = ControlCharacters[nKeyID].bVk;
\r
1854 keybind.bVk = a2v(m_Config.szFunctionDefinition[nFunctionID][i]);
\r
1860 BOOL CXkeymacsDll::IsShift(TCHAR nAscii)
\r
1873 return m_Config.b106Keyboard;
\r
1883 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
1886 return !m_Config.b106Keyboard;
\r
1892 return m_Config.b106Keyboard;
\r
1897 return !m_Config.b106Keyboard;
\r
1898 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
1899 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
1900 case _T('U'): case _T('V'): case _T('W'): case _T('X'): case _T('Y'): case _T('Z'):
\r
1907 return !m_Config.b106Keyboard;
\r
1911 return m_Config.b106Keyboard;
\r
1912 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
1913 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
1914 case _T('u'): case _T('v'): case _T('w'): case _T('x'): case _T('y'): case _T('z'):
\r
1926 BYTE CXkeymacsDll::a2v(TCHAR nAscii)
\r
1934 return m_Config.b106Keyboard ? '2' : (BYTE) 0xde; // VK_OEM_7
\r
1942 return m_Config.b106Keyboard ? '6' : '7';
\r
1944 return m_Config.b106Keyboard ? '7' : (BYTE) 0xde; // VK_OEM_7
\r
1946 return m_Config.b106Keyboard ? '8' : '9';
\r
1948 return m_Config.b106Keyboard ? '9' : '0';
\r
1950 return m_Config.b106Keyboard ? (BYTE) 0xba : '8'; // VK_OEM_1
\r
1952 return 0xbb; // VK_OEM_PLUS
\r
1954 return 0xbc; // VK_OEM_COMMA
\r
1956 return 0xbd; // VK_OEM_MINUS
\r
1958 return 0xbe; // VK_OEM_PERIOD
\r
1960 return 0xbf; // VK_OEM_2
\r
1961 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
1964 return 0xba; // VK_OEM_1
\r
1966 return m_Config.b106Keyboard ? (BYTE) 0xbb : (BYTE) 0xba; // VK_OEM_PLUS VK_OEM_1
\r
1968 return 0xbc; // VK_OEM_COMMA
\r
1970 return m_Config.b106Keyboard ? (BYTE) 0xbd : (BYTE) 0xbb; // VK_OEM_MINUS VK_OEM_PLUS
\r
1972 return 0xbe; // VK_OEM_PERIOD
\r
1974 return 0xbf; // VK_OEM_2
\r
1976 return m_Config.b106Keyboard ? (BYTE) 0xc0 : '2';
\r
1977 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
1978 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
1979 case _T('U'): case _T('V'): case _T('W'): case _T('X'): case _T('Y'): case _T('Z'):
\r
1982 return 0xdb; // VK_OEM_4
\r
1984 return 0xdc; // VK_OEM_5
\r
1986 return 0xdd; // VK_OEM_6
\r
1988 return m_Config.b106Keyboard ? (BYTE) 0xde : '6'; // VK_OEM_7
\r
1990 return m_Config.b106Keyboard ? (BYTE) 0xe2 : (BYTE) 0xbd; // VK_OEM_102 VK_OEM_MINUS
\r
1992 return 0xc0; // VK_OEM_3
\r
1993 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
1994 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
1995 case _T('u'): case _T('v'): case _T('w'): case _T('x'): case _T('y'): case _T('z'):
\r
1996 return (BYTE) (nAscii - (_T('a') - _T('A')));
\r
1998 return 0xdb; // VK_OEM_4
\r
2000 return 0xdc; // VK_OEM_5
\r
2002 return 0xdd; // VK_OEM_6
\r
2004 return m_Config.b106Keyboard ? (BYTE) 0xde : (BYTE) 0xc0; // VK_OEM_7 VK_OEM_3
\r
2010 BOOL CXkeymacsDll::IsMatchWindowText(CString szWindowText)
\r
2012 BOOL bIsMatchWindowText = TRUE;
\r
2014 TCHAR szCurrentWindowText[WINDOW_TEXT_LENGTH] = {'\0'};
\r
2015 GetWindowText(GetForegroundWindow(), szCurrentWindowText, sizeof(szCurrentWindowText));
\r
2017 switch (CUtils::GetWindowTextType(szWindowText)) {
\r
2018 case IDS_WINDOW_TEXT_MATCH: // *foo*
\r
2019 szWindowText.Delete(0); // Delete first '*'
\r
2020 szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'
\r
2021 bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText);
\r
2023 case IDS_WINDOW_TEXT_MATCH_FORWARD: // foo*
\r
2024 szWindowText.Delete(szWindowText.GetLength() - 1); // Delete last '*'
\r
2025 bIsMatchWindowText = 0 == CString(szCurrentWindowText).Find(szWindowText);
\r
2027 case IDS_WINDOW_TEXT_MATCH_BACKWARD: // *foo
\r
2028 szWindowText.Delete(0); // Delete first '*'
\r
2029 bIsMatchWindowText = 0 <= CString(szCurrentWindowText).Find(szWindowText, CString(szCurrentWindowText).GetLength() - szWindowText.GetLength());
\r
2031 case IDS_WINDOW_TEXT_MATCH_FULL: // foo
\r
2032 bIsMatchWindowText = szWindowText == CString(szCurrentWindowText);
\r
2034 case IDS_WINDOW_TEXT_IGNORE: // *
\r
2035 bIsMatchWindowText = TRUE;
\r
2042 // CUtils::Log(_T("IsMatchWindowText: %d, _%s_, _%s_"), bIsMatchWindowText, szCurrentWindowText, szWindowText);
\r
2043 return bIsMatchWindowText;
\r
2046 void CXkeymacsDll::SetAccelerate(int nAccelerate)
\r
2048 m_nAccelerate = nAccelerate;
\r
2051 int CXkeymacsDll::GetAccelerate()
\r
2053 return m_nAccelerate;
\r
2056 void CXkeymacsDll::SetKeyboardSpeed(int nKeyboardSpeed)
\r
2058 m_nKeyboardSpeed = nKeyboardSpeed;
\r
2061 unsigned int CXkeymacsDll::GetMaxKeyInterval()
\r
2063 // m_nKeyboardSpeed == 0: slowest repeat rate; approximately 2 characters per second
\r
2064 // m_nKeyboardSpeed == 31: fastest repeat rate; approximately 30 characters per second
\r
2065 // 47 ms is max on my machine w/ KeyboardSpeed 31.
\r
2066 // 1000 / 2 + 50 = 550
\r
2067 // 1000 / 30 + 50 = 83
\r
2068 return (unsigned int) (1000.0 / (2.0 + m_nKeyboardSpeed % 32 * 28.0 / 31.0) + 50.0);
\r
2071 void CXkeymacsDll::SetCursorData(HCURSOR hEnable, HCURSOR hDisableTMP, HCURSOR hDisableWOCQ, HICON hDisable, BOOL bEnable)
\r
2073 m_hCursor[STATUS_ENABLE] = hEnable;
\r
2074 m_hCursor[STATUS_DISABLE_TMP] = hDisableTMP;
\r
2075 m_hCursor[STATUS_DISABLE_WOCQ] = hDisableWOCQ;
\r
2076 m_hCursor[STATUS_DISABLE] = hDisable;
\r
2077 m_bCursor = bEnable;
\r
2080 void CXkeymacsDll::DoSetCursor()
\r
2082 if (m_bCursor && m_hCurrentCursor) {
\r
2083 ::SetCursor(m_hCurrentCursor);
\r
2087 void CXkeymacsDll::Set326Compatible(int nApplicationID, BOOL b326Compatible)
\r
2089 m_Config.b326Compatible[nApplicationID] = b326Compatible;
\r
2092 BOOL CXkeymacsDll::Get326Compatible()
\r
2094 return m_Config.b326Compatible[m_nApplicationID];
\r
2097 void CXkeymacsDll::InvokeM_x(const TCHAR *const szPath)
\r
2099 // CUtils::Log("M-x: szPath=_%s_", szPath);
\r
2100 int (*fCommand)() = NULL;
\r
2102 for (int i = 0; i < MAX_COMMAND; ++i) {
\r
2103 if (_tcsicmp(szPath, Commands[i].szCommandName) == 0) {
\r
2104 fCommand = Commands[i].fCommand;
\r
2110 // CUtils::Log("M-x: Command: _%s_", Commands[i].szCommandName);
\r
2113 // CUtils::Log("M-x: Path: _%s_", szPath);
\r
2114 ShellExecute(NULL, NULL, szPath, NULL, NULL, SW_SHOWNORMAL);
\r
2118 void CXkeymacsDll::SetM_xTip(const TCHAR *const szPath)
\r
2120 _tcscpy_s(m_M_xTip, "M-x LED");
\r
2121 if (szPath && _tcslen(szPath) < 128 - 5)
\r
2122 _stprintf_s(m_M_xTip, "M-x %s", szPath);
\r
2125 BOOL CXkeymacsDll::SendIconMessage(ICONMSG *pMsg, DWORD num)
\r
2128 return CallNamedPipe(ICON_PIPE, pMsg, sizeof(ICONMSG) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
\r