{ VK_DECIMAL, _T("kp-decimal") },\r
{ VK_DIVIDE, _T("kp-divide") },\r
// { VK_F1, _T("f1") }, // FIXME\r
-// { 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
+// { VK_F2, _T("f2") }, // Move at the end of definition of function keys to keep away confliction f1/f2 and f1?/f2? by _tcsncmp() i.e. strncmp()\r
{ VK_F3, _T("f3") },\r
{ VK_F4, _T("f4") },\r
{ VK_F5, _T("f5") },\r
\r
static AFX_EXTENSION_MODULE XkeymacsdllDLL = { NULL, NULL };\r
\r
-HINSTANCE g_hDllInst = NULL;\r
-UINT g_ImeManipulationMessage = 0;\r
-#pragma data_seg(".xkmcs")\r
-HHOOK g_hHookKeyboard = NULL;\r
-HHOOK g_hHookDummy = NULL;\r
-#pragma data_seg()\r
-\r
-inline bool IsWow64(HANDLE mod) {\r
- typedef BOOL (WINAPI *pfnIsWow64Process_t)(HANDLE, PBOOL);\r
- if (const pfnIsWow64Process_t IsWow64Process = (pfnIsWow64Process_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process")) {\r
- BOOL b;\r
- return IsWow64Process(mod, &b) && b;\r
- }\r
- return false;\r
-}\r
-\r
-inline bool Is64System() {\r
- SYSTEM_INFO info;\r
- GetNativeSystemInfo(&info);\r
- return info.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL;\r
-}\r
-\r
-inline bool Is64Process(HANDLE mod) {\r
- return Is64System() && !IsWow64(mod);\r
-}\r
-\r
-const bool IsDll64 = sizeof(void *) == 8;\r
-\r
-inline bool Is64ProcessHwnd(HWND hwnd) {\r
- DWORD pid;\r
- GetWindowThreadProcessId(hwnd, &pid);\r
- HANDLE hmod = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);\r
- bool b = Is64Process(hmod);\r
- CloseHandle(hmod);\r
- return b;\r
-}\r
+static HINSTANCE g_hDllInst = NULL;\r
+static DWORD g_TlsIndex = NULL;\r
\r
extern "C" int APIENTRY\r
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)\r
{\r
g_hDllInst = hInstance;\r
+ LPVOID lpData;\r
\r
// Remove this if you use lpReserved\r
UNREFERENCED_PARAMETER(lpReserved);\r
switch (dwReason) {\r
case DLL_PROCESS_ATTACH:\r
TRACE0("XKEYMACSDLL.DLL Initializing!\n");\r
- g_ImeManipulationMessage = RegisterWindowMessage(_T("XkManipulateIME"));\r
\r
// Extension DLL one-time initialization\r
if (!AfxInitExtensionModule(XkeymacsdllDLL, hInstance)) {\r
e->Delete();\r
// CUtils::Log("DllMain: 'new' threw an exception");\r
}\r
+\r
+ if ((g_TlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)\r
+ return FALSE;\r
+ // fall through\r
+ case DLL_THREAD_ATTACH:\r
+ if ((lpData = LocalAlloc(LPTR, sizeof(HHOOK))) != NULL)\r
+ TlsSetValue(g_TlsIndex, lpData);\r
break;\r
case DLL_PROCESS_DETACH:\r
TRACE0("XKEYMACSDLL.DLL Terminating!\n");\r
// Terminate the library before destructors are called\r
AfxTermExtensionModule(XkeymacsdllDLL);\r
+ CXkeymacsDll::ReleaseKeyboardHook();\r
+ if ((lpData = TlsGetValue(g_TlsIndex)) != NULL)\r
+ LocalFree(lpData);\r
+ TlsFree(g_TlsIndex);\r
+ break;\r
+ case DLL_THREAD_DETACH:\r
+ CXkeymacsDll::ReleaseKeyboardHook();\r
+ if ((lpData = TlsGetValue(g_TlsIndex)) != NULL)\r
+ LocalFree(lpData);\r
break;\r
}\r
return 1; // ok\r
\r
#include "xkeymacsDll.h"\r
#pragma data_seg(".xkmcs")\r
+ bool CXkeymacsDll::m_bEnableKeyboardHook = false;\r
DWORD CXkeymacsDll::m_nHookAltRelease = 0;\r
- HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;\r
- HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;\r
- HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;\r
- HHOOK CXkeymacsDll::m_hHookShell = NULL;\r
BOOL CXkeymacsDll::m_bRightControl = FALSE;\r
BOOL CXkeymacsDll::m_bRightAlt = FALSE;\r
BOOL CXkeymacsDll::m_bRightShift = FALSE;\r
BOOL CXkeymacsDll::m_bHook = TRUE;\r
CList<CClipboardSnap *, CClipboardSnap *> CXkeymacsDll::m_oKillRing;\r
int CXkeymacsDll::m_nKillRing = 0;\r
- int CXkeymacsDll::m_nOriginal[MAX_COMMAND_TYPE][MAX_KEY] = {'\0'};\r
- int CXkeymacsDll::m_nApplicationID = 0;\r
+ BYTE CXkeymacsDll::m_nOriginal[MAX_COMMAND_TYPE][MAX_KEY] = {'\0'};\r
+ int CXkeymacsDll::m_nAppID = 0;\r
int CXkeymacsDll::m_nAccelerate = 0;\r
int CXkeymacsDll::m_nKeyboardSpeed = 31;\r
HCURSOR CXkeymacsDll::m_hCursor[MAX_STATUS] = {'\0'};\r
TCHAR CXkeymacsDll::m_M_xTip[128] = "";\r
CONFIG CXkeymacsDll::m_Config = {0};\r
#pragma data_seg()\r
+HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;\r
+HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;\r
+HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;\r
+HHOOK CXkeymacsDll::m_hHookShell = NULL;\r
BOOL CXkeymacsDll::m_bRecordingMacro = FALSE;\r
BOOL CXkeymacsDll::m_bDown[MAX_KEY] = {0};\r
std::list<KbdMacro> CXkeymacsDll::m_Macro;\r
\r
-//////////////////////////////////////////////////////////////////////\r
-// Construction/Destruction\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-CXkeymacsDll::CXkeymacsDll()\r
-{\r
-\r
-}\r
-\r
-CXkeymacsDll::~CXkeymacsDll()\r
-{\r
-\r
-}\r
-\r
BOOL CXkeymacsDll::SaveConfig()\r
{\r
TCHAR szTmp[MAX_PATH];\r
return res;\r
}\r
\r
-// set hooks\r
-LRESULT WINAPI DummyProc(int code, WPARAM wp, LPARAM lp) {\r
- return CallNextHookEx(0, code, wp, lp);\r
+void CXkeymacsDll::SetConfig(const CONFIG& config)\r
+{\r
+ m_Config = config;\r
}\r
\r
void CXkeymacsDll::SetHooks()\r
{\r
- m_hHookCallWnd = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, g_hDllInst, 0);\r
- m_hHookCallWndRet = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)CallWndRetProc, g_hDllInst, 0);\r
- m_hHookGetMessage = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgProc, g_hDllInst, 0);\r
- m_hHookShell = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, g_hDllInst, 0);\r
- g_hHookDummy = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)DummyProc, g_hDllInst, 0);\r
- g_hHookKeyboard = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, g_hDllInst, 0);\r
+ m_hHookCallWnd = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, g_hDllInst, 0);\r
+ m_hHookCallWndRet = SetWindowsHookEx(WH_CALLWNDPROCRET, CallWndRetProc, g_hDllInst, 0);\r
+ m_hHookGetMessage = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hDllInst, 0);\r
+ m_hHookShell = SetWindowsHookEx(WH_SHELL, ShellProc, g_hDllInst, 0);\r
+ m_bEnableKeyboardHook = true;\r
}\r
\r
-inline void unhook(HHOOK &hh) {\r
+void CXkeymacsDll::SetKeyboardHook()\r
+{\r
+ LPVOID lpData = TlsGetValue(g_TlsIndex);\r
+ if (!lpData) {\r
+ lpData = LocalAlloc(LPTR, sizeof(HHOOK));\r
+ if (!lpData)\r
+ return;\r
+ if (!TlsSetValue(g_TlsIndex, lpData))\r
+ return;\r
+ }\r
+ HHOOK *phHook = reinterpret_cast<HHOOK *>(lpData);\r
+ if (!*phHook)\r
+ *phHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, g_hDllInst, GetCurrentThreadId());\r
+}\r
+\r
+inline void unhook(HHOOK &hh)\r
+{\r
if (hh)\r
UnhookWindowsHookEx(hh);\r
hh = NULL;\r
SetHooks();\r
}\r
\r
-// release hooks\r
void CXkeymacsDll::ReleaseHooks()\r
{\r
unhook(m_hHookCallWnd);\r
unhook(m_hHookCallWndRet);\r
unhook(m_hHookGetMessage);\r
unhook(m_hHookShell);\r
- unhook(g_hHookKeyboard);\r
- unhook(g_hHookDummy);\r
+ m_bEnableKeyboardHook = false;\r
+}\r
+\r
+void CXkeymacsDll::ReleaseKeyboardHook()\r
+{\r
+ HHOOK *phHook = reinterpret_cast<HHOOK *>(TlsGetValue(g_TlsIndex));\r
+ if (phHook)\r
+ unhook(*phHook);\r
}\r
\r
void CXkeymacsDll::ToggleKeyboardHookState()\r
} else {\r
msg.nState = STATUS_DISABLE_WOCQ;\r
}\r
- if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE\r
- || (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))\r
+ if (m_Config.nSettingStyle[m_nAppID] == SETTING_DISABLE\r
+ || (!_tcsicmp(m_Config.szSpecialApp[m_nAppID], _T("Default"))\r
&& CUtils::IsDefaultIgnoreApplication())) {\r
msg.nState = STATUS_DISABLE;\r
m_hCurrentCursor = m_hCursor[STATUS_DISABLE];\r
\r
LRESULT CALLBACK CXkeymacsDll::CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)\r
{\r
- if (nCode < 0)\r
- CallNextHookEx(m_hHookCallWnd, nCode, wParam, lParam);\r
- const CWPSTRUCT *cwps = reinterpret_cast<CWPSTRUCT *>(lParam);\r
- switch (cwps->message) {\r
- case WM_IME_STARTCOMPOSITION:\r
- InitKeyboardProc(TRUE);\r
- break;\r
- case WM_IME_ENDCOMPOSITION:\r
- InitKeyboardProc(FALSE);\r
- break;\r
- case WM_SETFOCUS:\r
- if (cwps->hwnd == GetForegroundWindow()) {\r
- InitKeyboardProc(FALSE);\r
- ShowKeyboardHookState();\r
- }\r
- break;\r
- case WM_NCACTIVATE:\r
- if (cwps->wParam && cwps->hwnd == GetForegroundWindow()) {\r
+ SetKeyboardHook();\r
+ if (nCode >= 0) {\r
+ const CWPSTRUCT *cwps = reinterpret_cast<CWPSTRUCT *>(lParam);\r
+ switch (cwps->message) {\r
+ case WM_IME_STARTCOMPOSITION:\r
+ InitKeyboardProc(TRUE);\r
+ break;\r
+ case WM_IME_ENDCOMPOSITION:\r
InitKeyboardProc(FALSE);\r
- ShowKeyboardHookState();\r
+ break;\r
+ case WM_SETFOCUS:\r
+ if (cwps->hwnd == GetForegroundWindow()) {\r
+ InitKeyboardProc(FALSE);\r
+ ShowKeyboardHookState();\r
+ }\r
+ break;\r
+ case WM_NCACTIVATE:\r
+ if (cwps->wParam && cwps->hwnd == GetForegroundWindow()) {\r
+ InitKeyboardProc(FALSE);\r
+ ShowKeyboardHookState();\r
+ }\r
+ break;\r
}\r
- break;\r
}\r
- return CallNextHookEx(m_hHookCallWnd, nCode, wParam, lParam);\r
+ return CallNextHookEx(NULL, nCode, wParam, lParam);\r
}\r
\r
LRESULT CALLBACK CXkeymacsDll::CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)\r
{\r
+ SetKeyboardHook();\r
if (nCode >= 0) {\r
const CWPRETSTRUCT *cwprets = reinterpret_cast<CWPRETSTRUCT *>(lParam);\r
switch (cwprets->message) {\r
break;\r
}\r
}\r
- return CallNextHookEx(m_hHookCallWndRet, nCode, wParam, lParam);\r
+ return CallNextHookEx(NULL, nCode, wParam, lParam);\r
}\r
\r
LRESULT CALLBACK CXkeymacsDll::GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)\r
{\r
- const MSG *msg = reinterpret_cast<MSG *>(lParam);\r
- if (msg->message == g_ImeManipulationMessage) {\r
- if (wParam)\r
- CCommands::DoSetInputMethodOpenStatus(static_cast<INPUT_METHOD_OPEN_STATUS>(msg->wParam), static_cast<BOOL>(msg->lParam));\r
- return 1;\r
- }\r
- switch (msg->message) {\r
- case WM_IME_STARTCOMPOSITION:\r
- InitKeyboardProc(TRUE);\r
- break;\r
- case WM_IME_ENDCOMPOSITION:\r
- InitKeyboardProc(FALSE);\r
- break;\r
+ SetKeyboardHook();\r
+ if (nCode >= 0) {\r
+ const MSG *msg = reinterpret_cast<MSG *>(lParam);\r
+ switch (msg->message) {\r
+ case WM_IME_STARTCOMPOSITION:\r
+ InitKeyboardProc(TRUE);\r
+ break;\r
+ case WM_IME_ENDCOMPOSITION:\r
+ InitKeyboardProc(FALSE);\r
+ break;\r
+ }\r
}\r
- return CallNextHookEx(m_hHookGetMessage, nCode, wParam, lParam);\r
+ return CallNextHookEx(NULL, nCode, wParam, lParam);\r
}\r
\r
LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam)\r
ShowKeyboardHookState();\r
}\r
}\r
- return CallNextHookEx( m_hHookShell, nCode, wParam, lParam );\r
+ return CallNextHookEx(NULL, nCode, wParam, lParam);\r
}\r
\r
UINT CXkeymacsDll::GetModifierState(BOOL bPhysicalKey)\r
UpdateKeyboardState(VK_CONTROL, 0);\r
}\r
\r
- const BOOL bHookApp = CUtils::IsVisualCpp() || CUtils::IsFirefox() || CUtils::IsVisualStudio() || CUtils::IsInternetExplorer();\r
+ const BOOL bHookApp =\r
+ CUtils::IsVisualCpp() || CUtils::IsVisualStudio() ||\r
+ CUtils::IsInternetExplorer() || CUtils::IsFirefox() || CUtils::IsChrome();\r
if (after & META && !(before & META)) {\r
if (bHookApp)\r
m_nHookAltRelease |= HOOK_ALT_LATER;\r
DepressKey(VK_MENU);\r
} else if (!(after & META) && before & META) {\r
if (bHookApp)\r
- m_nHookAltRelease++;\r
+ ++m_nHookAltRelease;\r
ReleaseKey(VK_MENU);\r
}\r
}\r
void CXkeymacsDll::InitKeyboardProc(BOOL bImeComposition)\r
{\r
CUtils::SetApplicationName(bImeComposition);\r
- if (_tcsnicmp(m_Config.szSpecialApp[m_nApplicationID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nApplicationID])) { // PROCESSENTRY32 has only 0xF bytes of Name\r
- m_nApplicationID = -1;\r
- for (int nAppID = 0; nAppID < MAX_APP; nAppID++) {\r
+ if (_tcsnicmp(m_Config.szSpecialApp[m_nAppID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[m_nAppID])) { // PROCESSENTRY32 has only 0xF bytes of Name\r
+ m_nAppID = -1;\r
+ for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {\r
if (_tcsnicmp(m_Config.szSpecialApp[nAppID], CUtils::GetApplicationName(), 0xF) || !IsMatchWindowText(m_Config.szWindowText[nAppID]))\r
continue;\r
- if (m_nApplicationID < 0)\r
- m_nApplicationID = nAppID;\r
+ if (m_nAppID < 0)\r
+ m_nAppID = nAppID;\r
else {\r
- const LPCSTR curText = m_Config.szWindowText[m_nApplicationID];\r
+ const LPCSTR curText = m_Config.szWindowText[m_nAppID];\r
const LPCSTR newText = m_Config.szWindowText[nAppID];\r
const int curType = CUtils::GetWindowTextType(curText);\r
const int newType = CUtils::GetWindowTextType(newText);\r
if (curType < newType || curType == newType && _tcscmp(curText, newText) <= 0)\r
- m_nApplicationID = nAppID;\r
+ m_nAppID = nAppID;\r
}\r
}\r
- if (m_nApplicationID < 0)\r
- m_nApplicationID = GetAppID(_T("Default"), 0);\r
+ if (m_nAppID < 0)\r
+ m_nAppID = GetAppID(_T("Default"), 0);\r
}\r
- if (m_Config.nSettingStyle[m_nApplicationID] != SETTING_DISABLE &&\r
- (_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default")) || !CUtils::IsDefaultIgnoreApplication()) &&\r
- !bImeComposition && CUtils::IsDialog() && m_Config.bUseDialogSetting[m_nApplicationID])\r
+ if (m_Config.nSettingStyle[m_nAppID] != SETTING_DISABLE &&\r
+ (_tcsicmp(m_Config.szSpecialApp[m_nAppID], _T("Default")) || !CUtils::IsDefaultIgnoreApplication()) &&\r
+ !bImeComposition && CUtils::IsDialog() && m_Config.bUseDialogSetting[m_nAppID])\r
// Use Dialog Setting\r
- m_nApplicationID = GetAppID(_T("Dialog"), m_nApplicationID);\r
+ m_nAppID = GetAppID(_T("Dialog"), m_nAppID);\r
\r
ICONMSG msg[3] = {\r
{CX_ICON, OFF_ICON, ""},\r
\r
int CXkeymacsDll::GetAppID(const LPCSTR szName, const int fallback)\r
{\r
- for (int i = 0; i < MAX_APP; i++)\r
+ for (int i = 0; i < MAX_APP; ++i)\r
if (!_tcsicmp(m_Config.szSpecialApp[i], szName))\r
return i;\r
return fallback;\r
\r
LRESULT CALLBACK CXkeymacsDll::KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)\r
{\r
- ASSERT(0 <= wParam && wParam <= UCHAR_MAX);\r
-\r
- UINT nCommandType = NONE;\r
- BYTE nOrigKey = (BYTE)wParam;\r
+ const BYTE nOrigKey = static_cast<BYTE>(wParam);\r
+ const bool bRelease = (HIWORD(lParam) & KF_UP) != 0;\r
+ const bool bExtended = (HIWORD(lParam) & KF_EXTENDED) != 0;\r
\r
static BOOL bLocked = FALSE;\r
static const BYTE RECURSIVE_KEY = 0x07;\r
- static int (*fCommand)() = NULL;\r
+ static int (*fLastCommand)() = NULL;\r
static BYTE nOneShotModifier[MAX_KEY] = {'\0'};\r
static BOOL bCherryOneShotModifier = FALSE;\r
\r
-// CUtils::Log(_T("nCode = %#x, nKey = %#x, lParam = %p, %d, %d"), nOrigCode, nKey, lParam, IsDll64, Is64ProcessHwnd(GetForegroundWindow()));\r
-\r
- if (Is64ProcessHwnd(GetForegroundWindow()) != IsDll64 || CUtils::IsXkeymacs())\r
- return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);\r
+// CUtils::Log(_T("nCode = %#x, nKey = %#x, lParam = %#x"), nCode, nOrigKey, lParam);\r
\r
- if (nCode < 0 || nCode == HC_NOREMOVE) {\r
- goto DO_NOTHING;\r
- }\r
+ if (!m_bEnableKeyboardHook || CUtils::IsXkeymacs() ||\r
+ nCode < 0 || nCode == HC_NOREMOVE)\r
+ return CallNextHookEx(NULL, nCode, wParam, lParam);\r
\r
// CUtils::Log(_T("nKey = %#x, ext = %d, rel = %d, pre = %d, %#hx, %#hx"), nOrigKey,\r
-// (lParam & EXTENDED_KEY) ? 1 : 0, (lParam & BEING_RELEASED) ? 1 : 0, (lParam & REPEATED_KEY) ? 1 : 0,\r
+// (HIWORD(lParam) & KF_EXTENDED) ? 1 : 0, (HIWORD(lParam) & KF_UP) ? 1 : 0, (HIWORD(lParam) & KF_REPEAT) ? 1 : 0,\r
// GetKeyState(nOrigKey), GetAsyncKeyState(nOrigKey));\r
\r
if (nOrigKey == RECURSIVE_KEY) {\r
- if (lParam & BEING_RELEASED) {\r
+ if (bRelease)\r
goto HOOK_RECURSIVE_KEY;\r
- } else {\r
+ else\r
goto RECURSIVE_COMMAND;\r
- }\r
}\r
\r
- {\r
- static BOOL bShift = FALSE;\r
- if (IsDepressedShiftKeyOnly(nOrigKey)) {\r
- if (lParam & BEING_RELEASED) {\r
- if (bShift) {\r
- CCommands::SetMark(FALSE);\r
- }\r
- } else {\r
- bShift = TRUE;\r
- }\r
- } else {\r
- bShift = FALSE;\r
- }\r
- }\r
+ CancelMarkWithShift(nOrigKey, bRelease);\r
\r
BYTE nKey = nOrigKey;\r
switch (nKey) {\r
case VK_CONTROL:\r
- if (lParam & EXTENDED_KEY) {\r
- nKey = VK_RCONTROL;\r
- } else {\r
- nKey = VK_LCONTROL;\r
- }\r
+ nKey = bExtended ? VK_RCONTROL : VK_LCONTROL;\r
break;\r
case VK_MENU:\r
- if (lParam & EXTENDED_KEY) {\r
- nKey = VK_RMENU;\r
- } else {\r
- nKey = VK_LMENU;\r
- }\r
+ nKey = bExtended ? VK_RMENU : VK_LMENU;\r
break;\r
case VK_SHIFT:\r
- if (lParam & EXTENDED_KEY) {\r
- nKey = VK_RSHIFT;\r
- } else {\r
- nKey = VK_LSHIFT;\r
- }\r
- break;\r
- default:\r
+ nKey = bExtended ? VK_RSHIFT : VK_LSHIFT;\r
break;\r
}\r
\r
- if (lParam & BEING_RELEASED) {\r
+#define fCommand(type) (Commands[m_Config.nCommandID[m_nAppID][(type)][nKey]].fCommand)\r
+#define nFunctionID (m_Config.nFunctionID[m_nAppID][nType][nKey])\r
+\r
+ if (bRelease) {\r
switch (nOrigKey) {\r
case VK_MENU:\r
if (m_nHookAltRelease) {\r
case VK_LWIN:\r
case VK_RWIN:\r
case VK_APPS:\r
- for (int i = 0; i < MAX_COMMAND_TYPE; i++) {\r
- int (*func)() = Commands[m_Config.nCommandID[m_nApplicationID][i][nKey]].fCommand;\r
- if (func && !(nOrigKey == VK_MENU && func == CCommands::MetaAlt))\r
+ for (int i = 0; i < MAX_COMMAND_TYPE; ++i) {\r
+ int (*const fCommand)() = fCommand(i);\r
+ if (fCommand && !(nOrigKey == VK_MENU && fCommand == CCommands::MetaAlt))\r
goto HOOK;\r
}\r
}\r
if (nOneShotModifier[nKey]) {\r
ReleaseKey(nOneShotModifier[nKey]);\r
nOneShotModifier[nKey] = 0;\r
-\r
if (bCherryOneShotModifier) {\r
bCherryOneShotModifier = FALSE;\r
Kdu(nKey);\r
goto DO_NOTHING;\r
}\r
\r
- if (m_Config.nSettingStyle[m_nApplicationID] == SETTING_DISABLE) {\r
+ if (m_Config.nSettingStyle[m_nAppID] == SETTING_DISABLE)\r
goto DO_NOTHING;\r
- }\r
\r
// Do Nothing for Meadow, Mule for Win32, ... if those use default setting.\r
- if (!_tcsicmp(m_Config.szSpecialApp[m_nApplicationID], _T("Default"))\r
- && CUtils::IsDefaultIgnoreApplication()) {\r
+ if (!_tcsicmp(m_Config.szSpecialApp[m_nAppID], _T("Default")) && CUtils::IsDefaultIgnoreApplication())\r
goto DO_NOTHING;\r
- }\r
\r
switch (IsPassThrough(nKey)) {\r
case GOTO_DO_NOTHING:\r
goto HOOK;\r
case CONTINUE:\r
break;\r
- default:\r
- ASSERT(0);\r
- break;\r
}\r
\r
// set command type\r
- nCommandType = IsDown(VK_SHIFT) * SHIFT | IsControl() * CONTROL | IsMeta() * META | CCommands::bC_x() * CONTROLX;\r
+ int nType = IsDown(VK_SHIFT) * SHIFT | IsControl() * CONTROL | IsMeta() * META | CCommands::bC_x() * CONTROLX;\r
// Ignore undefined C-x ?\r
- if (nCommandType & CONTROLX) {\r
- if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL\r
- && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {\r
- if (m_Config.bIgnoreUndefinedC_x[m_nApplicationID]) {\r
- CCommands::Reset(GOTO_HOOK);\r
- goto HOOK;\r
- }\r
- nCommandType &= ~CONTROLX;\r
+ if (nType & CONTROLX && fCommand(nType) == NULL && nFunctionID < 0) {\r
+ if (m_Config.bIgnoreUndefinedC_x[m_nAppID]) {\r
+ CCommands::Reset(GOTO_HOOK);\r
+ goto HOOK;\r
}\r
+ nType &= ~CONTROLX;\r
}\r
// Ignore undefined Meta Ctrl+?\r
- if (CCommands::bM_() && (nCommandType & CONTROL)) {\r
- if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == NULL\r
- && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < 0) {\r
- if (m_Config.bIgnoreUndefinedMetaCtrl[m_nApplicationID]) {\r
- if (CheckOriginal(CONTROL, nKey)) {\r
- goto DO_NOTHING;\r
- }\r
- CCommands::Reset(GOTO_HOOK);\r
- goto HOOK;\r
- }\r
- nCommandType &= ~META;\r
+ if (CCommands::bM_() && nType & CONTROL && fCommand(nType) == NULL && nFunctionID < 0) {\r
+ if (m_Config.bIgnoreUndefinedMetaCtrl[m_nAppID]) {\r
+ if (CheckOriginal(CONTROL, nKey))\r
+ goto DO_NOTHING;\r
+ CCommands::Reset(GOTO_HOOK);\r
+ goto HOOK;\r
+ nType &= ~META;\r
}\r
}\r
\r
- int nVirtualCommandType = GetModifierState(FALSE);\r
+ int nVirtualType = GetModifierState(FALSE);\r
if (nOrigKey == VK_CONTROL)\r
- nVirtualCommandType &= ~CONTROL;\r
+ nVirtualType &= ~CONTROL;\r
if (nOrigKey == VK_MENU)\r
- nVirtualCommandType &= ~META;\r
- if (CheckOriginal(nVirtualCommandType, nOrigKey)) {\r
+ nVirtualType &= ~META;\r
+ if (CheckOriginal(nVirtualType, nOrigKey)) {\r
goto DO_NOTHING;\r
}\r
\r
- if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableOrDisableXKeymacs) {\r
+ int (*const fCommand)() = fCommand(nType);\r
+ if (fCommand == CCommands::EnableOrDisableXKeymacs) {\r
ToggleKeyboardHookState();\r
goto HOOK;\r
}\r
- if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EnableXKeymacs) {\r
- if (!m_bHook) {\r
+ if (fCommand == CCommands::EnableXKeymacs) {\r
+ if (!m_bHook)\r
ToggleKeyboardHookState();\r
- }\r
goto HOOK;\r
}\r
- if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DisableXKeymacs) {\r
- if (m_bHook) {\r
+ if (fCommand == CCommands::DisableXKeymacs) {\r
+ if (m_bHook)\r
ToggleKeyboardHookState();\r
- }\r
goto HOOK;\r
}\r
- if (!m_bHook) {\r
+ if (!m_bHook)\r
goto DO_NOTHING;\r
- }\r
\r
- if (CCommands::bM_x()) {\r
- static unsigned int index = 0;\r
+ if (CCommands::bM_x() && !bRelease) {\r
+ static size_t index = 0;\r
static TCHAR szPath[MAX_PATH] = {'\0'};\r
-\r
- if (lParam & BEING_RELEASED) {\r
- // ignore\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BackwardChar) {\r
- if (index) {\r
+ if (fCommand == CCommands::BackwardChar) {\r
+ if (index)\r
--index;\r
- }\r
goto HOOKX;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::BeginningOfLine) {\r
+ } else if (fCommand == CCommands::BeginningOfLine) {\r
index = 0;\r
goto HOOKX;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteBackwardChar) {\r
+ } else if (fCommand == CCommands::DeleteBackwardChar) {\r
if (index) {\r
--index;\r
- memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);\r
+ memmove(szPath + index, szPath + index + 1, MAX_PATH - index);\r
SetM_xTip(szPath);\r
}\r
goto HOOKX;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::DeleteChar) {\r
+ } else if (fCommand == CCommands::DeleteChar) {\r
if (index < _tcslen(szPath)) {\r
- memmove(&szPath[index], &szPath[index + 1], _tcslen(szPath) - index);\r
+ memmove(szPath + index, szPath + index + 1, MAX_PATH - index);\r
SetM_xTip(szPath);\r
}\r
goto HOOKX;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::EndOfLine) {\r
+ } else if (fCommand == CCommands::EndOfLine) {\r
index = _tcslen(szPath);\r
goto HOOKX;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::ForwardChar) {\r
- if (index < _tcslen(szPath)) {\r
+ } else if (fCommand == CCommands::ForwardChar) {\r
+ if (index < _tcslen(szPath))\r
++index;\r
- }\r
goto HOOKX;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::KeyboardQuit) {\r
+ } else if (fCommand == CCommands::KeyboardQuit) {\r
CCommands::bM_x(FALSE);\r
index = 0;\r
memset(szPath, 0, sizeof(szPath));\r
goto HOOK;\r
- } else if (nKey == VK_RETURN\r
- || Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::Newline) {\r
+ } else if (nKey == VK_RETURN || fCommand == CCommands::Newline) {\r
InvokeM_x(szPath);\r
-\r
CCommands::bM_x(FALSE);\r
index = 0;\r
memset(szPath, 0, sizeof(szPath));\r
goto HOOK;\r
- } else if (index < MAX_PATH - 1) {\r
+ } else if (nKey && index < MAX_PATH - 1) {\r
const BOOL bIsShiftDown = IsDown(VK_SHIFT, FALSE);\r
- for (TCHAR nAscii = 1; nAscii != 0; ++nAscii) { // repeat until overflow\r
- if (nKey != 0 && a2v(nAscii) == nKey && bIsShiftDown == IsShift(nAscii)) {\r
+ TCHAR nAscii = 0;\r
+ do { // 1-127\r
+ if (a2v(++nAscii) == nKey && bIsShiftDown == IsShift(nAscii)) {\r
// CUtils::Log("M-x: %#X (%c), %#X (%c)", nKey, nKey, nAscii, nAscii);\r
- if (index < _tcslen(szPath)) {\r
- memmove(&szPath[index + 1], &szPath[index], __min(_tcslen(szPath) - index, MAX_PATH - (index + 1) - 1));\r
- }\r
+ if (index < _tcslen(szPath))\r
+ memmove(szPath + index + 1, szPath + index, MAX_PATH - index - 1);\r
szPath[index++] = nAscii;\r
// CUtils::Log("M-x: %c(%#04x)", nAscii, nAscii);\r
SetM_xTip(szPath);\r
goto HOOKX;\r
}\r
- }\r
+ } while (nAscii != 127);\r
}\r
}\r
\r
- if (CCommands::bC_u()) {\r
- if ((nCommandType == NONE) && ('0' <= nKey) && (nKey <= '9')) {\r
+ if (CCommands::bC_u() && nType == NONE) {\r
+ if ('0' <= nKey && nKey <= '9') {\r
CCommands::NumericArgument(nKey - '0');\r
goto HOOK0_9;\r
}\r
- if ((nCommandType == NONE) && (nKey == 0xBD)) {\r
+ if (nKey == VK_OEM_MINUS) {\r
CCommands::NumericArgumentMinus();\r
goto HOOK0_9;\r
}\r
}\r
\r
- if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrl) {\r
- nOneShotModifier[nKey] = VK_CONTROL;\r
- DepressKey(VK_CONTROL);\r
- bCherryOneShotModifier = TRUE;\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {\r
- nOneShotModifier[nKey] = VK_CONTROL;\r
- DepressKey(VK_CONTROL);\r
- bCherryOneShotModifier = TRUE;\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~CONTROL][nKey]].fCommand == CCommands::OneShotModifierCtrlRepeat) {\r
- ReleaseKey(VK_CONTROL);\r
- bCherryOneShotModifier = FALSE;\r
- Kdu(nKey);\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAlt) {\r
- nOneShotModifier[nKey] = VK_MENU;\r
- DepressKey(VK_MENU);\r
- bCherryOneShotModifier = TRUE;\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {\r
- nOneShotModifier[nKey] = VK_MENU;\r
- DepressKey(VK_MENU);\r
- bCherryOneShotModifier = TRUE;\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~META][nKey]].fCommand == CCommands::OneShotModifierAltRepeat) {\r
- ReleaseKey(VK_MENU);\r
- bCherryOneShotModifier = FALSE;\r
- Kdu(nKey);\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShift) {\r
- nOneShotModifier[nKey] = VK_SHIFT;\r
- DepressKey(VK_SHIFT);\r
- bCherryOneShotModifier = TRUE;\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {\r
- nOneShotModifier[nKey] = VK_SHIFT;\r
- DepressKey(VK_SHIFT);\r
- bCherryOneShotModifier = TRUE;\r
- goto HOOK;\r
- } else if (Commands[m_Config.nCommandID[m_nApplicationID][nCommandType & ~SHIFT][nKey]].fCommand == CCommands::OneShotModifierShiftRepeat) {\r
- ReleaseKey(VK_SHIFT);\r
- bCherryOneShotModifier = FALSE;\r
- Kdu(nKey);\r
- goto HOOK;\r
- } else {\r
- for (int i = 0; i < MAX_KEY; ++i) {\r
- if (nOneShotModifier[i] == nKey) {\r
- break;\r
- }\r
- }\r
- if (i == MAX_KEY) {\r
- bCherryOneShotModifier = FALSE;\r
- }\r
+#define OneShotModifier(type, vk, mod) \\r
+ if (fCommand(nType & ~type) == CCommands::OneShotModifier ## mod || \\r
+ fCommand(nType) == CCommands::OneShotModifier ## mod ## Repeat) { \\r
+ nOneShotModifier[nKey] = vk; \\r
+ DepressKey(vk); \\r
+ bCherryOneShotModifier = TRUE; \\r
+ goto HOOK; \\r
+ } else if (fCommand(nType & ~CONTROL) == CCommands::OneShotModifier ## mod ## Repeat) { \\r
+ ReleaseKey(vk); \\r
+ bCherryOneShotModifier = FALSE; \\r
+ Kdu(nKey); \\r
+ goto HOOK; \\r
}\r
\r
- if (0 <= m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]\r
- && m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey] < MAX_FUNCTION\r
- && _tcslen(m_Config.szFunctionDefinition[m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]])) {\r
- CallFunction(m_Config.nFunctionID[m_nApplicationID][nCommandType][nKey]);\r
+ OneShotModifier(CONTROL, VK_CONTROL, Ctrl);\r
+ OneShotModifier(META, VK_MENU, Alt);\r
+ OneShotModifier(SHIFT, VK_SHIFT, Shift);\r
+ int i;\r
+ for (i = 0; i < MAX_KEY; ++i)\r
+ if (nOneShotModifier[i] == nOrigKey)\r
+ break;\r
+ if (i == MAX_KEY)\r
+ bCherryOneShotModifier = FALSE;\r
+\r
+ if (0 <= nFunctionID && nFunctionID < MAX_FUNCTION && m_Config.szFunctionDefinition[nFunctionID][0]) {\r
+ CallFunction(nFunctionID);\r
CCommands::Reset(GOTO_HOOK);\r
goto HOOK;\r
}\r
+#undef fCommand\r
+#undef nFunctionID\r
\r
- if (!Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand) {\r
- if (nOrigKey == VK_CONTROL || nOrigKey == VK_MENU || nOrigKey == VK_SHIFT) {\r
+ if (!fCommand) {\r
+ if (nOrigKey == VK_CONTROL || nOrigKey == VK_MENU || nOrigKey == VK_SHIFT)\r
goto DO_NOTHING;\r
- }\r
-\r
- if (!(nCommandType & SHIFT)) {\r
+ if (!(nType & SHIFT)) {\r
if (CCommands::IsSetMark()) {\r
- if (CCommands::MoveCaret(nKey, nCommandType & CONTROL) != CONTINUE) {\r
+ if (CCommands::MoveCaret(nKey, nType & CONTROL) != CONTINUE) {\r
CCommands::ClearNumericArgument();\r
goto HOOK;\r
}\r
CCommands::SetMark(FALSE);\r
}\r
}\r
-\r
if (1 < CCommands::GetNumericArgument()) {\r
Kdu(nKey, CCommands::GetNumericArgument());\r
CCommands::ClearNumericArgument();\r
goto HOOK;\r
}\r
-\r
goto DO_NOTHING;\r
}\r
\r
- if (CCommands::IsTemporarilyDisableXKeymacs()\r
- && Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand != CCommands::KeyboardQuit) {\r
+ if (CCommands::IsTemporarilyDisableXKeymacs() && fCommand != CCommands::KeyboardQuit) {\r
CCommands::SetTemporarilyDisableXKeymacs(FALSE);\r
goto DO_NOTHING;\r
}\r
m_bRightAlt = IsDown(VK_RMENU, FALSE);\r
m_bRightShift = IsDown(VK_RSHIFT, FALSE);\r
\r
- if (!bLocked) {\r
- bLocked = TRUE;\r
- fCommand = Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][nKey]].fCommand;\r
+ if (bLocked)\r
+ goto HOOK_RECURSIVE_KEY;\r
+ bLocked = TRUE;\r
+ fLastCommand = fCommand;\r
RECURSIVE_COMMAND:\r
- switch (fCommand()) {\r
- case GOTO_DO_NOTHING:\r
- bLocked = FALSE;\r
- goto DO_NOTHING;\r
- case GOTO_HOOK:\r
- bLocked = FALSE;\r
- goto HOOK;\r
- case GOTO_RECURSIVE:\r
- goto RECURSIVE;\r
- case GOTO_HOOKX:\r
- bLocked = FALSE;\r
- goto HOOKX;\r
+ switch (fLastCommand()) {\r
+ case GOTO_DO_NOTHING:\r
+ bLocked = FALSE;\r
+ goto DO_NOTHING;\r
+ case GOTO_HOOK:\r
+ bLocked = FALSE;\r
+ goto HOOK;\r
+ case GOTO_RECURSIVE:\r
+ goto RECURSIVE;\r
+ case GOTO_HOOKX:\r
+ bLocked = FALSE;\r
+ goto HOOKX;\r
case GOTO_HOOK0_9:\r
- bLocked = FALSE;\r
- goto HOOK0_9;\r
- default:\r
- ASSERT(0);\r
- bLocked = FALSE;\r
- goto DO_NOTHING;\r
- }\r
- } else {\r
- goto HOOK_RECURSIVE_KEY;\r
+ bLocked = FALSE;\r
+ goto HOOK0_9;\r
}\r
\r
DO_NOTHING:\r
SetModifierIcons();\r
- if (m_bRecordingMacro && (!(lParam & BEING_RELEASED) || m_bDown[wParam])) {\r
+ if (m_bRecordingMacro && (!bRelease || m_bDown[wParam])) {\r
KbdMacro m = { nCode, wParam, lParam, TRUE };\r
m_Macro.push_back(m);\r
- m_bDown[wParam] |= !(lParam & BEING_RELEASED);\r
+ m_bDown[wParam] |= !bRelease;\r
}\r
- return CallNextHookEx(g_hHookKeyboard, nCode, wParam, lParam);\r
+ return CallNextHookEx(NULL, nCode, wParam, lParam);\r
\r
RECURSIVE:\r
Kdu(RECURSIVE_KEY, 1, FALSE);\r
goto HOOKX;\r
HOOK:\r
- CCommands::SetLastCommand(fCommand);\r
+ CCommands::SetLastCommand(fLastCommand);\r
HOOK0_9:\r
HOOKX:\r
SetModifierIcons();\r
\r
void CXkeymacsDll::SetModifierIcons()\r
{\r
-#define IconState(x) ((x) ? ON_ICON : OFF_ICON)\r
ICONMSG msg[6] = {\r
- {MX_ICON, IconState(CCommands::bM_x()), ""},\r
- {CX_ICON, IconState(CCommands::bC_x()), ""},\r
- {META_ICON, IconState(CCommands::bM_()), ""},\r
- {SHIFT_ICON, IconState(IsDown(VK_SHIFT, FALSE)), ""},\r
- {CTRL_ICON, IconState(IsControl()), ""},\r
- {ALT_ICON, IconState(IsDown(VK_MENU, FALSE)), ""}\r
+ {MX_ICON, CCommands::bM_x(), ""},\r
+ {CX_ICON, CCommands::bC_x(), ""},\r
+ {META_ICON, CCommands::bM_(), ""},\r
+ {SHIFT_ICON, IsDown(VK_SHIFT, FALSE), ""},\r
+ {CTRL_ICON, IsControl(), ""},\r
+ {ALT_ICON, IsDown(VK_MENU, FALSE), ""}\r
};\r
_tcscpy_s(msg[0].szTip, m_M_xTip);\r
SendIconMessage(msg, 6);\r
}\r
\r
-void CXkeymacsDll::SetApplicationName(int nApplicationID, CString szApplicationName)\r
-{\r
- ZeroMemory(m_Config.szSpecialApp[nApplicationID], CLASS_NAME_LENGTH);\r
- _tcsncpy_s(m_Config.szSpecialApp[nApplicationID], szApplicationName, _TRUNCATE);\r
-}\r
-\r
-void CXkeymacsDll::SetWindowText(int nApplicationID, CString szWindowText)\r
-{\r
- ZeroMemory(m_Config.szWindowText[nApplicationID], WINDOW_TEXT_LENGTH);\r
- _tcsncpy_s(m_Config.szWindowText[nApplicationID], szWindowText, _TRUNCATE);\r
-}\r
-\r
-void CXkeymacsDll::SetCommandID(int nApplicationID, int nCommandType, int nKey, int nCommandID)\r
+// Clear data of nAppID\r
+void CXkeymacsDll::Clear(int nAppID)\r
{\r
- m_Config.nCommandID[nApplicationID][nCommandType][nKey] = nCommandID;\r
-}\r
-\r
-void CXkeymacsDll::SetKillRingMax(int nApplicationID, int nKillRingMax)\r
-{\r
- m_Config.nKillRingMax[nApplicationID] = nKillRingMax;\r
-}\r
-\r
-void CXkeymacsDll::SetUseDialogSetting(int nApplicationID, BOOL bUseDialogSetting)\r
-{\r
- m_Config.bUseDialogSetting[nApplicationID] = bUseDialogSetting;\r
-}\r
-\r
-// Clear data of nApplicationID\r
-void CXkeymacsDll::Clear(int nApplicationID)\r
-{\r
- if (0 <= nApplicationID && nApplicationID < MAX_APP) {\r
- ZeroMemory(m_Config.szSpecialApp[nApplicationID], sizeof(m_Config.szSpecialApp[nApplicationID]));\r
- ZeroMemory(m_Config.nCommandID[nApplicationID], sizeof(m_Config.nCommandID[nApplicationID]));\r
- m_Config.nKillRingMax[nApplicationID] = 0;\r
- m_Config.bUseDialogSetting[nApplicationID] = FALSE;\r
- m_Config.nSettingStyle[nApplicationID] = 0;\r
+ if (0 <= nAppID && nAppID < MAX_APP) {\r
+ ZeroMemory(m_Config.szSpecialApp[nAppID], sizeof(m_Config.szSpecialApp[nAppID]));\r
+ ZeroMemory(m_Config.nCommandID[nAppID], sizeof(m_Config.nCommandID[nAppID]));\r
+ m_Config.nKillRingMax[nAppID] = 0;\r
+ m_Config.bUseDialogSetting[nAppID] = FALSE;\r
+ m_Config.nSettingStyle[nAppID] = 0;\r
} else {\r
ASSERT(0);\r
}\r
BYTE bVk = 0;\r
do {\r
if (IsValidKey(bVk) && IsDown(bVk, bPhysicalKey) &&\r
- Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == Modifier)\r
+ Commands[m_Config.nCommandID[m_nAppID][NONE][bVk]].fCommand == Modifier)\r
return TRUE;\r
} while (++bVk);\r
return FALSE;\r
}\r
\r
-BOOL CXkeymacsDll::IsDepressedShiftKeyOnly(BYTE nKey)\r
+void CXkeymacsDll::CancelMarkWithShift(BYTE nKey, bool bRelease)\r
{\r
- if (nKey != VK_SHIFT\r
- && nKey != VK_LSHIFT\r
- && nKey != VK_RSHIFT) {\r
- return FALSE;\r
- }\r
-\r
+ static bool bShift;\r
+ if (nKey != VK_SHIFT)\r
+ goto exit;\r
BYTE bVk = 0;\r
do {\r
- if (bVk == VK_SHIFT\r
- || bVk == VK_LSHIFT\r
- || bVk == VK_RSHIFT) {\r
+ if (bVk == VK_SHIFT || VK_LSHIFT || VK_RSHIFT)\r
continue;\r
- }\r
-\r
- if (IsDown(bVk, FALSE)) {\r
- return FALSE;\r
- }\r
+ if (IsDown(bVk, FALSE))\r
+ goto exit;\r
} while (++bVk);\r
- return TRUE;\r
+ if (!bRelease) {\r
+ bShift = TRUE;\r
+ return;\r
+ }\r
+ if (bShift)\r
+ CCommands::SetMark(FALSE);\r
+exit:\r
+ bShift = FALSE;\r
+ return;\r
}\r
\r
BOOL CXkeymacsDll::IsControl()\r
\r
void CXkeymacsDll::AddKillRing(BOOL bNewData)\r
{\r
- if (m_Config.nKillRingMax[m_nApplicationID] == 0) {\r
+ if (m_Config.nKillRingMax[m_nAppID] == 0) {\r
return;\r
}\r
\r
if (m_oKillRing.IsEmpty()) {\r
m_oKillRing.AddHead(pSnap);\r
} else {\r
- for (CClipboardSnap *pParent = m_oKillRing.GetHead(); pParent->GetNext(); pParent = pParent->GetNext()) {\r
+ CClipboardSnap *pParent;\r
+ for (pParent = m_oKillRing.GetHead(); pParent->GetNext(); pParent = pParent->GetNext()) {\r
;\r
}\r
pParent->SetNext(pSnap);\r
\r
m_nKillRing = 0;\r
\r
- if (m_Config.nKillRingMax[m_nApplicationID] < m_oKillRing.GetCount()) {\r
+ if (m_Config.nKillRingMax[m_nAppID] < m_oKillRing.GetCount()) {\r
CClipboardSnap *pSnap = m_oKillRing.GetTail();\r
delete pSnap;\r
pSnap = NULL;\r
// Return FALSE if there is no more data\r
CClipboardSnap* CXkeymacsDll::GetKillRing(CClipboardSnap* pSnap, BOOL bForce)\r
{\r
- if (m_Config.nKillRingMax[m_nApplicationID] == 0) {\r
+ if (m_Config.nKillRingMax[m_nAppID] == 0) {\r
return NULL;\r
}\r
\r
return pSnap->GetNext();\r
}\r
\r
-void CXkeymacsDll::SetOriginal(UINT nCommandType, BYTE bVk)\r
+void CXkeymacsDll::SetOriginal(UINT nType, BYTE bVk)\r
{\r
- m_nOriginal[nCommandType & ~SHIFT][bVk]++;\r
+ m_nOriginal[nType & ~SHIFT][bVk]++;\r
}\r
\r
-int CXkeymacsDll::CheckOriginal(UINT nCommandType, BYTE bVk)\r
+int CXkeymacsDll::CheckOriginal(UINT nType, BYTE bVk)\r
{\r
- nCommandType &= ~SHIFT;\r
- if (m_nOriginal[nCommandType][bVk])\r
- return m_nOriginal[nCommandType][bVk]--;\r
+ nType &= ~SHIFT;\r
+ if (m_nOriginal[nType][bVk])\r
+ return m_nOriginal[nType][bVk]--;\r
return 0;\r
}\r
\r
m_nKillRing += nKillRing;\r
}\r
\r
-void CXkeymacsDll::SetSettingStyle(int nApplicationID, int nSettingStyle)\r
-{\r
- m_Config.nSettingStyle[nApplicationID] = nSettingStyle;\r
-}\r
-\r
-void CXkeymacsDll::SetIgnoreUndefinedMetaCtrl(int nApplicationID, BOOL bIgnoreUndefinedMetaCtrl)\r
-{\r
- m_Config.bIgnoreUndefinedMetaCtrl[nApplicationID] = bIgnoreUndefinedMetaCtrl;\r
-}\r
-\r
-void CXkeymacsDll::SetIgnoreUndefinedC_x(int nApplicationID, BOOL bIgnoreUndefinedC_x)\r
-{\r
- m_Config.bIgnoreUndefinedC_x[nApplicationID] = bIgnoreUndefinedC_x;\r
-}\r
-\r
-void CXkeymacsDll::SetEnableCUA(int nApplicationID, BOOL bEnableCUA)\r
-{\r
- m_Config.bEnableCUA[nApplicationID] = bEnableCUA;\r
-}\r
-\r
BOOL CXkeymacsDll::GetEnableCUA()\r
{\r
- return m_Config.bEnableCUA[m_nApplicationID];\r
+ return m_Config.bEnableCUA[m_nAppID];\r
}\r
\r
void CXkeymacsDll::StartRecordMacro()\r
m_bRecordingMacro = FALSE;\r
while (!m_Macro.empty()) { // remove not released push\r
const KbdMacro& m = m_Macro.back();\r
- if (m.lParam & BEING_RELEASED)\r
+ if (HIWORD(m.lParam) & KF_UP)\r
break;\r
m_Macro.pop_back();\r
}\r
m_bRecordingMacro = FALSE;\r
UINT before = GetModifierState(FALSE);\r
SetModifierState(0, before);\r
- for (auto m = m_Macro.begin(); m != m_Macro.end(); m++)\r
- if (m->lParam & BEING_RELEASED)\r
+ for (std::list<KbdMacro>::const_iterator m = m_Macro.begin(); m != m_Macro.end(); ++m)\r
+ if (HIWORD(m->lParam) & KF_UP)\r
ReleaseKey(static_cast<BYTE>(m->wParam));\r
else\r
DepressKey(static_cast<BYTE>(m->wParam), m->bOriginal);\r
SetModifierState(before, 0);\r
}\r
\r
-void CXkeymacsDll::Set106Keyboard(BOOL b106Keyboard)\r
-{\r
- m_Config.b106Keyboard = b106Keyboard;\r
-}\r
-\r
BOOL CXkeymacsDll::Is106Keyboard()\r
{\r
return m_Config.b106Keyboard;\r
BYTE bVk = 0;\r
do {\r
if (IsDown(bVk)\r
- && (Commands[m_Config.nCommandID[m_nApplicationID][NONE][bVk]].fCommand == CCommands::PassThrough)) {\r
+ && (Commands[m_Config.nCommandID[m_nAppID][NONE][bVk]].fCommand == CCommands::PassThrough)) {\r
if (bVk == nKey) {\r
return GOTO_HOOK;\r
}\r
return CONTINUE;\r
}\r
\r
-void CXkeymacsDll::SetFunctionKey(int nFunctionID, int nApplicationID, int nCommandType, int nKey)\r
-{\r
- if (nApplicationID < 0 || MAX_APP <= nApplicationID\r
- || nCommandType < 0 || MAX_COMMAND_TYPE <= nCommandType\r
- || nKey < 0 || MAX_KEY <= nKey) {\r
- return;\r
- }\r
-\r
- m_Config.nFunctionID[nApplicationID][nCommandType][nKey] = nFunctionID;\r
-}\r
-\r
-void CXkeymacsDll::ClearFunctionDefinition()\r
-{\r
- memset(m_Config.nFunctionID, -1, sizeof(m_Config.nFunctionID));\r
- memset(m_Config.szFunctionDefinition, 0, sizeof(m_Config.szFunctionDefinition));\r
-}\r
-\r
-void CXkeymacsDll::SetFunctionDefinition(int nFunctionID, CString szDefinition)\r
-{\r
- if (nFunctionID < 0 || nFunctionID >= MAX_FUNCTION)\r
- return;\r
- memset(m_Config.szFunctionDefinition[nFunctionID], 0, sizeof(m_Config.szFunctionDefinition[nFunctionID]));\r
- _tcscpy_s(m_Config.szFunctionDefinition[nFunctionID], szDefinition);\r
- return;\r
-}\r
-\r
// call an original command which is defined in dot.xkeymacs\r
-void CXkeymacsDll::CallFunction(int nFunctionID)\r
+void CXkeymacsDll::CallFunction(int nFuncID)\r
{\r
- if (nFunctionID < 0 || nFunctionID >= MAX_FUNCTION)\r
+ if (nFuncID < 0 || nFuncID >= MAX_FUNCTION)\r
return;\r
- LPCTSTR def = m_Config.szFunctionDefinition[nFunctionID];\r
+ LPCTSTR def = m_Config.szFunctionDefinition[nFuncID];\r
if (!def[0])\r
return;\r
std::vector<KeyBind> keybinds;\r
const LPCTSTR last = def + _tcslen(def) - 1;\r
if (*def == _T('"') && *last == _T('"')) {\r
- def++; // skip '"'\r
+ ++def; // skip '"'\r
while (def < last)\r
keybinds.push_back(ParseKey(def));\r
} else if (*def == _T('[') && *last == _T(']')) {\r
continue;\r
}\r
// [VK]\r
- for (int i = 0; i < MAX_KEYNAME; i++) {\r
+ for (int i = 0; i < MAX_KEYNAME; ++i) {\r
size_t keylen = _tcslen(KeyNames[i].name);\r
if (!_tcsncmp(def, KeyNames[i].name, keylen)) {\r
KeyBind keybind = {NONE, KeyNames[i].bVk};\r
BOOL bInitialized = FALSE;\r
UINT before = GetModifierState(FALSE);\r
\r
- for (auto p = keybinds.begin(); p != keybinds.end(); p++) {\r
- const int nCommandType = p->nCommandType;\r
+ for (std::vector<KeyBind>::const_iterator p = keybinds.begin(); p != keybinds.end(); ++p) {\r
+ const int nType = p->nType;\r
const BYTE bVk = p->bVk;\r
- int (*fCommand)() = nCommandType < MAX_COMMAND_TYPE ? Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].fCommand : NULL;\r
+ int (*fCommand)() = nType < MAX_COMMAND_TYPE ? Commands[m_Config.nCommandID[m_nAppID][nType][bVk]].fCommand : NULL;\r
if (fCommand) {\r
if (fCommand == CCommands::ExecuteExtendedCommand)\r
bM_x = TRUE;\r
SetModifierState(0, before);\r
bInitialized = TRUE;\r
}\r
-// CUtils::Log("CallFunction: Command Name: %s", Commands[m_Config.nCommandID[m_nApplicationID][nCommandType][bVk]].szCommandName);\r
+// CUtils::Log("CallFunction: Command Name: %s", Commands[m_Config.nCommandID[m_nAppID][nType][bVk]].szCommandName);\r
while (fCommand() == GOTO_RECURSIVE)\r
;\r
continue;\r
else if (bVk != 0) {\r
TCHAR nAscii = 0;\r
do { // 1-127\r
- if (a2v(++nAscii) == bVk && ((nCommandType & SHIFT) != 0) == IsShift(nAscii)) {\r
+ if (a2v(++nAscii) == bVk && ((nType & SHIFT) != 0) == IsShift(nAscii)) {\r
// CUtils::Log("M-x: %#X (%c), %#X (%c)", bVk, bVk, nAscii, nAscii);\r
szPath[index++] = nAscii;\r
break;\r
SetModifierState(0, before);\r
bInitialized = TRUE;\r
}\r
- if (nCommandType & WIN_WIN)\r
+ if (nType & WIN_WIN)\r
DepressKey(VK_LWIN);\r
- if (nCommandType & WIN_CTRL)\r
+ if (nType & WIN_CTRL)\r
DepressKey(VK_CONTROL);\r
- if (nCommandType & WIN_ALT)\r
+ if (nType & WIN_ALT)\r
DepressKey(VK_MENU);\r
- if (nCommandType & SHIFT)\r
+ if (nType & SHIFT)\r
DepressKey(VK_SHIFT);\r
Kdu(bVk);\r
- const int nNextType = (p + 1) != keybinds.end() ? (p + 1)->nCommandType : 0;\r
- if (nCommandType & SHIFT && !(nNextType & SHIFT))\r
+ const int nNextType = (p + 1) != keybinds.end() ? (p + 1)->nType : 0;\r
+ if (nType & SHIFT && !(nNextType & SHIFT))\r
ReleaseKey(VK_SHIFT);\r
- if (nCommandType & WIN_ALT && !(nNextType & WIN_ALT))\r
+ if (nType & WIN_ALT && !(nNextType & WIN_ALT))\r
ReleaseKey(VK_MENU);\r
- if (nCommandType & WIN_CTRL && !(nNextType & WIN_CTRL))\r
+ if (nType & WIN_CTRL && !(nNextType & WIN_CTRL))\r
ReleaseKey(VK_CONTROL);\r
- if (nCommandType & WIN_WIN && !(nNextType & WIN_WIN))\r
+ if (nType & WIN_WIN && !(nNextType & WIN_WIN))\r
ReleaseKey(VK_LWIN);\r
}\r
\r
{\r
KeyBind keybind = {NONE};\r
if (*def == _T('\\')) { // set modifiers\r
- def++;\r
+ ++def;\r
LOOP:\r
- for (int i = 0; i < MAX_MODIFIER; i++) {\r
+ for (int i = 0; i < MAX_MODIFIER; ++i) {\r
size_t len = _tcslen(Modifiers[i].name);\r
if (!_tcsncmp(def, Modifiers[i].name, len)) {\r
- keybind.nCommandType |= Modifiers[i].id;\r
+ keybind.nType |= Modifiers[i].id;\r
def += len;\r
goto LOOP;\r
}\r
}\r
}\r
- if (IsShift(*def) && !(keybind.nCommandType & (WIN_CTRL | WIN_ALT | WIN_WIN)))\r
- keybind.nCommandType |= SHIFT;\r
+ if (IsShift(*def) && !(keybind.nType & (WIN_CTRL | WIN_ALT | WIN_WIN)))\r
+ keybind.nType |= SHIFT;\r
int i = 0;\r
- for (; i < MAX_KEYNAME; i++) {\r
+ for (; i < MAX_KEYNAME; ++i) {\r
size_t len = _tcslen(KeyNames[i].name);\r
if (!_tcsncmp(def, KeyNames[i].name, len)) {\r
def += len;\r
}\r
}\r
\r
-void CXkeymacsDll::Set326Compatible(int nApplicationID, BOOL b326Compatible)\r
-{\r
- m_Config.b326Compatible[nApplicationID] = b326Compatible;\r
-}\r
-\r
BOOL CXkeymacsDll::Get326Compatible()\r
{\r
- return m_Config.b326Compatible[m_nApplicationID];\r
+ return m_Config.b326Compatible[m_nAppID];\r
}\r
\r
void CXkeymacsDll::InvokeM_x(const TCHAR *const szPath)\r