Detect last 4 keys pressed from a set of seqs. and identify sequence.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dccostac
Posts: 24
Joined: 21 Jul 2016, 14:04

Detect last 4 keys pressed from a set of seqs. and identify sequence.

23 Oct 2017, 07:23

Hi,

So basically I am looking to monitor keys 1 2 3 and 4.

If the script detects sequence 123 4 msgbox saying sequence A pressed etc.

All sequences i am looking to detect are as follows:
123 4

111 4
222 4
333 4

331 4
332 4
311 4

122 4
112 4
233 4
(There is no space before 4th character, just emphasizing all sequences end with 4)

All sequences end with 4. I have no idea on how to even start thinking about this in ahk so any help would be appreciated.

Thanks
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Detect last 4 keys pressed from a set of seqs. and identify sequence.

23 Oct 2017, 09:20

Code: Select all

; b0: no automatic backspacing
; * : ending character is not required 
; ?:  The hotstring will be triggered even when it is inside another word

#Hotstring b0 * ?

::1234:: 
	MsgBox, sequence A pressed
return

::1114:: 
	MsgBox, sequence B pressed
return

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect last 4 keys pressed from a set of seqs. and identify sequence.

23 Oct 2017, 14:52

Here's an attempt:

Code: Select all

~1::
~2::
~3::
~4::
if (vLog = "")
	vLog := "xxxx"
vLog := SubStr(vLog, 2) SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
if vLog in 1234,1114,2224,3334,3314,3324,3114,1224,1124,2334
{
	ToolTip, % vLog " (MATCH)"
	vLog := "xxxx"
}
else
	ToolTip, % vLog
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Detect last 4 keys pressed from a set of seqs. and identify sequence.

23 Oct 2017, 16:27

Those are nice suggestions, I would use Input. This example is for v2 but is easy to make in v1 to ofc,

Code: Select all

endKey:=4
combos := {111:func("f"), 222:func("g"), abc:func("f")}	; Associate a combination with a function
loop {
	if combos.haskey(combo:=substr(Input("V", endKey),-3))	; Get the last 3 typed characters.
		combos[combo].call(combo)
}
f(combo){
	msgbox(A_ThisFunc  "`n"  combo)
}
g(combo){
	msgbox(A_ThisFunc  "`n"  combo)
}
The biggest advantage with this method is that it is trivial to extend beyond combinations of 1, 2 and 3. Just add whichever combo you like in the combos array.

Cheers.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hiahkforum, ntepa, vanove and 165 guests