Implement core functionality in ahk2

This commit is contained in:
2025-01-01 01:00:46 +01:00
parent 59b8ab5e57
commit f6bb50438d

View File

@@ -1,8 +1,8 @@
SendMode("Input") SendMode("Input")
SetWorkingDir(A_ScriptDir) SetWorkingDir(A_ScriptDir)
SetKeyDelay(-1, 100) SetKeyDelay(0)
SetControlDelay(500) SetControlDelay(0)
ih := InputHook("B") ih := InputHook("B")
ih.KeyOpt("{All}", "NV") ih.KeyOpt("{All}", "NV")
@@ -52,8 +52,8 @@ OnKeyDown(InputHook, VK, SC) {
return return
} }
if (whitelistedKeys.Has(key)) { if (whitelistedKeys.Has(key)) {
for k, v in enabledWindows[1] { for hwnd, windowName in enabledWindows {
ControlSend("{" . key . " down}", "ahk_id " . v) ControlSend("{" . key . " down}",, "ahk_id " . hwnd)
} }
} }
if (!keyLog.Has(key)) { if (!keyLog.Has(key)) {
@@ -66,18 +66,16 @@ OnKeyUp(InputHook, VK, SC) {
if (paused) { if (paused) {
return 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)) { if (whitelistedKeys.Has(key)) {
for k, v in enabledWindows[1] { for hwnd, windowName in enabledWindows {
ControlSend("{" . key . " up}", "ahk_id " . v) ControlSend("{" . key . " up}",, "ahk_id " . hwnd)
} }
} }
} }
SortArray(Array) {
Array.Sort()
}
WinGetAll() { WinGetAll() {
PIDs := [] PIDs := []
winTitles := [] winTitles := []
@@ -166,7 +164,6 @@ KeyLogToString() {
WhitelistButtonUI() { WhitelistButtonUI() {
Gui := Gui() Gui := Gui()
Gui.Destroy() Gui.Destroy()
SortArray(keyLog)
string := KeyLogToString() string := KeyLogToString()
Gui.Add("ListBox", "Multi w800 h600 vKeyLogUI", string) Gui.Add("ListBox", "Multi w800 h600 vKeyLogUI", string)
Gui.Add("Button", "Default", "Save") 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() { ResetHook() {
global ih global ih
ih.Stop() ih.Stop()
@@ -265,15 +232,37 @@ F4:: {
} }
^!Y:: { ^!Y:: {
global enabledWindows
ToolTip("Adding window") ToolTip("Adding window")
SetTimer(ToolTip, -500) 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:: { ^!C:: {
global enabledWindows
ToolTip("Removing window") ToolTip("Removing window")
SetTimer(ToolTip, -500) 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() F6:: TogglePause()