Compare commits

...

5 Commits

Author SHA1 Message Date
715ddfa24d Update 2024-08-24 19:41:37 +02:00
unknown
999531d2ab Remove keybind conflict 2022-01-10 20:06:24 +01:00
unknown
e028a339a2 Fix typo 2022-01-10 20:05:51 +01:00
unknown
ed246a7b02 Keys now added and removed via F3 and F4 respectively 2022-01-10 20:05:09 +01:00
PhatDave
f7bd71453c Now uses window ID instead of PID 2021-11-03 09:58:06 +01:00
3 changed files with 407 additions and 402 deletions

728
Echo.ahk
View File

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