From 812a59c6454b0b5eda564857228ec4a503c2fdd5 Mon Sep 17 00:00:00 2001 From: Nadromar Date: Sat, 30 Mar 2019 08:08:44 +0100 Subject: [PATCH] #53 Attempted fix for hotkey register/unregister flood - Change default hotkey for new configs to F4 Since F1-F3 might be boundto fold/checkcall/betraise by default (which also happens to be the only option for default bwin client) --- MultiTablePro/Data/Config.cs | 2 +- MultiTablePro/HotKeyHandler.cs | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/MultiTablePro/Data/Config.cs b/MultiTablePro/Data/Config.cs index dbe6010..306917c 100644 --- a/MultiTablePro/Data/Config.cs +++ b/MultiTablePro/Data/Config.cs @@ -38,7 +38,7 @@ internal Config() private int _autoLeaveVpip = 15; private int _autoLeaveHands = 20; private bool _preferSpreadOverStack = true; - private HotKey _asideHotkey = new HotKey(System.Windows.Forms.Keys.T); + private HotKey _asideHotkey = new HotKey(System.Windows.Forms.Keys.F4); private int _tableMovementDelay = 50; private bool _bwinSupportEnabled = false; diff --git a/MultiTablePro/HotKeyHandler.cs b/MultiTablePro/HotKeyHandler.cs index e93db1d..a8f10f5 100644 --- a/MultiTablePro/HotKeyHandler.cs +++ b/MultiTablePro/HotKeyHandler.cs @@ -33,27 +33,26 @@ internal class HotKeyHandler public const int WM_HOTKEY = 0x0312; // Definition for hotkey MSG private static Dictionary idMemory = new Dictionary(); - private static int _lastRegisterId = -1; + private static int _lastRegisterId = 0; + private static bool _handlingKeyPress = false; private static int LastRegisterId { - get - { - // Not sure if starting at 0 is the best idea for hooking into external applications. - // Starting at a unique value instead (our MainWindowHandle) - if (_lastRegisterId == -1) - _lastRegisterId = Process.GetCurrentProcess().MainWindowHandle.ToInt32(); - return _lastRegisterId; - } + get { return _lastRegisterId; } set { _lastRegisterId = value; } } private static IntPtr OurWindowHandle { get; set; } internal static void HotkeyPressed(ref MSG m, ref bool handled) { - if (m.message != WM_HOTKEY) + // Only accept hotkey messages + if (m.message != WM_HOTKEY || _handlingKeyPress) return; + // Indicate that we're currently processing a HotKeyPressed event & lock it + // Hopefully prevents unknown flooding issue #53 + _handlingKeyPress = true; + // Find the targeted table, if any Table table = FindTableUnderMouse(); bool wasRelevant = table == null || table.IsVirtual ? false : true; @@ -78,6 +77,9 @@ internal static void HotkeyPressed(ref MSG m, ref bool handled) RegisterHotKey(foundHotkey, OurWindowHandle); } } + + // Unlock the event handler + _handlingKeyPress = false; } public static void RegisterHotKey(HotKey hotKey, IntPtr windowHandle)