Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Commit

Permalink
#53 Attempted fix for hotkey register/unregister flood
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
Nadromar committed Mar 30, 2019
1 parent c644686 commit 812a59c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MultiTablePro/Data/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 12 additions & 10 deletions MultiTablePro/HotKeyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,26 @@ internal class HotKeyHandler

public const int WM_HOTKEY = 0x0312; // Definition for hotkey MSG
private static Dictionary<int, HotKey> idMemory = new Dictionary<int, HotKey>();
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;
Expand All @@ -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)
Expand Down

0 comments on commit 812a59c

Please sign in to comment.