Skip to content

Commit

Permalink
add tempdisable/tempenable, for #30
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 27, 2023
1 parent 14e26a7 commit 7118300
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions KeyboardChatterBlocker/KeyBlocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public enum MeasureFrom
/// </summary>
public MeasureFrom MeasureMode = MeasureFrom.Press;

/// <summary>
/// If marked, the blocker is disabled, temporarily.
/// </summary>
public bool TempDisable = false;

/// <summary>
/// Load the <see cref="KeyBlocker"/> from config file settings.
/// </summary>
Expand Down Expand Up @@ -162,6 +167,14 @@ public void ApplyConfigSetting(string setting)
Hotkeys["disable"] = settingValue;
HotKeys.Register(settingValue, () => Program.MainForm.SetEnabled(false));
break;
case "hotkey_tempenable":
Hotkeys["tempenable"] = settingValue;
HotKeys.Register(settingValue, () => TempDisable = false);
break;
case "hotkey_tempdisable":
Hotkeys["tempdisable"] = settingValue;
HotKeys.Register(settingValue, () => TempDisable = true);
break;
case "measure_from":
MeasureMode = (MeasureFrom)Enum.Parse(typeof(MeasureFrom), settingValue, true);
break;
Expand Down Expand Up @@ -314,7 +327,7 @@ public string GetConfigurationString()
/// <returns>True to allow the press, false to deny it.</returns>
public bool AllowKeyDown(Keys key, bool defaultZero)
{
if (!IsEnabled || IsAutoDisabled) // Not enabled = allow everything through.
if (!IsEnabled || IsAutoDisabled || TempDisable) // Not enabled = allow everything through.
{
return true;
}
Expand Down Expand Up @@ -363,7 +376,7 @@ public bool AllowKeyDown(Keys key, bool defaultZero)
public bool AllowKeyUp(Keys key)
{
ulong timeNow = GetTickCount64();
if (!IsEnabled || IsAutoDisabled) // Not enabled = allow everything through.
if (!IsEnabled || IsAutoDisabled || TempDisable) // Not enabled = allow everything through.
{
KeysToLastReleaseTime[key] = timeNow;
return true;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ I've taken a similar approach to the software solutions mentioned above, but wit
- `keys.<KEY>`: (for example, `keys.H`) set to the time (in ms) for that specific key's keyboard chatter threshold.
- `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.
- `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).
- `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).
- `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).
- `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).
- `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.

Expand Down

0 comments on commit 7118300

Please sign in to comment.