From ceaa8c411077fcac94f6e6f72bf1c9a9158f8197 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sat, 3 Aug 2024 12:08:16 +0200 Subject: [PATCH] Hotkeys with 4-key combos https://github.com/seerge/g-helper/issues/2916 --- app/Input/InputDispatcher.cs | 3 +++ app/Input/KeyboardHook.cs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index ea9a0b52..80c4a777 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -218,6 +218,9 @@ namespace GHelper.Input case 3: KeyboardHook.KeyKeyKeyPress((Keys)hexKeys[0], (Keys)hexKeys[1], (Keys)hexKeys[2]); break; + case 4: + KeyboardHook.KeyKeyKeyKeyPress((Keys)hexKeys[0], (Keys)hexKeys[1], (Keys)hexKeys[2], (Keys)hexKeys[3]); + break; default: LaunchProcess(command); break; diff --git a/app/Input/KeyboardHook.cs b/app/Input/KeyboardHook.cs index 8e4ea9ef..c879a924 100644 --- a/app/Input/KeyboardHook.cs +++ b/app/Input/KeyboardHook.cs @@ -77,6 +77,21 @@ public sealed class KeyboardHook : IDisposable keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); } + public static void KeyKeyKeyKeyPress(Keys key, Keys key2, Keys key3, Keys key4, int sleep = 1) + { + keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); + keybd_event((byte)key2, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); + keybd_event((byte)key3, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); + keybd_event((byte)key4, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); + + Thread.Sleep(sleep); + + keybd_event((byte)key4, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); + keybd_event((byte)key3, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); + keybd_event((byte)key2, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); + keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); + } + /// /// Represents the window that is used internally to get the messages. ///