Keys can now be added/removed by using hotkeys
This commit is contained in:
55
Echo.ahk
55
Echo.ahk
@@ -5,12 +5,18 @@ SetWorkingDir %A_ScriptDir%
|
|||||||
#SingleInstance force
|
#SingleInstance force
|
||||||
#Persistent
|
#Persistent
|
||||||
|
|
||||||
|
SetKeyDelay, -1
|
||||||
|
SetControlDelay, -1
|
||||||
|
|
||||||
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 removeNext := 0
|
||||||
|
|
||||||
global enabledWindows := Array()
|
global enabledWindows := Array()
|
||||||
enabledWindows.Push(Array())
|
enabledWindows.Push(Array())
|
||||||
enabledWindows.Push(Array())
|
enabledWindows.Push(Array())
|
||||||
@@ -20,6 +26,32 @@ global whitelistKeys := Array()
|
|||||||
|
|
||||||
OnKeyDown(InputHook, VK, SC) {
|
OnKeyDown(InputHook, VK, SC) {
|
||||||
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
|
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
|
||||||
|
if (addNext) {
|
||||||
|
if (!whitelistKeys.HasKey(Key)) {
|
||||||
|
whitelistKeys[key] := 1
|
||||||
|
sstring := "Added "
|
||||||
|
sstring .= key
|
||||||
|
ShowTooltip(sstring)
|
||||||
|
addNext := 0
|
||||||
|
} else {
|
||||||
|
sstring := "Key already exists"
|
||||||
|
ShowTooltip(sstring)
|
||||||
|
addNext := 0asqq
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removeNext) {
|
||||||
|
if (whitelistKeys.HasKey(Key)) {
|
||||||
|
whitelistKeys.Remove(key)
|
||||||
|
sstring := "Removed "
|
||||||
|
sstring .= key
|
||||||
|
ShowTooltip(sstring)
|
||||||
|
removeNext := 0
|
||||||
|
} else {
|
||||||
|
sstring := "Key not found"
|
||||||
|
ShowTooltip(sstring)
|
||||||
|
removeNext := 0
|
||||||
|
}
|
||||||
|
}
|
||||||
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%
|
||||||
@@ -28,10 +60,17 @@ OnKeyDown(InputHook, VK, SC) {
|
|||||||
if (!keyLog.HasKey(key)) {
|
if (!keyLog.HasKey(key)) {
|
||||||
keyLog[key] := SC,
|
keyLog[key] := SC,
|
||||||
}
|
}
|
||||||
; ControlSend,, v, ahk_pid 16736
|
|
||||||
; Tooltip, %key%
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShowTooltip(text) {
|
||||||
|
ToolTip, %text%
|
||||||
|
SetTimer, RemoveToolTip, -500
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoveToolTip:
|
||||||
|
ToolTip
|
||||||
|
return
|
||||||
|
|
||||||
OnKeyUp(InputHook, VK, SC) {
|
OnKeyUp(InputHook, VK, SC) {
|
||||||
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
|
key := GetKeyName(Format("vk{:x}sc{:x}", VK, SC))
|
||||||
if (whitelistKeys.HasKey(key)) {
|
if (whitelistKeys.HasKey(key)) {
|
||||||
@@ -188,7 +227,9 @@ WhitelistButtonUI() {
|
|||||||
|
|
||||||
WhitelistKeys(string) {
|
WhitelistKeys(string) {
|
||||||
for k, v in StrSplit(string, "|") {
|
for k, v in StrSplit(string, "|") {
|
||||||
whitelistKeys.Insert(v)
|
if (v != "a" and v != "s" and v != "d" and v != "w" and v != "enter" and v != "escape") {
|
||||||
|
whitelistKeys[v] := 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +237,14 @@ F3::
|
|||||||
MakeUI()
|
MakeUI()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
^!A::
|
||||||
|
addNext := 1
|
||||||
|
return
|
||||||
|
|
||||||
|
^!R::
|
||||||
|
removeNext := 1
|
||||||
|
return
|
||||||
|
|
||||||
F4::
|
F4::
|
||||||
WhitelistButtonUI()
|
WhitelistButtonUI()
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user