diff --git a/Echo.ahk2 b/Echo.ahk2 index bc4863e..52c0a2a 100644 --- a/Echo.ahk2 +++ b/Echo.ahk2 @@ -1,8 +1,8 @@ SendMode("Input") SetWorkingDir(A_ScriptDir) -SetKeyDelay(-1, 100) -SetControlDelay(500) +SetKeyDelay(0) +SetControlDelay(0) ih := InputHook("B") ih.KeyOpt("{All}", "NV") @@ -52,8 +52,8 @@ OnKeyDown(InputHook, VK, SC) { return } if (whitelistedKeys.Has(key)) { - for k, v in enabledWindows[1] { - ControlSend("{" . key . " down}", "ahk_id " . v) + for hwnd, windowName in enabledWindows { + ControlSend("{" . key . " down}",, "ahk_id " . hwnd) } } if (!keyLog.Has(key)) { @@ -66,18 +66,16 @@ OnKeyUp(InputHook, VK, SC) { if (paused) { return } - key := GetKeyName("%vk" . VK . "sc" . SC "%") + hexVK := Format("{:X}", VK) + hexSC := Format("{:X}", SC) + key := GetKeyName("vk" . hexVK . "sc" . hexSC) if (whitelistedKeys.Has(key)) { - for k, v in enabledWindows[1] { - ControlSend("{" . key . " up}", "ahk_id " . v) + for hwnd, windowName in enabledWindows { + ControlSend("{" . key . " up}",, "ahk_id " . hwnd) } } } -SortArray(Array) { - Array.Sort() -} - WinGetAll() { PIDs := [] winTitles := [] @@ -166,7 +164,6 @@ KeyLogToString() { WhitelistButtonUI() { Gui := Gui() Gui.Destroy() - SortArray(keyLog) string := KeyLogToString() Gui.Add("ListBox", "Multi w800 h600 vKeyLogUI", string) Gui.Add("Button", "Default", "Save") @@ -184,36 +181,6 @@ WhitelistKeys(string) { } } -AddCurrentWindow() { - global enabledWindows - activeID := WinGetID("A") - if (enabledWindows.Has(activeID)) { - ToolTip("Window already in echo list") - SetTimer(ToolTip, -500) - return - } - activeName := WinGetProcessName("A") - enabledWindows.Set(activeID, activeName) - ToolTip("Added " . activeID . " (" . activeName . ") to echo list") - SetTimer(ToolTip, -500) - return -} - -RemoveCurrentWindow() { - global enabledWindows - activeID := WinGetID("A") - if (!enabledWindows.Has(activeID)) { - ToolTip("Window not found in echo list") - SetTimer(ToolTip, -500) - return - } - activeName := enabledWindows[activeID] - enabledWindows.Delete(activeID) - ToolTip("Removed " . activeID . " (" . activeName . ") from echo list") - SetTimer(ToolTip, -500) - return -} - ResetHook() { global ih ih.Stop() @@ -265,15 +232,37 @@ F4:: { } ^!Y:: { + global enabledWindows ToolTip("Adding window") SetTimer(ToolTip, -500) - AddCurrentWindow() + activeID := WinGetID("A") + if (enabledWindows.Has(activeID)) { + ToolTip("Window already in echo list") + SetTimer(ToolTip, -500) + return + } + activeName := WinGetProcessName("A") + enabledWindows.Set(activeID, activeName) + ToolTip("Added " . activeID . " (" . activeName . ") to echo list") + SetTimer(ToolTip, -500) + return } ^!C:: { + global enabledWindows ToolTip("Removing window") SetTimer(ToolTip, -500) - RemoveCurrentWindow() + activeID := WinGetID("A") + if (!enabledWindows.Has(activeID)) { + ToolTip("Window not found in echo list") + SetTimer(ToolTip, -500) + return + } + activeName := enabledWindows[activeID] + enabledWindows.Delete(activeID) + ToolTip("Removed " . activeID . " (" . activeName . ") from echo list") + SetTimer(ToolTip, -500) + return } F6:: TogglePause()