I've got a low-level keyboard hook which currently allows me to control a media player from inside any application, including games.
It works by looking at the specific keystroke captured.
I'd like to extend it to look for combinations of keys. I can hardcode some logic but I feel there must be a more logical way.
Really, I'm looking for something like a shift register...
eg as I type "BlahPlay", I'd like a structure which can be used like this...
[_,_,_,_]
[_,_,_,B]
[_,_,B,l]
[_,B,l,a]
[B,l,a,h]
[l,a,h,P]
[a,h,P,l]
[h,P,l,a]
[P,l,a,y] <-- detect "Play"
Short of looping and shifting the items in an array, what's the correct way to do this?
The best I can think of right now is ...
Private Register(4) As Char
Private Position = 0
Sub Add(Character as Char)
Register(Position) = Character
Position = (Position + 1) Mod Register.Length
End Sub
Function Get() as String
Dim Ret As New StringBuilder
For i = Position To Position + Register.Length
Ret.Append(Register(i Mod Register.Length)
Next
Return Ret.ToString
End Function