This commit is contained in:
2024-08-24 19:41:37 +02:00
parent 999531d2ab
commit 715ddfa24d
3 changed files with 407 additions and 407 deletions

733
Echo.ahk
View File

@@ -1,372 +1,363 @@
#NoEnv #NoEnv
#Warn SendMode Input
SendMode Input SetWorkingDir %A_ScriptDir%
SetWorkingDir %A_ScriptDir% #SingleInstance force
#SingleInstance force #Persistent
#Persistent
SetBatchLines, -1
SetBatchLines, -1 SetKeyDelay, -1, 100
SetKeyDelay, -1, 100 SetControlDelay, 500
SetControlDelay, 500
ih := InputHook("B")
ih := InputHook("B") ih.KeyOpt("{All}", "NV")
ih.KeyOpt("{All}", "NV") ih.OnKeyDown := Func("OnKeyDown")
ih.OnKeyDown := Func("OnKeyDown") ih.OnKeyUp := Func("OnKeyUp")
ih.OnKeyUp := Func("OnKeyUp") ih.Start()
ih.Start()
global addNext := 0
global addNext := 0 global removeNext := 0
global removeNext := 0
global enabledWindows := Array()
global enabledWindows := Array() enabledWindows.Push(Array())
enabledWindows.Push(Array()) enabledWindows.Push(Array())
enabledWindows.Push(Array())
global keyLog := Array()
global keyLog := Array() global whitelistKeys := Array()
global whitelistKeys := Array()
global paused := 0
global paused := 0
SetTimer, ResetHook, -60000
SetTimer, ResetHook, -60000
OnKeyDown(InputHook, VK, SC) {
OnKeyDown(InputHook, VK, SC) { if (!paused) {
if (!paused) { key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC)) if (addNext) {
if (addNext) { if (!whitelistKeys.HasKey(Key)) {
if (!whitelistKeys.HasKey(Key)) { whitelistKeys[key] := 1
whitelistKeys[key] := 1 sstring := "Added "
sstring := "Added " sstring .= key
sstring .= key ShowTooltip(sstring)
ShowTooltip(sstring) addNext := 0
addNext := 0 } else {
} else { sstring := "Key already exists"
sstring := "Key already exists" ShowTooltip(sstring)
ShowTooltip(sstring) addNext := 0
addNext := 0 }
} return
return }
} if (removeNext) {
if (removeNext) { if (whitelistKeys.HasKey(Key)) {
if (whitelistKeys.HasKey(Key)) { whitelistKeys.Remove(key)
whitelistKeys.Remove(key) sstring := "Removed "
sstring := "Removed " sstring .= key
sstring .= key ShowTooltip(sstring)
ShowTooltip(sstring) removeNext := 0
removeNext := 0 } else {
} else { sstring := "Key not found"
sstring := "Key not found" ShowTooltip(sstring)
ShowTooltip(sstring) removeNext := 0
removeNext := 0 }
} return
return }
} if (whitelistKeys.HasKey(key)) {
if (whitelistKeys.HasKey(key)) { for k, v in enabledWindows[1] {
for k, v in enabledWindows[1] { ; ControlSend,, {%key% down}, ahk_pid %v%
; ControlSend,, {%key% down}, ahk_pid %v% ; Random, rand, 50, 2000
ControlSend,, {%key% down}, ahk_id %v% ; Sleep %rand%
} ControlSend,, {%key% down}, ahk_id %v%
} }
if (!keyLog.HasKey(key)) { }
keyLog[key] := SC, if (!keyLog.HasKey(key)) {
} keyLog[key] := SC,
} }
} }
}
OnKeyUp(InputHook, VK, SC) {
if (!paused) { ; ~LButton::
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC)) ; MouseGetPos, xpos, ypos
if (whitelistKeys.HasKey(key)) { ; for k, v in enabledWindows[1] {
for k, v in enabledWindows[1] { ; ControlClick, xpos ypos, ahk_id %v%
; ControlSend,, {%key% up}, ahk_pid %v% ; ControlClick,, {%key% down}, ahk_id %v%
ControlSend,, {%key% up}, ahk_id %v% ; }
} ; return
}
} OnKeyUp(InputHook, VK, SC) {
} if (!paused) {
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
ShowTooltip(text) { if (whitelistKeys.HasKey(key)) {
ToolTip, %text% for k, v in enabledWindows[1] {
SetTimer, RemoveToolTip, -800 ; ControlSend,, {%key% up}, ahk_pid %v%
} ControlSend,, {%key% up}, ahk_id %v%
}
RemoveToolTip: }
ToolTip }
return }
; Not really mine at all ShowTooltip(text) {
SortArray(Array, Order="A") { ToolTip, %text%
;Order A: Ascending, D: Descending, R: Reverse SetTimer, RemoveToolTip, -800
MaxIndex := ObjMaxIndex(Array) }
If (Order = "R") {
count := 0 RemoveToolTip:
Loop, % MaxIndex ToolTip
ObjInsert(Array, ObjRemove(Array, MaxIndex - count++)) return
Return
} ; Not really mine at all
Partitions := "|" ObjMinIndex(Array) "," MaxIndex SortArray(Array, Order="A") {
Loop { ;Order A: Ascending, D: Descending, R: Reverse
comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",") MaxIndex := ObjMaxIndex(Array)
spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1) If (Order = "R") {
if (Order = "A") { count := 0
Loop, % epos - spos { Loop, % MaxIndex
if (Array[pivot] > Array[A_Index+spos]) ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos)) Return
} }
} else { Partitions := "|" ObjMinIndex(Array) "," MaxIndex
Loop, % epos - spos { Loop {
if (Array[pivot] < Array[A_Index+spos]) comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",")
ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos)) spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
} if (Order = "A") {
} Loop, % epos - spos {
Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1) if (Array[pivot] > Array[A_Index+spos])
if (pivot - spos) > 1 ;if more than one elements ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
Partitions .= "|" spos "," pivot-1 ;the left partition }
if (epos - pivot) > 1 ;if more than one elements } else {
Partitions .= "|" pivot+1 "," epos ;the right partition Loop, % epos - spos {
} Until !Partitions if (Array[pivot] < Array[A_Index+spos])
} ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
}
WinGetAll() { }
PIDs := Array() Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1)
winTitles := Array() if (pivot - spos) > 1 ;if more than one elements
output := Array() Partitions .= "|" spos "," pivot-1 ;the left partition
WinGet, all, list if (epos - pivot) > 1 ;if more than one elements
Loop, %all% Partitions .= "|" pivot+1 "," epos ;the right partition
{ } Until !Partitions
WinGet, PID, PID, % "ahk_id " all%A_Index% }
WinGet, name, ProcessName, % "ahk_id " all%A_Index%
if (name != "") { WinGetAll() {
PIDs.Push(PID) PIDs := Array()
winTitles.Push(name) winTitles := Array()
} output := Array()
} WinGet, all, list
output.Push(PIDs) Loop, %all%
output.Push(winTitles) {
return output WinGet, PID, PID, % "ahk_id " all%A_Index%
} WinGet, name, ProcessName, % "ahk_id " all%A_Index%
if (name != "") {
AllWindowsToString() { PIDs.Push(PID)
allWindows := WinGetAll() winTitles.Push(name)
output := "" }
for k, v in allWindows[1] { }
output .= allWindows[1][k] output.Push(PIDs)
output .= ", " output.Push(winTitles)
output .= allWindows[2][k] return output
output .= "|" }
}
StringTrimRight, output, output, 1 AllWindowsToString() {
return output allWindows := WinGetAll()
} output := ""
for k, v in allWindows[1] {
Find(arr, val) { output .= allWindows[1][k]
for k, v in arr { output .= ", "
if (v == val) { output .= allWindows[2][k]
return k output .= "|"
} }
} StringTrimRight, output, output, 1
return 0 return output
} }
EnableWindows(istring) { Find(arr, val) {
while (enabledWindows.Length() > 0) { for k, v in arr {
enabledWindows.Pop() if (v == val) {
} return k
enabledWindows.Push(Array()) }
enabledWindows.Push(Array()) }
if (InStr(istring, "|") == 0) { return 0
ostring := StrSplit(istring, ", ") }
if (!Find(enabledWindows[1], (ostring[1]))) {
enabledWindows[1].Push(ostring[1]) EnableWindows(istring) {
enabledWindows[2].Push(ostring[2]) while (enabledWindows.Length() > 0) {
} enabledWindows.Pop()
} else { }
ostring := StrSplit(istring, "|") enabledWindows.Push(Array())
for k, v in ostring { enabledWindows.Push(Array())
ostring2 := StrSplit(v, ", ") if (InStr(istring, "|") == 0) {
if (!Find(enabledWindows[1], (ostring2[1]))) { ostring := StrSplit(istring, ", ")
enabledWindows[1].Push(ostring2[1]) if (!Find(enabledWindows[1], (ostring[1]))) {
enabledWindows[2].Push(ostring2[2]) enabledWindows[1].Push(ostring[1])
} enabledWindows[2].Push(ostring[2])
} }
} } else {
; TODO: Remove all non selected windows ostring := StrSplit(istring, "|")
} for k, v in ostring {
ostring2 := StrSplit(v, ", ")
GuiSelectActiveWindows(allWindows) { if (!Find(enabledWindows[1], (ostring2[1]))) {
output := Array() enabledWindows[1].Push(ostring2[1])
for k, v in allWindows[1] { enabledWindows[2].Push(ostring2[2])
if (Find(enabledWindows[1], "" v)) { }
; GuiControl, Choose, WindowListGUI, k }
output.Push(k) }
} ; TODO: Remove all non selected windows
} }
return output
} GuiSelectActiveWindows(allWindows) {
output := Array()
MakeUI() { for k, v in allWindows[1] {
Gui, Destroy if (Find(enabledWindows[1], "" v)) {
string := AllWindowsToString() ; GuiControl, Choose, WindowListGUI, k
Gui, Add, ListBox, Multi h600 w800 vWindowListGUI, %string% output.Push(k)
Gui, Add, Button, Default, OK }
Gui, Show }
for k, v in GuiSelectActiveWindows(WinGetAll()) { return output
; See what's wrong with choose, maybe it doesn't like to be called many times though just that is being done on forum guy }
GuiControl, Choose, WindowListGUI, v
} MakeUI() {
} Gui, Destroy
string := AllWindowsToString()
KeyLogToString() { Gui, Add, ListBox, Multi h600 w800 vWindowListGUI, %string%
output := "" Gui, Add, Button, Default, OK
for k, v in keyLog { Gui, Show
output .= k for k, v in GuiSelectActiveWindows(WinGetAll()) {
output .= "|" ; See what's wrong with choose, maybe it doesn't like to be called many times though just that is being done on forum guy
} GuiControl, Choose, WindowListGUI, v
StringTrimRight, output, output, 1 }
return output }
}
KeyLogToString() {
WhitelistButtonUI() { output := ""
Gui, Destroy for k, v in keyLog {
SortArray(keyLog) output .= k
string := KeyLogToString() output .= "|"
Gui, Add, ListBox, Multi h600 w800 vKeyLogUI, %string% }
Gui, Add, Button, Default, Save StringTrimRight, output, output, 1
Gui, Show return output
for k, v in GuiSelectActiveWindows(WinGetAll()) { }
; See what's wrong with choose, maybe it doesn't like to be called many times though just that is being done on forum guy
GuiControl, Choose, WindowListGUI, v WhitelistButtonUI() {
} Gui, Destroy
} SortArray(keyLog)
string := KeyLogToString()
WhitelistKeys(string) { Gui, Add, ListBox, Multi h600 w800 vKeyLogUI, %string%
whitelistKeys := Array() Gui, Add, Button, Default, Save
for k, v in StrSplit(string, "|") { Gui, Show
whitelistKeys[v] := 1 for k, v in GuiSelectActiveWindows(WinGetAll()) {
} ; See what's wrong with choose, maybe it doesn't like to be called many times though just that is being done on forum guy
} GuiControl, Choose, WindowListGUI, v
}
AddCurrentWindow() { }
; WinGet, activePID, PID, A
WinGet, activeID, ID, A WhitelistKeys(string) {
if (!Find(enabledWindows[1], activeID)) { whitelistKeys := Array()
WinGet, activeName, ProcessName, A for k, v in StrSplit(string, "|") {
enabledWindows[1].Insert(activeID) whitelistKeys[v] := 1
enabledWindows[2].Insert(activeName) }
sstring := "Added " }
sstring .= activeID
sstring .= " (" AddCurrentWindow() {
sstring .= activeName ; WinGet, activePID, PID, A
sstring .= ") to echo list" WinGet, activeID, ID, A
ShowTooltip(sstring) if (!Find(enabledWindows[1], activeID)) {
} WinGet, activeName, ProcessName, A
} enabledWindows[1].Insert(activeID)
enabledWindows[2].Insert(activeName)
RemoveCurrentWindow() { sstring := "Added "
; WinGet, activePID, PID, A sstring .= activeID
WinGet, activeID, ID, A sstring .= " ("
if (Find(enabledWindows[1], activeID)) { sstring .= activeName
WinGet, activeName, ProcessName, A sstring .= ") to echo list"
enabledWindows[1].RemoveAt(Find(enabledWindows[1], activeID)) ShowTooltip(sstring)
enabledWindows[2].RemoveAt(Find(enabledWindows[2], activeName)) }
sstring := "Removed " }
sstring .= activeID
sstring .= " (" RemoveCurrentWindow() {
sstring .= activeName ; WinGet, activePID, PID, A
sstring .= ") from echo list" WinGet, activeID, ID, A
ShowTooltip(sstring) if (Find(enabledWindows[1], activeID)) {
} WinGet, activeName, ProcessName, A
} enabledWindows[1].RemoveAt(Find(enabledWindows[1], activeID))
enabledWindows[2].RemoveAt(Find(enabledWindows[2], activeName))
ResetHook: sstring := "Removed "
ih.Stop() sstring .= activeID
ih := InputHook("B") sstring .= " ("
ih.KeyOpt("{All}", "NV") sstring .= activeName
ih.OnKeyDown := Func("OnKeyDown") sstring .= ") from echo list"
ih.OnKeyUp := Func("OnKeyUp") ShowTooltip(sstring)
ih.Start() }
; Tooltip, WIN }
SetTimer, ResetHook, -30000
return ResetHook:
ih.Stop()
TogglePause() { ih := InputHook("B")
if (paused) { ih.KeyOpt("{All}", "NV")
ShowTooltip("Unpaused") ih.OnKeyDown := Func("OnKeyDown")
paused := 0 ih.OnKeyUp := Func("OnKeyUp")
return ih.Start()
} ; Tooltip, WIN
ShowTooltip("Paused") SetTimer, ResetHook, -30000
paused := 1 return
return
} TogglePause() {
if (paused) {
ShowTooltip("Unpaused")
F5:: paused := 0
ih.Stop() return
ih := InputHook("B") }
ih.KeyOpt("{All}", "NV") ShowTooltip("Paused")
ih.OnKeyDown := Func("OnKeyDown") paused := 1
ih.OnKeyUp := Func("OnKeyUp") return
ih.Start() }
return
; F3:: F5::
; MakeUI() ih.Stop()
; return ih := InputHook("B")
ih.KeyOpt("{All}", "NV")
; F4:: ih.OnKeyDown := Func("OnKeyDown")
; WhitelistButtonUI() ih.OnKeyUp := Func("OnKeyUp")
; return ih.Start()
return
F3::
ShowTooltip("Adding key") ; F3::
addNext := 1 ; MakeUI()
return ; return
F4:: ; F4::
ShowTooltip("Removing key") ; WhitelistButtonUI()
removeNext := 1 ; return
return
F3::
^!S:: ShowTooltip("Adding key")
ShowTooltip("Adding window") addNext := 1
AddCurrentWindow() return
return
F4::
^!D:: ShowTooltip("Removing key")
ShowTooltip("Removing window") removeNext := 1
RemoveCurrentWindow() return
Return
^!X::
F6:: ShowTooltip("Adding window")
TogglePause() AddCurrentWindow()
return return
F7:: ^!C::
whitelistKeys["q"] := 1 ShowTooltip("Removing window")
whitelistKeys["e"] := 1 RemoveCurrentWindow()
whitelistKeys[1] := 1 Return
whitelistKeys[2] := 1
whitelistKeys[3] := 1 F6::
whitelistKeys[4] := 1 TogglePause()
whitelistKeys[5] := 1 return
whitelistKeys["LShift"] := 1
whitelistKeys["LControl"] := 1 ButtonSave:
whitelistKeys["g"] := 1 Gui, Submit
whitelistKeys["v"] := 1 WhitelistKeys(KeyLogUI)
whitelistKeys["r"] := 1 return
whitelistKeys["f"] := 1
whitelistKeys["c"] := 1 ButtonOK:
whitelistKeys["y"] := 1 Gui, Submit
return EnableWindows(WindowListGUI)
return
ButtonSave:
Gui, Submit
WhitelistKeys(KeyLogUI)
return
ButtonOK:
Gui, Submit
EnableWindows(WindowListGUI)
return
; F5::reload ; F5::reload

9
MouseTest.ahk Normal file
View File

@@ -0,0 +1,9 @@
#NoEnv
SetBatchLines, -1
#InstallMouseHook
; Mouse button event handlers
~LButton::
MouseGetPos, xpos, ypos
ToolTip, %xpos% %ypos%
return

View File

@@ -1,37 +1,37 @@
# Echoes keyboard events to selectable windows # Echoes keyboard events to selectable windows
Mainly used (and made) for World of Warcraft but it might have it's other uses Mainly used (and made) for World of Warcraft but it might have it's other uses
F3 brings up UI which allows the user to select 1 or more applications to echo **all** keyboard events to F3 brings up UI which allows the user to select 1 or more applications to echo **all** keyboard events to
In the current state ALL events are echoed, ~~customizability is planned~~ In the current state ALL events are echoed, ~~customizability is planned~~
## 1.1.x ## 1.1.x
Keys can now be whitelisted and only whitelisted keys will be echoed Keys can now be whitelisted and only whitelisted keys will be echoed
The whitelist menu can be accessed by pressing F4 and only keys pressed since the start of the program will be shown, user can then pick as many as they please to whitelist and only those the user picks will be echoed to other windows The whitelist menu can be accessed by pressing F4 and only keys pressed since the start of the program will be shown, user can then pick as many as they please to whitelist and only those the user picks will be echoed to other windows
## 1.1.2 ## 1.1.2
Keys can now be whitelisted by using hotkeys Keys can now be whitelisted by using hotkeys
Pressing Pressing
`Ctrl + Alt + A` `Ctrl + Alt + A`
Will add the next hit key to the whitelist Will add the next hit key to the whitelist
`Ctrl + Alt + R` `Ctrl + Alt + R`
Will remove the next hit key from the whitelist Will remove the next hit key from the whitelist
## 1.1.3 ## 1.1.3
Windows can now be added to the echo list using `Ctrl+Alt+S` and `Ctrl+Alt+D` where S adds the **current** window and D removes the **current** window Windows can now be added to the echo list using `Ctrl+Alt+S` and `Ctrl+Alt+D` where S adds the **current** window and D removes the **current** window
## 1.1.4 ## 1.1.4
For some reason the keyboard hook sometimes gives up For some reason the keyboard hook sometimes gives up
Added option to re-hook keyboard on `F5` Added option to re-hook keyboard on `F5`