Skip to content

Commit 7118300

Browse files
committed
add tempdisable/tempenable, for #30
1 parent 14e26a7 commit 7118300

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

KeyboardChatterBlocker/KeyBlocker.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public enum MeasureFrom
5555
/// </summary>
5656
public MeasureFrom MeasureMode = MeasureFrom.Press;
5757

58+
/// <summary>
59+
/// If marked, the blocker is disabled, temporarily.
60+
/// </summary>
61+
public bool TempDisable = false;
62+
5863
/// <summary>
5964
/// Load the <see cref="KeyBlocker"/> from config file settings.
6065
/// </summary>
@@ -162,6 +167,14 @@ public void ApplyConfigSetting(string setting)
162167
Hotkeys["disable"] = settingValue;
163168
HotKeys.Register(settingValue, () => Program.MainForm.SetEnabled(false));
164169
break;
170+
case "hotkey_tempenable":
171+
Hotkeys["tempenable"] = settingValue;
172+
HotKeys.Register(settingValue, () => TempDisable = false);
173+
break;
174+
case "hotkey_tempdisable":
175+
Hotkeys["tempdisable"] = settingValue;
176+
HotKeys.Register(settingValue, () => TempDisable = true);
177+
break;
165178
case "measure_from":
166179
MeasureMode = (MeasureFrom)Enum.Parse(typeof(MeasureFrom), settingValue, true);
167180
break;
@@ -314,7 +327,7 @@ public string GetConfigurationString()
314327
/// <returns>True to allow the press, false to deny it.</returns>
315328
public bool AllowKeyDown(Keys key, bool defaultZero)
316329
{
317-
if (!IsEnabled || IsAutoDisabled) // Not enabled = allow everything through.
330+
if (!IsEnabled || IsAutoDisabled || TempDisable) // Not enabled = allow everything through.
318331
{
319332
return true;
320333
}
@@ -363,7 +376,7 @@ public bool AllowKeyDown(Keys key, bool defaultZero)
363376
public bool AllowKeyUp(Keys key)
364377
{
365378
ulong timeNow = GetTickCount64();
366-
if (!IsEnabled || IsAutoDisabled) // Not enabled = allow everything through.
379+
if (!IsEnabled || IsAutoDisabled || TempDisable) // Not enabled = allow everything through.
367380
{
368381
KeysToLastReleaseTime[key] = timeNow;
369382
return true;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ 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_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).
75+
- `hotkey_toggle`, `hotkey_enable`, `hotkey_disable`, `hotkey_tempenable`, `hotkey_tempdisable`: 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). The `tempdisable` and `tempenable` pair allow for disabling in a temporary way (ie, don't affect or override the main application setting, useful for things like AutoHotKey scripts).
7676
- `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).
7777
- `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.
7878

0 commit comments

Comments
 (0)