Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

refactor(infra): rename `KbLLHookStruct` -> `LowLevelKeyboardInputEvent` and improve related comments

Lars Berger03ac508ada31
diff --git a/LarsWM.Domain/Common/Services/KeybindingService.cs b/LarsWM.Domain/Common/Services/KeybindingService.cs
index 90174625..85926898 100644
--- a/LarsWM.Domain/Common/Services/KeybindingService.cs
+++ b/LarsWM.Domain/Common/Services/KeybindingService.cs
@@ -38,7 +38,6 @@ namespace LarsWM.Domain.Common.Services
var thread = new Thread(() =>
{
SetWindowsHookEx(HookType.WH_KEYBOARD_LL, KbHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);
- //SetWindowsHookEx(HookType.WH_MOUSE_LL, _mouseHook, Process.GetCurrentProcess().MainModule.BaseAddress, 0);
Application.Run();
});
thread.Name = "LarsWMKeybindingService";
@@ -63,10 +62,13 @@ namespace LarsWM.Domain.Common.Services
if (modifiersPressed.Count() == 0)
return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
- // Get structure with details about keyboard input event.
- var hookStruct = (KbLLHookStruct)Marshal.PtrToStructure(lParam, typeof(KbLLHookStruct));
+ // Get struct with details about keyboard input event.
+ var rawEventStruct = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent));
+ var inputEvent = (LowLevelKeyboardInputEvent)rawEventStruct;
- _modKeypresses.OnNext(hookStruct.vkCode);
+ _modKeypresses.OnNext(inputEvent.Key);
+
+ // Avoid forwarding the key input to other applications.
return new IntPtr(1);
}
diff --git a/LarsWM.Infrastructure/WindowsApi/WindowsApiService.cs b/LarsWM.Infrastructure/WindowsApi/WindowsApiService.cs
index 0d505205..8deefe2f 100644
--- a/LarsWM.Infrastructure/WindowsApi/WindowsApiService.cs
+++ b/LarsWM.Infrastructure/WindowsApi/WindowsApiService.cs
@@ -211,13 +211,37 @@ namespace LarsWM.Infrastructure.WindowsApi
/// Contains information about a low-level keyboard input event.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
- public class KbLLHookStruct
+ public struct LowLevelKeyboardInputEvent
{
- public Keys vkCode;
- public int scanCode;
- public int flags;
- public int time;
- public int dwExtraInfo;
+ /// <summary>
+ /// A virtual-key code. The code must be a value in the range 1 to 254.
+ /// </summary>
+ public int VirtualCode;
+
+ /// <summary>
+ /// The `VirtualCode` converted to `Keys` for better usability.
+ /// </summary>
+ public Keys Key { get { return (Keys)VirtualCode; } }
+
+ /// <summary>
+ /// A hardware scan code for the key.
+ /// </summary>
+ public int HardwareScanCode;
+
+ /// <summary>
+ /// The extended-key flag, event-injected Flags, context code, and transition-state flag. This member is specified as follows. An application can use the following values to test the keystroke Flags. Testing LLKHF_INJECTED (bit 4) will tell you whether the event was injected. If it was, then testing LLKHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not the event was injected from a process running at lower integrity level.
+ /// </summary>
+ public int Flags;
+
+ /// <summary>
+ /// The time stamp stamp for this message, equivalent to what GetMessageTime would return for this message.
+ /// </summary>
+ public int TimeStamp;
+
+ /// <summary>
+ /// Additional information associated with the message.
+ /// </summary>
+ public IntPtr AdditionalInformation;
}
[DllImport("user32.dll")]