private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) { WinFormsKeys virtualKey; switch (msg) { case Win32Native.WM_KEYDOWN: case Win32Native.WM_SYSKEYDOWN: virtualKey = (WinFormsKeys)wParam.ToInt64(); virtualKey = GetCorrectExtendedKey(virtualKey, lParam.ToInt64()); keyboard?.HandleKeyDown(virtualKey); heldKeys.Add(virtualKey); break; case Win32Native.WM_KEYUP: case Win32Native.WM_SYSKEYUP: virtualKey = (WinFormsKeys)wParam.ToInt64(); virtualKey = GetCorrectExtendedKey(virtualKey, lParam.ToInt64()); heldKeys.Remove(virtualKey); keyboard?.HandleKeyUp(virtualKey); break; case Win32Native.WM_DEVICECHANGE: // Trigger scan on device changed input.Scan(); break; } var result = Win32Native.CallWindowProc(defaultWndProc, hWnd, msg, wParam, lParam); return(result); }
internal void HandleKeyDown(IntPtr wParam, IntPtr lParam) { var virtualKey = (WinFormsKeys)wParam.ToInt64(); virtualKey = GetCorrectExtendedKey(virtualKey, lParam.ToInt64()); keyboard?.HandleKeyDown(virtualKey); heldKeys.Add(virtualKey); }