I'm currently trying to set something up whereby I can use Autohotkey to read a barcode and output a filepath.
My barcode scanner reads a barcode and outputs the result as text (as if it were typed into a keyboard very quickly) followed by the enter key.
I can format my barcodes how I like, and I currently have the following:
::**::
input, scan,,{Enter}
If StrLen(scan) <> 11 {
msgbox There was an error - barcode read was not 11 characters long (= %scan% )
} else
{
StringSplit, ScanArray, scan, ~
;msgbox Job ID is %ScanArray1%
;msgbox Part ID is %ScanArray2%
strPathString := "z:\jobs\" . ScanArray1 . "\" . ScanArray2 . ".xxl"
send {home}
send {shift down}
send {end}
send {shift up}
send %strPathString%
send {Enter}
}
return
The barcodes I'm using are formatted: ** 12345|67890
. If this barcode is scanned, the plan is:
**
(including space after asterisks) at the start activates the hotstring.12345|67890
is read into AHK and strPathString
becomes z:\jobs\12345\67890.xxl
Now this works correctly, some of the time, however I'm hitting the issue that once the hotstring fires, it seems to be taking too long to start reading the input, resulting in AHK receiving things like "345|67890" and other results where the first ~1-4 digits are missing. The effect is also worse if my computer/cpu is busy with other things.
If I were to have the user press a hotkey (say ctrl+shift+e) to bring up an InputBox, which then reads and processes the barcode input, it works correctly every time (I have tested this), but I'd rather just have the user position the cursor in the right field, then scan the barcode directly without having to use an InputBox. Also of note is that when an InputBox is active, scanning the barcode with the HotString code still active, and the "** " at the start of the barcode, the hotstring is processed perfectly every time, which is what leads me to believe that it's just a case of AHK's "wake up" time being too slow.
Are there any other ways to do this which will be more reliable?
Try this piece of code using RegEx powered hotstrings.
#Include Hotstrings.ahk
SetBatchLines, -1
; Not sure, whether to put "|" or "~" as delimiter here
hotstrings("\*\* (\d{5})\|(\d{5})", "ProcessBarcode")
ProcessBarcode:
msgbox % "Job ID: " $1 "`nPart ID: " $2
return