Now uses window ID instead of PID

This commit is contained in:
PhatDave
2021-11-03 09:58:06 +01:00
parent d82d7cee48
commit f7bd71453c

View File

@@ -5,8 +5,8 @@ SetWorkingDir %A_ScriptDir%
#SingleInstance force
#Persistent
SetKeyDelay, 0
SetControlDelay, 100
SetKeyDelay, -1, 100
SetControlDelay, 500
ih := InputHook("B")
ih.KeyOpt("{All}", "NV")
@@ -61,7 +61,8 @@ OnKeyDown(InputHook, VK, SC) {
}
if (whitelistKeys.HasKey(key)) {
for k, v in enabledWindows[1] {
ControlSend,, {%key% down}, ahk_pid %v%
; ControlSend,, {%key% down}, ahk_pid %v%
ControlSend,, {%key% down}, ahk_id %v%
}
}
if (!keyLog.HasKey(key)) {
@@ -75,7 +76,8 @@ OnKeyUp(InputHook, VK, SC) {
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
if (whitelistKeys.HasKey(key)) {
for k, v in enabledWindows[1] {
ControlSend,, {%key% up}, ahk_pid %v%
; ControlSend,, {%key% up}, ahk_pid %v%
ControlSend,, {%key% up}, ahk_id %v%
}
}
}
@@ -243,13 +245,14 @@ WhitelistKeys(string) {
}
AddCurrentWindow() {
WinGet, activePID, PID, A
if (!Find(enabledWindows[1], activePID)) {
; WinGet, activePID, PID, A
WinGet, activeID, ID, A
if (!Find(enabledWindows[1], activeID)) {
WinGet, activeName, ProcessName, A
enabledWindows[1].Insert(activePID)
enabledWindows[1].Insert(activeID)
enabledWindows[2].Insert(activeName)
sstring := "Added "
sstring .= activePID
sstring .= activeID
sstring .= " ("
sstring .= activeName
sstring .= ") to echo list"
@@ -258,13 +261,14 @@ AddCurrentWindow() {
}
RemoveCurrentWindow() {
WinGet, activePID, PID, A
if (Find(enabledWindows[1], activePID)) {
; WinGet, activePID, PID, A
WinGet, activeID, ID, A
if (Find(enabledWindows[1], activeID)) {
WinGet, activeName, ProcessName, A
enabledWindows[1].RemoveAt(Find(enabledWindows[1], activePID))
enabledWindows[1].RemoveAt(Find(enabledWindows[1], activeID))
enabledWindows[2].RemoveAt(Find(enabledWindows[2], activeName))
sstring := "Removed "
sstring .= activePID
sstring .= activeID
sstring .= " ("
sstring .= activeName
sstring .= ") from echo list"