From 98c61d65104c90f6850638e5ad18da3dfc46d93a Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 11 May 2025 12:20:23 +0100 Subject: [PATCH 1/3] Replace `GetKeyboardState` --- src/Files.App.CsWin32/NativeMethods.txt | 1 + src/Files.App/Data/Commands/HotKey/HotKey.cs | 3 ++- src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs | 5 ----- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt index aee2e82f99b3..f70799104ba3 100644 --- a/src/Files.App.CsWin32/NativeMethods.txt +++ b/src/Files.App.CsWin32/NativeMethods.txt @@ -226,3 +226,4 @@ _SICHINTF RoGetAgileReference IQueryInfo QITIPF_FLAGS +GetKeyboardState diff --git a/src/Files.App/Data/Commands/HotKey/HotKey.cs b/src/Files.App/Data/Commands/HotKey/HotKey.cs index 215203aadb6a..dad388a03cc0 100644 --- a/src/Files.App/Data/Commands/HotKey/HotKey.cs +++ b/src/Files.App/Data/Commands/HotKey/HotKey.cs @@ -4,6 +4,7 @@ using System.Collections.Frozen; using System.Runtime.InteropServices; using System.Text; +using Windows.Win32; using Forms = System.Windows.Forms; namespace Files.App.Data.Commands @@ -374,7 +375,7 @@ private static string GetKeyCharacter(Forms.Keys key) var state = new byte[256]; // Get the current keyboard state - if (!Win32PInvoke.GetKeyboardState(state)) + if (!PInvoke.GetKeyboardState(state)) return buffer.ToString(); // Convert the key to its virtual key code diff --git a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs index 9af7345111ec..bf02537cc2a1 100644 --- a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs +++ b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs @@ -228,11 +228,6 @@ public static extern int ToUnicodeEx( IntPtr keyboardLayout ); - [DllImport("user32.dll")] - public static extern bool GetKeyboardState( - byte[] lpKeyState - ); - [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr GetKeyboardLayout ( From d5d0dbc66fbd055aba5e3cabec27c4cda7e9763b Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 11 May 2025 13:00:23 +0100 Subject: [PATCH 2/3] Replace `MapVirtualKey` --- src/Files.App.CsWin32/NativeMethods.txt | 1 + src/Files.App/Data/Commands/HotKey/HotKey.cs | 2 +- src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt index f70799104ba3..598ed2808dd3 100644 --- a/src/Files.App.CsWin32/NativeMethods.txt +++ b/src/Files.App.CsWin32/NativeMethods.txt @@ -227,3 +227,4 @@ RoGetAgileReference IQueryInfo QITIPF_FLAGS GetKeyboardState +MapVirtualKey diff --git a/src/Files.App/Data/Commands/HotKey/HotKey.cs b/src/Files.App/Data/Commands/HotKey/HotKey.cs index dad388a03cc0..11e991e2c6be 100644 --- a/src/Files.App/Data/Commands/HotKey/HotKey.cs +++ b/src/Files.App/Data/Commands/HotKey/HotKey.cs @@ -382,7 +382,7 @@ private static string GetKeyCharacter(Forms.Keys key) var virtualKey = (uint)key; // Map the virtual key to a scan code - var scanCode = Win32PInvoke.MapVirtualKey(virtualKey, 0); + var scanCode = PInvoke.MapVirtualKey(virtualKey, 0); // Get the active keyboard layout var keyboardLayout = Win32PInvoke.GetKeyboardLayout(0); diff --git a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs index bf02537cc2a1..e14b8b69ebba 100644 --- a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs +++ b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs @@ -234,12 +234,6 @@ public static extern IntPtr GetKeyboardLayout uint idThread ); - [DllImport("user32.dll")] - public static extern uint MapVirtualKey( - uint code, - uint mapType - ); - [DllImport("user32.dll")] public static extern bool TranslateMessage( ref MSG lpMsg From 44f03e8decf19dbff4a68b6305ef031a6dac877a Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sun, 11 May 2025 13:09:44 +0100 Subject: [PATCH 3/3] Replace `GetKeyboardLayout` --- src/Files.App.CsWin32/NativeMethods.txt | 1 + src/Files.App/Data/Commands/HotKey/HotKey.cs | 2 +- src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt index 598ed2808dd3..9d43788449e8 100644 --- a/src/Files.App.CsWin32/NativeMethods.txt +++ b/src/Files.App.CsWin32/NativeMethods.txt @@ -228,3 +228,4 @@ IQueryInfo QITIPF_FLAGS GetKeyboardState MapVirtualKey +GetKeyboardLayout diff --git a/src/Files.App/Data/Commands/HotKey/HotKey.cs b/src/Files.App/Data/Commands/HotKey/HotKey.cs index 11e991e2c6be..4c710e3d783d 100644 --- a/src/Files.App/Data/Commands/HotKey/HotKey.cs +++ b/src/Files.App/Data/Commands/HotKey/HotKey.cs @@ -385,7 +385,7 @@ private static string GetKeyCharacter(Forms.Keys key) var scanCode = PInvoke.MapVirtualKey(virtualKey, 0); // Get the active keyboard layout - var keyboardLayout = Win32PInvoke.GetKeyboardLayout(0); + var keyboardLayout = PInvoke.GetKeyboardLayout(0); if (Win32PInvoke.ToUnicodeEx(virtualKey, scanCode, state, buffer, buffer.Capacity, 0, keyboardLayout) > 0) return buffer[^1].ToString(); diff --git a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs index e14b8b69ebba..5e3c2155a86d 100644 --- a/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs +++ b/src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs @@ -228,12 +228,6 @@ public static extern int ToUnicodeEx( IntPtr keyboardLayout ); - [DllImport("user32.dll", CharSet = CharSet.Auto)] - public static extern IntPtr GetKeyboardLayout - ( - uint idThread - ); - [DllImport("user32.dll")] public static extern bool TranslateMessage( ref MSG lpMsg