The best way to handle Barcode input is to set your scanner to have a pre-amble (Key that scanner sends at beginning of scan) / post-amble (Key that scanner sends at end of scan)
Then you do not need to bother with any of this A_TimeSincePriorHotkey nonsense to be able to tell the difference between you typing on the keyboard normally, or the scanner sending keys
Pre/post amble will be set by scanning a special barcode from the manual.
Just set the pre-amble to say F11 and the post-amble to say F12, then you can turn on or off the capture hotkeys easily:
Code: Select all
Scanning := 0
F11::
Scanning := 1
return
F12::
Scanning := 0
return
#if Scanning
Loop {
; Set up your number / letter hotkeys here
Chars = 0123456789abcdefghijklmnopqrstuvwxyz!""$`%^&*()_+=-``\|,./;'#[]{}:@~<>?
Loop, Parse, Chars
Hotkey, % "$~" A_LoopField, BarCodeHandler, on
}
#if
Also, you can avoid a lot of run-time work with function binding
Instead of:
Code: Select all
Chars = 0123456789abcdefghijklmnopqrstuvwxyz!""$`%^&*()_+=-``\|,./;'#[]{}:@~<>?
Loop, Parse, Chars
Hotkey, % "$~" A_LoopField, BarCodeHandler, on
BarCodeHandler:
Accu .= SubStr(A_ThisHotkey, 0)
; ...
You can do this:
Code: Select all
Chars = 0123456789abcdefghijklmnopqrstuvwxyz!""$`%^&*()_+=-``\|,./;'#[]{}:@~<>?
Loop, Parse, Chars
{
fn := Func("BarCodeHandler").Bind(A_LoopField)
Hotkey, % "$~" A_LoopField, % fn, on
}
BarCodeHandler(key){
; key already holds A_ThisHotkey
}
Also see
here for some code which can bind to every key on the keyboard, without having to specify a key list.