regex - AHK - How to use dynamic hotstring with a barcode scanner -


i need trigger subroutine when serial number of product has been scanned in barcode scanner. serial number looks this: 11nnnn22334. need use scanned in serial number variable.

i tried dynamic regular expression hotstrings library include below, can't make work reliably using barcode scanner (it's fast). don't want slow down barcode scanner. either not trigger subroutine @ or leaves first digit of serial number behind after subroutine been triggered. ideas?

test: msgbox, %$1% ; string triggered subroutine return  hotstrings("([0-9][0-9]nnnn[0-9][0-9][0-9][0-9][0-9])", "test")  /*     function: hotstrings         dynamically adds regular expression hotstrings.      parameters:         c - regular expression hotstring         - (optional) text replace hotstring or label goto,             leave blank remove hotstring definition triggering action      examples: > hotstrings("(b|b)tw\s", "%$1%y way") ; type 'btw' followed space, tab or return > hotstrings("i)omg", "oh god!") ; type 'omg' in case, upper, lower or mixed > hotstrings("\bcolou?r", "rgb(128, 255, 0);") ; '\b' prevents matching before word, e.g. 'multicololoured'      license:         - regex dynamic hotstrings: modified version edd           - original: <http://www.autohotkey.net/~polyethene/#hotstrings>         - dedicated public domain (cc0 1.0) <http://creativecommons.org/publicdomain/zero/1.0/> */  hotstrings(k, = "", options:="") {     static z, m = "~$", m_ = "*~$", s, t, w = 2000, sd, d = "left,right,up,down,home,end,rbutton,lbutton", f = "!,+,^,#", f_="{,}"     global $     if z = ; init     {         regread, sd, hkcu, control panel\international, sdecimal         loop, 94         {             c := chr(a_index + 32)             if a_index between 33 , 58                 hotkey, %m_%%c%, __hs             else if a_index not between 65 , 90                 hotkey, %m%%c%, __hs         }         e = 0,1,2,3,4,5,6,7,8,9,dot,div,mult,add,sub,enter         loop, parse, e, `,             hotkey, %m%numpad%a_loopfield%, __hs         e = bs,shift,space,enter,return,tab,%d%         loop, parse, e, `,             hotkey, %m%%a_loopfield%, __hs         z = 1     }     if (a == "" , k == "") ; poll     {         q:=regexreplace(a_thishotkey, "\*\~\$(.*)", "$1")         q:=regexreplace(q, "\~\$(.*)", "$1")         if q = bs         {             if (substr(s, 0) != "}")                 stringtrimright, s, s, 1         }         else if q in %d%             s =         else         {             if q = shift             return             else if q = space                 q := " "             else if q = tab                 q := "`t"             else if q in enter,return,numpadenter                 q := "`n"             else if (regexmatch(q, "numpad(.+)", n))             {                 q := n1 == "div" ? "/" : n1 == "mult" ? "*" : n1 == "add" ? "+" : n1 == "sub" ? "-" : n1 == "dot" ? sd : ""                 if n1 digit                     q = %n1%             }             else if (getkeystate("shift") ^ !getkeystate("capslock", "t"))                 stringlower, q, q             s .= q         }         loop, parse, t, `n ; check         {             stringsplit, x, a_loopfield, `r             if (regexmatch(s, x1 . "$", $)) ; match             {                 stringlen, l, $                 stringtrimright, s, s, l                 if !(x3~="i)\bnb\b")        ; if no backspce "nb"                     sendinput, {bs %l%}                 if (islabel(x2))                     gosub, %x2%                 else                 {                     transform, x0, deref, %x2%                     loop, parse, f_, `,                         stringreplace, x0, x0, %a_loopfield%, ¥%a_loopfield%¥,                     loop, parse, f_, `,                         stringreplace, x0, x0, ¥%a_loopfield%¥, {%a_loopfield%},                     loop, parse, f, `,                         stringreplace, x0, x0, %a_loopfield%, {%a_loopfield%},                     sendinput, %x0%                 }             }         }         if (strlen(s) > w)             stringtrimleft, s, s, w // 2     }     else ; assert     {         stringreplace, k, k, `n, \n, ; normalize         stringreplace, k, k, `r, \r,         loop, parse, t, `n         {             l = %a_loopfield%             if (substr(l, 1, instr(l, "`r") - 1) == k)                 stringreplace, t, t, `n%l%         }         if !=             t = %t%`n%k%`r%a%`r%options%     }     return     __hs: ; event     hotstrings("", "", options)     return } 

you can try speed hotkeys function fiddling setbatchlines:

hotstrings(k, = "", options:="") {     prevbatchlines := a_batchlines     setbatchlines, -1       ... ; rest of function here       }      ; reset whatever      setbatchlines, %prevbatchlines%      return      __hs: ; event         hotstrings("", "", options)     return } 

although not recommended (it's nonzero default reason), way.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -