Prevent Hotkey If Any Other Keys Are Pressed?
Prevent Hotkey If Any Other Keys Are Pressed?
For example, to only fire a::b if a is the only button being pressed. To further clarify, a::b shouldn't fire if c (or any other key) is already being held down when a is pressed. Can this be done?
Re: Prevent Hotkey If Any Other Keys Are Pressed?
From (https://autohotkey.com/board/topic/1006 ... y-pressed/). Script by Leef_me
Code: Select all
return ; end of autoexec section
F1::
f := GetAllKeysPressed("P") ; see function below
MaxIndex := f.MaxIndex()
if MaxIndex > 1
msgbox more %MaxIndex%
else
msgbox this message will only be shown if the f1 key is pressed alone.
return
;======================================================
; the following 'for' loop could be used to see the keys being pressed
;======================================================
; Read from the array:
; Loop % f.MaxIndex() ; More traditional approach.
for index, element in f ; Recommended approach in most cases.
{
; Using "Loop", indices must be consecutive numbers from 1 to the number
; of elements in the array (or they must be calculated within the loop).
; MsgBox % "Element number " . A_Index . " is " . Array[A_Index]
; Using "for", both the index (or "key") and its associated value
; are provided, and the index can be *any* value of your choosing.
MsgBox % "Element number " . index . " is " . element
}
;======================================================
return
#singleinstance force
#Persistent
; leef_me's debugging tools
+esc::exitapp ; <-- shift escape to exit program
f11::listvars
f12::reload
; the following function taken from the forum, posted by himanshu
; http://www.autohotkey.com/board/topic/85347-find-out-all-the-keys-that-are-pressed-down-currently/page-2
; returns an array containing names of all keys pressed down currently.
; Pass "L" (default) to check only the logical state of the keys, and "P" to check the physical state
GetAllKeysPressed(mode = "L") {
pressed := Array()
i := 1
keys = ``|1|2|3|4|5|6|7|8|9|0|-|=|[|]\|;|'|,|.|/|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|Esc|Tab|CapsLock|LShift|RShift|LCtrl|RCtrl|LWin|RWin|LAlt|RAlt|Space|AppsKey|Up|Down|Left|Right|Enter|BackSpace|Delete|Home|End|PGUP|PGDN|PrintScreen|ScrollLock|Pause|Insert|NumLock|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|F13|F14|F15|F16|F17|F18|F19|F20
; '|' isn't a key itself (with '\' being the "actual" key), so okay to use is as a delimiter
Loop Parse, keys, |
{
key = %A_LoopField%
isDown := GetKeyState(key, mode)
if(isDown)
{
pressed[i] := key ; using 'i' instead of array.insert() for efficiency
i++
}
}
return pressed
}
I am your average ahk newbie. Just.. a tat more cute.
Re: Prevent Hotkey If Any Other Keys Are Pressed?
Thanks so much! That works. However, it has some unnecessary functions and some long-hand tags. I'll post a more concise version here in case anyone else comes across this.Nwb wrote:...
Code: Select all
q::
a := getallkeyspressed("p")
maxindex := a.maxindex()
if maxindex > 1
return
else
send x
return
getallkeyspressed(mode = "p") {
pressed := array()
i := 1
keys = ``|1|2|3|4|5|6|7|8|9|0|-|=|[|]\|;|'|,|.|/|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|esc|tab|capslock|lshift|rshift|lctrl|rctrl|lwin|rwin|lalt|ralt|space|appskey|up|down|left|right|enter|bs|del|home|end|pgup|pgdn|printscreen|scrolllock|pause|ins|numlock|f1|f2|f3|f4|f5|f6|f7|f8|f9|f10|f11|f12
loop parse, keys, |
{
key = %a_loopfield%
isdown := getkeystate(key, mode)
if(isdown)
{
pressed[i] := key
i++
}
}
return pressed
}
^esc::exitapp
Who is online
Users browsing this forum: No registered users and 134 guests