Skip to content

Commit 14e26a7

Browse files
committed
special temporary all-input-block hotkey option
1 parent 4021f82 commit 14e26a7

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

KeyboardChatterBlocker/AcceleratedKeyMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace KeyboardChatterBlocker
99
{
1010
/// <summary>
11-
/// Represents essentially a Dictionary[Key, T] with a special case for low range keys.
11+
/// Represents essentially a Dictionary[<see cref="Keys"/>, <typeparamref name="T"/>] with a special case for low range keys.
1212
/// </summary>
1313
/// <typeparam name="T">The type of value in the Dictionary.</typeparam>
1414
public class AcceleratedKeyMap<T>
@@ -24,7 +24,7 @@ public class AcceleratedKeyMap<T>
2424
public Dictionary<Keys, T> MainDictionary = new Dictionary<Keys, T>(1024);
2525

2626
/// <summary>
27-
/// Get or set a key-to-T mapping.
27+
/// Get or set a key-to-<typeparamref name="T"/> mapping.
2828
/// </summary>
2929
/// <param name="key">The key index.</param>
3030
public T this[Keys key]

KeyboardChatterBlocker/KeyBlocker.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ public void ApplyConfigSetting(string setting)
165165
case "measure_from":
166166
MeasureMode = (MeasureFrom)Enum.Parse(typeof(MeasureFrom), settingValue, true);
167167
break;
168+
case "hotkey_tempblock":
169+
BlockAllInputsKeySet = settingValue.Split('+').Select(s => s.Trim().ToLowerInvariant()).Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => (Keys)Enum.Parse(typeof(Keys), s, true)).ToArray();
170+
break;
168171
}
169172
}
170173

@@ -211,9 +214,23 @@ public string GetConfigurationString()
211214
{
212215
result.Append($"hotkey_{pair.Key}: {pair.Value}\n");
213216
}
217+
if (BlockAllInputsKeySet != null)
218+
{
219+
result.Append($"hotkey_tempblock: {string.Join(" + ", BlockAllInputsKeySet)}\n");
220+
}
214221
return result.ToString();
215222
}
216223

224+
/// <summary>
225+
/// A special set of keys that when pressed together will block all other key or mouse inputs until released.
226+
/// </summary>
227+
public Keys[] BlockAllInputsKeySet = null;
228+
229+
/// <summary>
230+
/// Whether ALL key inputs should be temporarily blocked.
231+
/// </summary>
232+
public bool ShouldBlockAll => BlockAllInputsKeySet != null && BlockAllInputsKeySet.Length > 0 && BlockAllInputsKeySet.All(k => KeyIsDown[k]);
233+
217234
/// <summary>
218235
/// Event for when a key is blocked.
219236
/// </summary>
@@ -310,6 +327,10 @@ public bool AllowKeyDown(Keys key, bool defaultZero)
310327
StatsKeyCount[key]++;
311328
ulong timeNow = GetTickCount64();
312329
ulong timeLast = MeasureMode == MeasureFrom.Release ? KeysToLastReleaseTime[key] : KeysToLastPressTime[key];
330+
if (ShouldBlockAll)
331+
{
332+
return false;
333+
}
313334
if (timeLast > timeNow) // In the future = number handling mixup, just allow it.
314335
{
315336
KeysToLastPressTime[key] = timeNow;
@@ -348,6 +369,10 @@ public bool AllowKeyUp(Keys key)
348369
return true;
349370
}
350371
KeyIsDown[key] = false;
372+
if (ShouldBlockAll)
373+
{
374+
return false;
375+
}
351376
if (!KeysWereDownBlocked[key]) // Down wasn't blocked = allow it.
352377
{
353378
KeysToLastReleaseTime[key] = timeNow;

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ I've taken a similar approach to the software solutions mentioned above, but wit
7272
- `keys.<KEY>`: (for example, `keys.H`) set to the time (in ms) for that specific key's keyboard chatter threshold.
7373
- `auto_disable_programs`: Set to a list of executable names (case insensitive, without the `.exe`) separated by slashes (like `some_video_game/other_game`) that will cause the chatter block to automatically disable whenever that program is open.
7474
- `auto_disable_on_fullscreen`: set to `true` to auto-disable the chatter block when any application is open in fullscreen - see also [#26](https://github.com/mcmonkeyprojects/KeyboardChatterBlocker/issues/26).
75-
- `hotkey_<type>`: (where type is `toggle`, `enable`, `disable`) set to a key combo. Must be a combination of any of `control`, `alt`, `win`, `shift`, and any valid key separated by `+`. For example `control + a`, `win + alt + b`, `shift + d1`. Note that hotkeys including `control` often won't work as they often get reserved by other applications (or Windows itself). This line will register a global hotkey that performs the applicable action (eg `hotkey_disable: win + shift + pause` will allow you to hold those three keys together at any time to immediately disable the chatter blocker).
75+
- `hotkey_toggle`, `hotkey_enable`, `hotkey_disable`: set to a key combo. Must be a combination of any of `control`, `alt`, `win`, `shift`, and any valid key separated by `+`. For example `control + a`, `win + alt + b`, `shift + d1`. Note that hotkeys including `control` often won't work as they often get reserved by other applications (or Windows itself). This line will register a global hotkey that performs the applicable action (eg `hotkey_disable: win + shift + pause` will allow you to hold those three keys together at any time to immediately disable the chatter blocker).
76+
- `hotkey_tempblock`: set to a key combo (any list of keys separated by `+`). Refer to [Microsoft Keys Enum](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.keys?view=netframework-4.7.2) for a list of valid key IDs. Note that you need to use precise key IDs, such as `LShiftKey` (for left shift) rather than generic ones like `Shift`. If you have `hotkey_tempblock` set, any time hold this combination down, all key inputs (down or up) will be discarded. If you have mouse buttons listed as blockable, mouse inputs will be blocked too. For example, `hotkey_tempblock: pause` will allow you to hold the Pause key at any time to pause all input recognition. This is useful for example to block press a key down, and then hold your Pause input to block the release, allowing an app to see it as still being held down (for example: press down on Shift, press down on Pause, release Shift, release Pause, then type - all your input text will then be capitalized).
7677
- `measure_from` set to `Press` or `Release` (defaults to `Press`) to choose when to measure chatter delay from - the last key press, or last key release.
7778

7879
### Other Features

0 commit comments

Comments
 (0)