Skip to content

Commit 5810fbc

Browse files
authored
[Win32+SharpHook] Keyboard layout bugfix (#209)
1 parent 2d71ebe commit 5810fbc

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
GetForegroundWindow
12
GetKeyState
23
GetKeyboardState
34
GetKeyboardLayout
4-
ToUnicodeEx
5+
GetKeyboardLayoutNameW
6+
GetWindowThreadProcessId
57
MapVirtualKey
8+
ToUnicodeEx
69
VIRTUAL_KEY

src/20-Services/Wtq.Services.SharpHook/SharpHookHotkeyService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ protected override Task OnStartAsync(CancellationToken cancellationToken)
8383
// Turn key code into sequence.
8484
var keySeq = _keyService.GetKeySequence(keyCode, e.Data.RawCode);
8585

86+
_log.LogDebug("Got key sequence '{Sequence}'", keySeq);
87+
8688
// Look for a registered hotkey matching the one just pressed.
8789
var hk = GetHotkeys().FirstOrDefault(h => h.Sequence == keySeq);
8890
if (hk == null)

src/20-Services/Wtq.Services.SharpHook/Win32.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ public bool IsSuperPressed() =>
5555
wFlags: 0,
5656
dwhkl: layout);
5757

58-
// The result of ToUnicodeEx should be greater than 0 if it succeeded.
59-
if (length <= 0)
60-
{
61-
return null;
62-
}
63-
64-
// Pull the relevant part out of the buffer (as specified by the returned "length").
65-
var result = buffer[..length].ToString();
58+
var result = buffer.ToString().Trim('\0').Trim();
6659

6760
// The result could still be empty, e.g. for the "Tab" character, which returns \t.
6861
if (string.IsNullOrWhiteSpace(result))

0 commit comments

Comments
 (0)