feat: (2) implement better keybind system

This commit is contained in:
2025-10-15 21:09:22 -04:00
parent c14427bf81
commit 86d7e3ffbd
+31 -1
View File
@@ -107,7 +107,7 @@ namespace Spectrum.Input
{ {
if (!mainConfig.Data.TriggerBot) if (!mainConfig.Data.TriggerBot)
return; return;
if (!IsKeyOrMouseDown(mainConfig.Data.TriggerKey) || mainConfig.Data.TriggerKey == Keys.None) if (!IsKeyOrMouseDown(mainConfig.Data.TriggerKeybind) || mainConfig.Data.TriggerKeybind.Key == Keys.None)
return; return;
var currentPosition = new Point(); var currentPosition = new Point();
@@ -318,6 +318,36 @@ namespace Spectrum.Input
return (GetAsyncKeyState((int)key) & 0x8000) != 0; ; return (GetAsyncKeyState((int)key) & 0x8000) != 0; ;
} }
private static readonly Dictionary<string, bool> _keybindToggleStates = new();
public static bool IsKeyOrMouseDown(Keybind keybind)
{
if (keybind.Type == KeybindType.Always)
return true;
bool isKeyDown = IsKeyOrMouseDown(keybind.Key);
if (keybind.Type == KeybindType.Hold)
return isKeyDown;
string toggleKey = keybind.Key.ToString();
if (!_keybindToggleStates.ContainsKey(toggleKey))
_keybindToggleStates[toggleKey] = false;
if (isKeyDown && !_keybindToggleStates.ContainsKey($"{toggleKey}_pressed"))
{
_keybindToggleStates[$"{toggleKey}_pressed"] = true;
_keybindToggleStates[toggleKey] = !_keybindToggleStates[toggleKey];
}
else if (!isKeyDown)
{
_keybindToggleStates.Remove($"{toggleKey}_pressed");
}
return _keybindToggleStates[toggleKey];
}
private static MakcuMouseButton? MapKeysToMakcuButton(Keys key) private static MakcuMouseButton? MapKeysToMakcuButton(Keys key)
{ {
return key switch return key switch