aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/platform/MSWindowsHook.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/platform/MSWindowsHook.cpp')
-rw-r--r--src/lib/platform/MSWindowsHook.cpp66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/lib/platform/MSWindowsHook.cpp b/src/lib/platform/MSWindowsHook.cpp
index b9b9740..3230d24 100644
--- a/src/lib/platform/MSWindowsHook.cpp
+++ b/src/lib/platform/MSWindowsHook.cpp
@@ -3,11 +3,11 @@
* Copyright (C) 2018 Debauchee Open Source Group
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2011 Chris Schoeneman
- *
+ *
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
- *
+ *
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -56,14 +56,13 @@ static BYTE g_deadKeyState[256] = { 0 };
static BYTE g_keyState[256] = { 0 };
static bool g_fakeServerInput = false;
static std::vector<DWORD> g_immuneKeys;
-
-static const std::string ImmuneKeysPath = DataDirectories::profile() + "\\ImmuneKeys.txt";
+static std::string g_immuneKeysPath;
static std::vector<DWORD> immune_keys_list()
{
std::vector<DWORD> keys;
std::string badLine;
- if (!ImmuneKeysReader::get_list(ImmuneKeysPath.c_str(), keys, badLine))
+ if (!ImmuneKeysReader::get_list(g_immuneKeysPath.c_str(), keys, badLine))
LOG((CLOG_ERR "Reading immune keys stopped at: %s", badLine.c_str()));
return keys;
}
@@ -144,9 +143,9 @@ keyboardGetState(BYTE keys[256], DWORD vkCode, bool kf_up)
static
WPARAM
-makeKeyMsg(UINT virtKey, char c, bool noAltGr)
+makeKeyMsg(UINT virtKey, WCHAR wc, bool noAltGr)
{
- return MAKEWPARAM(MAKEWORD(virtKey & 0xff, (BYTE)c), noAltGr ? 1 : 0);
+ return MAKEWPARAM((WORD)wc, MAKEWORD(virtKey & 0xff, noAltGr ? 1 : 0));
}
static
@@ -193,7 +192,7 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
(lParam & 0x80000000u) != 0) {
g_deadRelease = 0;
PostThreadMessage(g_threadID, BARRIER_MSG_DEBUG,
- wParam | 0x04000000, lParam);
+ wParam | 0x40000000, lParam);
return false;
}
@@ -245,19 +244,19 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
}
}
- WORD c = 0;
+ WCHAR wc[2] = { 0, 0 };
// map the key event to a character. we have to put the dead
// key back first and this has the side effect of removing it.
if (g_deadVirtKey != 0) {
- if (ToAscii((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
- g_deadKeyState, &c, flags) == 2) {
- // If ToAscii returned 2, it means that we accidentally removed
+ if (ToUnicode((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
+ g_deadKeyState, wc, 2, flags) == 2) {
+ // If ToUnicode returned 2, it means that we accidentally removed
// a double dead key instead of restoring it. Thus, we call
- // ToAscii again with the same parameters to restore the
+ // ToUnicode again with the same parameters to restore the
// internal dead key state.
- ToAscii((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
- g_deadKeyState, &c, flags);
+ ToUnicode((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
+ g_deadKeyState, wc, 2, flags);
// We need to keep track of this because g_deadVirtKey will be
// cleared later on; this would cause the dead key release to
@@ -267,7 +266,7 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
}
UINT scanCode = ((lParam & 0x10ff0000u) >> 16);
- int n = ToAscii((UINT)wParam, scanCode, keys, &c, flags);
+ int n = ToUnicode((UINT)wParam, scanCode, keys, wc, 2, flags);
// if mapping failed and ctrl and alt are pressed then try again
// with both not pressed. this handles the case where ctrl and
@@ -279,12 +278,12 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
if (n == 0 && (control & 0x80) != 0 && (menu & 0x80) != 0) {
noAltGr = true;
PostThreadMessage(g_threadID, BARRIER_MSG_DEBUG,
- wParam | 0x05000000, lParam);
+ wParam | 0x50000000, lParam);
if (g_deadVirtKey != 0) {
- if (ToAscii((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
- g_deadKeyState, &c, flags) == 2) {
- ToAscii((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
- g_deadKeyState, &c, flags);
+ if (ToUnicode((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
+ g_deadKeyState, wc, 2, flags) == 2) {
+ ToUnicode((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
+ g_deadKeyState, wc, 2, flags);
g_deadRelease = g_deadVirtKey;
}
}
@@ -298,12 +297,12 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
keys2[VK_LMENU] = 0;
keys2[VK_RMENU] = 0;
keys2[VK_MENU] = 0;
- n = ToAscii((UINT)wParam, scanCode, keys2, &c, flags);
+ n = ToUnicode((UINT)wParam, scanCode, keys2, wc, 2, flags);
}
PostThreadMessage(g_threadID, BARRIER_MSG_DEBUG,
- wParam | ((c & 0xff) << 8) |
- ((n & 0xff) << 16) | 0x06000000,
+ (wc[0] & 0xffff) | ((wParam & 0xff) << 16) |
+ ((n & 0xf) << 24) | 0x60000000,
lParam);
WPARAM charAndVirtKey = 0;
bool clearDeadKey = false;
@@ -329,12 +328,12 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
case 0:
// key doesn't map to a character. this can happen if
// non-character keys are pressed after a dead key.
- charAndVirtKey = makeKeyMsg((UINT)wParam, (char)0, noAltGr);
+ charAndVirtKey = makeKeyMsg((UINT)wParam, (WCHAR)0, noAltGr);
break;
case 1:
// key maps to a character composed with dead key
- charAndVirtKey = makeKeyMsg((UINT)wParam, (char)LOBYTE(c), noAltGr);
+ charAndVirtKey = makeKeyMsg((UINT)wParam, wc[0], noAltGr);
clearDeadKey = true;
break;
@@ -342,14 +341,14 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
// previous dead key not composed. send a fake key press
// and release for the dead key to our window.
WPARAM deadCharAndVirtKey =
- makeKeyMsg((UINT)g_deadVirtKey, (char)LOBYTE(c), noAltGr);
+ makeKeyMsg((UINT)g_deadVirtKey, wc[0], noAltGr);
PostThreadMessage(g_threadID, BARRIER_MSG_KEY,
deadCharAndVirtKey, g_deadLParam & 0x7fffffffu);
PostThreadMessage(g_threadID, BARRIER_MSG_KEY,
deadCharAndVirtKey, g_deadLParam | 0x80000000u);
// use uncomposed character
- charAndVirtKey = makeKeyMsg((UINT)wParam, (char)HIBYTE(c), noAltGr);
+ charAndVirtKey = makeKeyMsg((UINT)wParam, wc[1], noAltGr);
clearDeadKey = true;
break;
}
@@ -357,8 +356,8 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
// put back the dead key, if any, for the application to use
if (g_deadVirtKey != 0) {
- ToAscii((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
- g_deadKeyState, &c, flags);
+ ToUnicode((UINT)g_deadVirtKey, (g_deadLParam & 0x10ff0000u) >> 16,
+ g_deadKeyState, wc, 2, flags);
}
// clear out old dead key state
@@ -375,7 +374,7 @@ keyboardHookHandler(WPARAM wParam, LPARAM lParam)
// forwarding.
if (charAndVirtKey != 0) {
PostThreadMessage(g_threadID, BARRIER_MSG_DEBUG,
- charAndVirtKey | 0x07000000, lParam);
+ charAndVirtKey | 0x70000000, lParam);
PostThreadMessage(g_threadID, BARRIER_MSG_KEY, charAndVirtKey, lParam);
}
@@ -575,8 +574,9 @@ MSWindowsHook::install()
g_fakeServerInput = false;
// setup immune keys
+ g_immuneKeysPath = (barrier::DataDirectories::profile() / "ImmuneKeys.txt").u8string();
g_immuneKeys = immune_keys_list();
- LOG((CLOG_DEBUG "Found %u immune keys in %s", g_immuneKeys.size(), ImmuneKeysPath.c_str()));
+ LOG((CLOG_DEBUG "Found %u immune keys in %s", g_immuneKeys.size(), g_immuneKeysPath.c_str()));
#if NO_GRAB_KEYBOARD
// we only need the mouse hook
@@ -638,4 +638,4 @@ void
MSWindowsHook::uninstallScreenSaver()
{
g_hkMessage.unset();
-} \ No newline at end of file
+}