From 1b7847da6340e70ee28014b7da9bd002d97dc881 Mon Sep 17 00:00:00 2001 From: PhatDave Date: Wed, 27 Oct 2021 22:42:39 +0200 Subject: [PATCH] Keys can now be added/removed by using hotkeys --- Echo.ahk | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/Echo.ahk b/Echo.ahk index 4f25831..2103f82 100644 --- a/Echo.ahk +++ b/Echo.ahk @@ -5,12 +5,18 @@ SetWorkingDir %A_ScriptDir% #SingleInstance force #Persistent +SetKeyDelay, -1 +SetControlDelay, -1 + ih := InputHook("B") ih.KeyOpt("{All}", "NV") ih.OnKeyDown := Func("OnKeyDown") ih.OnKeyUp := Func("OnKeyUp") ih.Start() +global addNext := 0 +global removeNext := 0 + global enabledWindows := Array() enabledWindows.Push(Array()) enabledWindows.Push(Array()) @@ -20,6 +26,32 @@ global whitelistKeys := Array() OnKeyDown(InputHook, VK, SC) { key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC)) + if (addNext) { + if (!whitelistKeys.HasKey(Key)) { + whitelistKeys[key] := 1 + sstring := "Added " + sstring .= key + ShowTooltip(sstring) + addNext := 0 + } else { + sstring := "Key already exists" + ShowTooltip(sstring) + addNext := 0asqq + } + } + if (removeNext) { + if (whitelistKeys.HasKey(Key)) { + whitelistKeys.Remove(key) + sstring := "Removed " + sstring .= key + ShowTooltip(sstring) + removeNext := 0 + } else { + sstring := "Key not found" + ShowTooltip(sstring) + removeNext := 0 + } + } if (whitelistKeys.HasKey(key)) { for k, v in enabledWindows[1] { ControlSend,, {%key% down}, ahk_pid %v% @@ -28,10 +60,17 @@ OnKeyDown(InputHook, VK, SC) { if (!keyLog.HasKey(key)) { keyLog[key] := SC, } - ; ControlSend,, v, ahk_pid 16736 - ; Tooltip, %key% } +ShowTooltip(text) { + ToolTip, %text% + SetTimer, RemoveToolTip, -500 +} + +RemoveToolTip: + ToolTip +return + OnKeyUp(InputHook, VK, SC) { key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC)) if (whitelistKeys.HasKey(key)) { @@ -188,7 +227,9 @@ WhitelistButtonUI() { WhitelistKeys(string) { for k, v in StrSplit(string, "|") { - whitelistKeys.Insert(v) + if (v != "a" and v != "s" and v != "d" and v != "w" and v != "enter" and v != "escape") { + whitelistKeys[v] := 1 + } } } @@ -196,6 +237,14 @@ F3:: MakeUI() return +^!A:: + addNext := 1 +return + +^!R:: + removeNext := 1 +return + F4:: WhitelistButtonUI() return