SendMode("Input") SetWorkingDir(A_ScriptDir) SetKeyDelay(0) SetControlDelay(0) ih := InputHook("B") ih.KeyOpt("{All}", "NV") ih.OnKeyDown := OnKeyDown ih.OnKeyUp := OnKeyUp ih.Start() addNext := 0 removeNext := 0 enabledWindows := Map() whitelistedKeys := Map() paused := 0 SetTimer(ResetHook, -60000) OnKeyDown(InputHook, VK, SC) { global paused, addNext, removeNext, enabledWindows, whitelistedKeys if (paused) { return } hexVK := Format("{:X}", VK) hexSC := Format("{:X}", SC) key := GetKeyName("vk" . hexVK . "sc" . hexSC) if (addNext) { addNext := 0 if (whitelistedKeys.Has(key)) { ToolTip("Key already exists") SetTimer(ToolTip, -500) return } whitelistedKeys.Set(key, 1) ToolTip("Added " . key) SetTimer(ToolTip, -500) return } if (removeNext) { removeNext := 0 if (!whitelistedKeys.Has(key)) { ToolTip("Key not found") SetTimer(ToolTip, -500) return } whitelistedKeys.Delete(key) ToolTip("Removed " . key) SetTimer(ToolTip, -500) return } if (whitelistedKeys.Has(key)) { for hwnd, windowName in enabledWindows { ControlSend("{" . key . " down}",, "ahk_id " . hwnd) } } } OnKeyUp(InputHook, VK, SC) { global paused, whitelistedKeys, enabledWindows if (paused) { return } hexVK := Format("{:X}", VK) hexSC := Format("{:X}", SC) key := GetKeyName("vk" . hexVK . "sc" . hexSC) if (whitelistedKeys.Has(key)) { for hwnd, windowName in enabledWindows { ControlSend("{" . key . " up}",, "ahk_id " . hwnd) } } } WinGetAll() { PIDs := [] winTitles := [] all := WinGetList() for window in all { PID := WinGetPID("ahk_id " . window) name := WinGetProcessName("ahk_id " . window) if (name != "") { PIDs.Push(PID) winTitles.Push(name) } } return [PIDs, winTitles] } ResetHook() { global ih ih.Stop() ih := InputHook("B") ih.KeyOpt("{All}", "NV") ih.OnKeyDown := OnKeyDown ih.OnKeyUp := OnKeyUp ih.Start() SetTimer(ResetHook, -30000) } TogglePause() { global paused if (paused) { ToolTip("Unpaused") SetTimer(ToolTip, -500) paused := 0 return } ToolTip("Paused") SetTimer(ToolTip, -500) paused := 1 return } F5:: { global ih ih.Stop() ih := InputHook("B") ih.KeyOpt("{All}", "NV") ih.OnKeyDown := OnKeyDown ih.OnKeyUp := OnKeyUp ih.Start() Reload } F3:: { global addNext ToolTip("Adding key") SetTimer(ToolTip, -500) addNext := 1 } F4:: { global removeNext ToolTip("Removing key") SetTimer(ToolTip, -500) removeNext := 1 } ^!Y:: { global enabledWindows ToolTip("Adding window") SetTimer(ToolTip, -500) 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) 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()