## Recommended Posts

I just got a CueCat from eBay, and I want to make an application that will dominate the use of the barcode reader. After each reading, it'll send an {ENTER} key. I was thinking if I I could make a script that will buffer system wide key inputs, and if the keys are sent at an exact interval and followed by {ENTER} (I'm assuming that when the barcode sends the keys, they are in a certain pattern/interval), then take the string and do what I want with it.

I have looked around the forums, and I have not found anything that does this. I have found scripts that'll show a dialog, then you scan something, and it sends it to the dialog/input box, etc. That's too simple, and not "Automated" enough.

I did however find an interresting idea mentioned but never provided a true example for was using

```Opt("SendKeyDownDelay", 50)
Opt("SendKeyDelay", 50)```

Not sure exactly how that would work exactly, unless I was able to really track and time each key pressed.

Anyway, if anyone could help me, or point me in the right direction, I'd appreciate it.

Edited by AcidicChip

##### Share on other sites

What's wrong with HotKeySet() or _IsPressed()?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

What's wrong with HotKeySet() or _IsPressed()?

I had thought of that, but hotkeyset has a limit of so many keys, plus it intercepts the keys so on each key I would have to do a "Send", and I get errors like

C:\Documents and Settings\Chance\Desktop\!TEMP!\New AutoIt v3 Script (2).au3 (114) : ==> Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.:

Send("s")

And using _IsPressed just can't capture all the keys sent (or so it seems), no matter how fast I check them...

```#include <Date.au3>
#include <Misc.au3>

\$oDLL = DllOpen("user32.dll")

\$sTemp = ""
\$sLastTime = _NowCalc()

Func CheckForInput()
#cs
For \$i = 48 To 57 Step 1; 0-9
If _IsPressed(Hex(\$i), \$oDLL) Then
ClipPut(ClipGet()&"|"&Chr(\$i))
ExitLoop
EndIf
Next
#ce
For \$i = 65 To 90 Step 1; A-Z
If _IsPressed(Hex(\$i), \$oDLL) Then
ClipPut(ClipGet()&"|"&Chr(\$i))
ExitLoop
EndIf
Next
#cs
For \$i = 97 To 122 Step 1; a-z
If _IsPressed(Hex(\$i), \$oDLL) Then
ClipPut(ClipGet()&"|"&Chr(\$i))
ExitLoop
EndIf
Next
#ce
EndFunc

While 1
Sleep(1)
WEnd

DllClose(\$oDLL)```

What it captured in clipboard when the cueca scanned "hello" was

H|E|L|L|L|L

. It didn't misread the barcode, because it also typed out "hello{ENTER}".

Purhapse my logic/way I'm trying to go about it, is wrong?

##### Share on other sites

I had thought of that, but hotkeyset has a limit of so many keys, plus it intercepts the keys so on each key I would have to do a "Send", and I get errors like

And using _IsPressed just can't capture all the keys sent (or so it seems), no matter how fast I check them...

```#include <Date.au3>
#include <Misc.au3>

\$oDLL = DllOpen("user32.dll")

\$sTemp = ""
\$sLastTime = _NowCalc()

Func CheckForInput()
#cs
For \$i = 48 To 57 Step 1; 0-9
If _IsPressed(Hex(\$i), \$oDLL) Then
ClipPut(ClipGet()&"|"&Chr(\$i))
ExitLoop
EndIf
Next
#ce
For \$i = 65 To 90 Step 1; A-Z
If _IsPressed(Hex(\$i), \$oDLL) Then
ClipPut(ClipGet()&"|"&Chr(\$i))
ExitLoop
EndIf
Next
#cs
For \$i = 97 To 122 Step 1; a-z
If _IsPressed(Hex(\$i), \$oDLL) Then
ClipPut(ClipGet()&"|"&Chr(\$i))
ExitLoop
EndIf
Next
#ce
EndFunc

While 1
Sleep(1)
WEnd

DllClose(\$oDLL)```

What it captured in clipboard when the cueca scanned "hello" was . It didn't misread the barcode, because it also typed out "hello{ENTER}".

Purhapse my logic/way I'm trying to go about it, is wrong?

What API is being used to capture the bar code and send the data? do you need drivers for it to work and which application can it work in? I am very interested in your project because i'm trying to make a similar one for our office to check in and check out books.

The whole process of capturing the data and sending it to the target app can be broken down into events, events have triggers and they also end, the end of an event is also an event. So many you need to capture the event and send the key after it. I just dont know how you would go about it.

i hope that helps if not, i hope you didnt waste too much on reading this.

just trying to help.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

##### Share on other sites

I'm using CueCat, with no API. I just plug it in via USB, and scan something, There wasn't even any driver prompts or anything, and it will send text to whatever is active of what you scanned followed by the {ENTER} key.

##### Share on other sites

```HotKeySet('s', '_SendS')

While 1
Sleep(10000)
WEnd

Func _SendS()
HotKeySet('s', '');kill the hotkey
Send('s');Send the 's'
HotKeySet('s', '_SendS');reactivate Hotkey
EndFunc```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

I'm using CueCat, with no API. I just plug it in via USB, and scan something, There wasn't even any driver prompts or anything, and it will send text to whatever is active of what you scanned followed by the {ENTER} key.

On a lighter note, i totally remember when the cuecat came out. Wired magazine had an issue dedicated to it: they provided a free cuecat and you could scan all of the adverts in the mag. I would spend hours on that thing, it was great.

Your post actually inspired me to purchase one as well, not just for the notalgic feeling but im hoping to mod it for my office.

i'll be watching this thread and posting if I can find anything useful for you.

Cuecat, army of two. {= )

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

##### Share on other sites

Okay, I basically I decided to go with HotKeySet... I found that this method works a lot better than doing for loops of _IsPressed. This method allows me to keep more accurate track of miliseconds that have passed in between key sends.

Here's the code I have that generates my final code (No way in hell I'm doing 36 manual practically duplicate HotKeySets and Funcs).

```Func CodeTemplate(\$iChr)
\$tCode = ""
\$tCode &= 'HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'")'&@CRLF
\$tCode &= 'Func Key_'&StringUpper(Chr(\$iChr))&'()'&@CRLF
\$tCode &= ';ClipPut(ClipGet()&"|'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ';ClipPut(ClipGet()&"|"&\$iTime)'&@CRLF
\$tCode &= ' If (\$iTime >= 0 And \$iTime <= 10) Or (\$iLastTime >= 0 And \$iLastTime <= 10) Then'&@CRLF
\$tCode &= '     If (\$iLastTimeAgain > 10) Then'&@CRLF
\$tCode &= '         \$sKeys = \$sLastKeyAgain&\$sLastKey&"'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= '     Else'&@CRLF
\$tCode &= '         \$sKeys &= "'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= ' EndIf'&@CRLF
\$tCode &= ' \$sLastKeyAgain = \$sLastKey'&@CRLF
\$tCode &= ' \$sLastKey = "'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= ' \$iLastTimeAgain = \$iLastTime'&@CRLF
\$tCode &= ' \$iLastTime = \$iTime'&@CRLF
\$tCode &= ' \$iTime = 0'&@CRLF
\$tCode &= ' HotKeySet("'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ' Send("'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ' HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'")'&@CRLF
\$tCode &= ' ClipPut(\$sKeys)'&@CRLF
\$tCode &= 'EndFunc'&@CRLF&@CRLF
Return \$tCode
EndFunc

\$sCode = ""
\$sCode &= '\$iTime = 0'&@CRLF
\$sCode &= '\$iLastTime = 0'&@CRLF
\$sCode &= '\$iLastTimeAgain = 0'&@CRLF
\$sCode &= '\$sKeys = ""'&@CRLF
\$sCode &= '\$sLastKey = ""'&@CRLF
\$sCode &= '\$sLastKeyAgain = ""'&@CRLF&@CRLF
For \$i = 48 To 57 Step 1; 0-9
\$sCode &= CodeTemplate(\$i)
Next
For \$i = 97 To 122 Step 1; a-z
\$sCode &= CodeTemplate(\$i)
Next
\$sCode &= 'HotKeySet(Chr(13), "KeyCheck")'&@CRLF
\$sCode &= 'Func KeyCheck()'&@CRLF
\$sCode &= ';ClipPut(ClipGet()&"|ENTER")'&@CRLF
\$sCode &= ';ClipPut(ClipGet()&"|"&\$iTime)'&@CRLF
\$sCode &= ' If (\$iTime >= 0 And \$iTime <= 10) Or (\$iLastTime >= 0 And \$iLastTime <= 10) Then'&@CRLF
\$sCode &= '     If StringLen(\$sKeys) >= 5 Then'&@CRLF
\$sCode &= '         TrayTip("CueCat Reader ("&Random(0, 1)&")", \$sKeys&@CRLF&\$iTime&@CRLF&\$iLastTime, 10)'&@CRLF
\$sCode &= '     EndIf'&@CRLF
\$sCode &= ' EndIf'&@CRLF
\$sCode &= ' \$sLastKeyAgain = ""'&@CRLF
\$sCode &= ' \$sLastKey = ""'&@CRLF
\$sCode &= ' \$iLastTimeAgain = 0'&@CRLF
\$sCode &= ' \$iLastTime = 0'&@CRLF
\$sCode &= ' \$iTime = 0'&@CRLF
\$sCode &= ' HotKeySet(Chr(13))'&@CRLF
\$sCode &= ' Send(Chr(13))'&@CRLF
\$sCode &= ' HotKeySet(Chr(13), "KeyCheck")'&@CRLF
\$sCode &= ' ClipPut(\$sKeys)'&@CRLF
\$sCode &= ' \$sKeys = ""'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'Func IncreaseTime()'&@CRLF
\$sCode &= ' \$iTime += 1'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'While 1'&@CRLF
\$sCode &= ' Sleep(250)'&@CRLF
\$sCode &= 'WEnd'&@CRLF

FileDelete(\$sOutputScript)
FileWrite(\$sOutputScript, \$sCode)

If keys are sent within 10 (5 seems to be most accurate) miliseconds, followed by {ENTER}, and the string is longer than 5, then we assume it's a scan.

This seems to work great for the most part, except for sometimes when a barcode contains two letters or numbers that are the same in order (eg. "ll" in "helloworld"), it doesn't pickup both letters/numbers (eg. "helloworld" sometimes registers as "heloworld").

This is where I think the Opt SendKeyDownDelay and SendKeyDelay changing might come in handy, but not sure of how to apply it.

This seems to be my last hurdle. Any more suggestions?

Edited by AcidicChip

##### Share on other sites

Okay, now I have it all working for the most part. This gets all the keys and detects a scan, perfectly...

```Func CodeTemplate(\$iChr)
\$tCode = ""
\$tCode &= 'HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'")'&@CRLF
\$tCode &= 'Func Key_'&StringUpper(Chr(\$iChr))&'()'&@CRLF
\$tCode &= ';ClipPut(ClipGet()&"|'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ';ClipPut(ClipGet()&"|"&\$iTime)'&@CRLF
\$tCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then'&@CRLF
\$tCode &= '     If (\$iLastTimeAgain > \$iMaxDelay) Then'&@CRLF
\$tCode &= '         \$sKeys = \$sLastKeyAgain&\$sLastKey&"'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= '     Else'&@CRLF
\$tCode &= '         \$sKeys &= "'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= ' EndIf'&@CRLF
\$tCode &= ' \$sLastKeyAgain = \$sLastKey'&@CRLF
\$tCode &= ' \$sLastKey = "'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= ' \$iLastTimeAgain = \$iLastTime'&@CRLF
\$tCode &= ' \$iLastTime = \$iTime'&@CRLF
\$tCode &= ' \$iTime = 0'&@CRLF
\$tCode &= ' HotKeySet("'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ' Send("'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ' HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'")'&@CRLF
\$tCode &= ' ClipPut(\$sKeys)'&@CRLF
\$tCode &= 'EndFunc'&@CRLF&@CRLF
Return \$tCode
EndFunc

\$sCode = ""
\$sCode &= 'Opt("SendKeyDelay", 1)'&@CRLF
\$sCode &= 'Opt("SendKeyDownDelay", 1)'&@CRLF&@CRLF
\$sCode &= '\$iMaxDelay = 5'&@CRLF
\$sCode &= '\$iTime = 0'&@CRLF
\$sCode &= '\$iLastTime = 0'&@CRLF
\$sCode &= '\$iLastTimeAgain = 0'&@CRLF
\$sCode &= '\$sKeys = ""'&@CRLF
\$sCode &= '\$sLastKey = ""'&@CRLF
\$sCode &= '\$sLastKeyAgain = ""'&@CRLF&@CRLF
For \$i = 48 To 57 Step 1; 0-9
\$sCode &= CodeTemplate(\$i)
Next
For \$i = 97 To 122 Step 1; a-z
\$sCode &= CodeTemplate(\$i)
Next
\$sCode &= 'HotKeySet(Chr(13), "KeyCheck")'&@CRLF
\$sCode &= 'Func KeyCheck()'&@CRLF
\$sCode &= ';ClipPut(ClipGet()&"|ENTER")'&@CRLF
\$sCode &= ';ClipPut(ClipGet()&"|"&\$iTime)'&@CRLF
\$sCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then'&@CRLF
\$sCode &= '     If StringLen(\$sKeys) >= 5 Then'&@CRLF
\$sCode &= '         TrayTip("CueCat Reader ("&Random(0, 1)&")", \$sKeys&@CRLF&\$iTime&@CRLF&\$iLastTime, 10)'&@CRLF
\$sCode &= '     EndIf'&@CRLF
\$sCode &= ' EndIf'&@CRLF
\$sCode &= ' \$sLastKeyAgain = ""'&@CRLF
\$sCode &= ' \$sLastKey = ""'&@CRLF
\$sCode &= ' \$iLastTimeAgain = 0'&@CRLF
\$sCode &= ' \$iLastTime = 0'&@CRLF
\$sCode &= ' \$iTime = 0'&@CRLF
\$sCode &= ' HotKeySet(Chr(13))'&@CRLF
\$sCode &= ' Send(Chr(13))'&@CRLF
\$sCode &= ' HotKeySet(Chr(13), "KeyCheck")'&@CRLF
\$sCode &= ' ClipPut(\$sKeys)'&@CRLF
\$sCode &= ' \$sKeys = ""'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'Func IncreaseTime()'&@CRLF
\$sCode &= ' \$iTime += 1'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'While 1'&@CRLF
\$sCode &= ' Sleep(250)'&@CRLF
\$sCode &= 'WEnd'&@CRLF

FileDelete(\$sOutputScript)
FileWrite(\$sOutputScript, \$sCode)

Now I'm trying to make it so that if someone were to just type on the keyboard, and the key intervals didn't match my interval specs, then it would just send the keys. I'm not having much luck with it.

Wha's happening is, if I push 1 key, nothing happens. If I then push another key, then the last key I pressed will send twice, and the last key I pressed will send. For example, I type "12" and "112" get's send after I press "2".

The scanning part/intercepting is working for the most part, as long as I don't push a key then scan something when the key cache has something in it, it'll report a mixed keys and code.

Here's the code that I have to generate what's doing that.

```#cs
HotKeySet("a", "Key_A")
Func Key_A()
If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then
If (\$iLastTimeAgain > \$iMaxDelay) Then
\$sKeys = \$sLastKeyAgain&\$sLastKey&"a"
Else
\$sKeys &= "a"
EndIf
\$sLastKeyAgain = \$sLastKey
\$sLastKey = "a"
\$iLastTimeAgain = \$iLastTime
\$iLastTime = \$iTime
Else
If \$sKeys Then
Opt("SendKeyDelay", (\$iMaxDelay * 2))
Send(\$sKeys)
Opt("SendKeyDelay", 1)
EndIf
\$sLastKeyAgain = ""
\$sLastKey = ""
\$sKeys = ""
\$iLastTimeAgain = 0
\$iLastTime = 0
HotKeySet("a")
Send("a")
HotKeySet("a", "Key_A")
EndIf
\$iTime = 0
EndFunc
#ce

Func CodeTemplate(\$iChr)
\$tCode = ""
\$tCode &= 'HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'");Setup the hotkey'&@CRLF
\$tCode &= 'Func Key_'&StringUpper(Chr(\$iChr))&'()'&@CRLF
\$tCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then;If time passed between the last key and this key was within the max allowed interval'&@CRLF
\$tCode &= '     If (\$iLastTimeAgain > \$iMaxDelay) Then;If the time befor that was over the max allwed interval'&@CRLF
\$tCode &= '         \$sKeys = \$sLastKeyAgain&\$sLastKey&"'&Chr(\$iChr)&'";Cache the keys starting with the last 2 keys'&@CRLF
\$tCode &= '     Else;Otherwise'&@CRLF
\$tCode &= '         \$sKeys &= "'&Chr(\$iChr)&'";Append to the cached keys'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= '     \$sLastKeyAgain = \$sLastKey;Move keys down the tree'&@CRLF
\$tCode &= '     \$sLastKey = "'&Chr(\$iChr)&'";Move keys down the tree'&@CRLF
\$tCode &= '     \$iLastTimeAgain = \$iLastTime;Move key intervals down the tree'&@CRLF
\$tCode &= '     \$iLastTime = \$iTime;Move key intervals down the tree'&@CRLF
\$tCode &= ' Else;Assuming that keys pressed are not from scanner'&@CRLF
\$tCode &= '     If \$sKeys Then;If there is a key cache'&@CRLF
\$tCode &= '         Opt("SendKeyDelay", (\$iMaxDelay * 2));Increase send key delay to avoid triggering a check for a scanned key'&@CRLF
\$tCode &= '         HotKeySet("'&Chr(\$iChr)&'");Clear out this hotkey to avoid re-activating it for the cache display'&@CRLF
\$tCode &= '         Send(\$sKeys);Send key cache'&@CRLF
\$tCode &= '         HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'");Re-enable this hotkey'&@CRLF
\$tCode &= '         Opt("SendKeyDelay", 1);Reset send key delay to optimal setting'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= '     \$sLastKeyAgain = "";Clear key tree'&@CRLF
\$tCode &= '     \$sLastKey = "";Clear key tree'&@CRLF
\$tCode &= '     \$sKeys = "";Clear key tree'&@CRLF
\$tCode &= '     \$iLastTimeAgain = 0;Clear time tree'&@CRLF
\$tCode &= '     \$iLastTime = 0;Clear time tree'&@CRLF
\$tCode &= '     HotKeySet("'&Chr(\$iChr)&'");Disable hotkey for passthru'&@CRLF
\$tCode &= '     Send("'&Chr(\$iChr)&'");Pass thru this key'&@CRLF
\$tCode &= '     HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'");Reset hotkey interception'&@CRLF
\$tCode &= ' EndIf'&@CRLF
\$tCode &= ' \$iTime = 0;Reset timer interval'&@CRLF
\$tCode &= 'EndFunc'&@CRLF&@CRLF
Return \$tCode
EndFunc

\$sCode = ""
\$sCode &= 'Opt("SendKeyDelay", 1);Its better this way'&@CRLF
\$sCode &= 'Opt("SendKeyDownDelay", 1);Its just better this way'&@CRLF&@CRLF
\$sCode &= '\$iMaxDelay = 5;Setup the key interval max delay to identify as scan key'&@CRLF
\$sCode &= '\$iTime = 0;Setup time tree'&@CRLF
\$sCode &= '\$iLastTime = 0;Setup time tree'&@CRLF
\$sCode &= '\$iLastTimeAgain = 0;Setup time tree'&@CRLF
\$sCode &= '\$sKeys = "";Setup key tree'&@CRLF
\$sCode &= '\$sLastKey = "";Setup key tree'&@CRLF
\$sCode &= '\$sLastKeyAgain = "";Setup key tree'&@CRLF&@CRLF
For \$i = 48 To 57 Step 1; 0-9
\$sCode &= CodeTemplate(\$i)
Next
For \$i = 97 To 122 Step 1; a-z
\$sCode &= CodeTemplate(\$i)
Next
\$sCode &= 'HotKeySet(Chr(13), "KeyCheck");Setup enter key interception'&@CRLF
\$sCode &= 'Func KeyCheck()'&@CRLF
\$sCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then;If the last 2 keys were within interval time'&@CRLF
\$sCode &= '     If StringLen(\$sKeys) >= 5 Then;If they key cache is > 5'&@CRLF
\$sCode &= '         TrayTip("CueCat Reader ("&Random(0, 1)&")", \$sKeys&@CRLF&\$iTime&@CRLF&\$iLastTime, 10);We assume this is a full scan'&@CRLF
\$sCode &= '     Else;Otherwise'&@CRLF
\$sCode &= '         Opt("SendKeyDelay", (\$iMaxDelay * 2));Increase send key delay to avoid triggering a check for a scanned key'&@CRLF
\$sCode &= '         Send(\$sKeys);Send key cache'&@CRLF
\$sCode &= '         Opt("SendKeyDelay", 1);Reset send key delay to optimal setting'&@CRLF
\$sCode &= '     EndIf'&@CRLF
\$sCode &= ' EndIf'&@CRLF
\$sCode &= ' \$sLastKeyAgain = "";Clear key tree'&@CRLF
\$sCode &= ' \$sLastKey = "";Clear key tree'&@CRLF
\$sCode &= ' \$sKeys = "";Clear key tree'&@CRLF
\$sCode &= ' \$iLastTimeAgain = 0;Clear time tree'&@CRLF
\$sCode &= ' \$iLastTime = 0;Clear time tree'&@CRLF
\$sCode &= ' \$iTime = 0;Cear time tree'&@CRLF
\$sCode &= ' HotKeySet(Chr(13));Clear hotkey'&@CRLF
\$sCode &= ' Send(Chr(13));Send it'&@CRLF
\$sCode &= ' HotKeySet(Chr(13), "KeyCheck");Set key intercept'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'AdlibEnable("IncreaseTime", 1);Set a timer'&@CRLF&@CRLF
\$sCode &= 'Func IncreaseTime()'&@CRLF
\$sCode &= ' \$iTime += 1;Increase timer by 1'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'While 1'&@CRLF
\$sCode &= ' Sleep(250);Duh'&@CRLF
\$sCode &= 'WEnd'&@CRLF

FileDelete(\$sOutputScript)
FileWrite(\$sOutputScript, \$sCode)

I know this is done pretty sloppily, I'm just trying to get it to work, then I'll go thru and clean it up. First place I'll start is with my key and time 'trees'.

Anyway, if someone can tell me what I'm doing wrong,I'd greatly appreciate it.

##### Share on other sites

Okay, now I have it all working for the most part. This gets all the keys and detects a scan, perfectly...

```Func CodeTemplate(\$iChr)
\$tCode = ""
\$tCode &= 'HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'")'&@CRLF
\$tCode &= 'Func Key_'&StringUpper(Chr(\$iChr))&'()'&@CRLF
\$tCode &= ';ClipPut(ClipGet()&"|'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ';ClipPut(ClipGet()&"|"&\$iTime)'&@CRLF
\$tCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then'&@CRLF
\$tCode &= '     If (\$iLastTimeAgain > \$iMaxDelay) Then'&@CRLF
\$tCode &= '         \$sKeys = \$sLastKeyAgain&\$sLastKey&"'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= '     Else'&@CRLF
\$tCode &= '         \$sKeys &= "'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= ' EndIf'&@CRLF
\$tCode &= ' \$sLastKeyAgain = \$sLastKey'&@CRLF
\$tCode &= ' \$sLastKey = "'&Chr(\$iChr)&'"'&@CRLF
\$tCode &= ' \$iLastTimeAgain = \$iLastTime'&@CRLF
\$tCode &= ' \$iLastTime = \$iTime'&@CRLF
\$tCode &= ' \$iTime = 0'&@CRLF
\$tCode &= ' HotKeySet("'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ' Send("'&Chr(\$iChr)&'")'&@CRLF
\$tCode &= ' HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'")'&@CRLF
\$tCode &= ' ClipPut(\$sKeys)'&@CRLF
\$tCode &= 'EndFunc'&@CRLF&@CRLF
Return \$tCode
EndFunc

\$sCode = ""
\$sCode &= 'Opt("SendKeyDelay", 1)'&@CRLF
\$sCode &= 'Opt("SendKeyDownDelay", 1)'&@CRLF&@CRLF
\$sCode &= '\$iMaxDelay = 5'&@CRLF
\$sCode &= '\$iTime = 0'&@CRLF
\$sCode &= '\$iLastTime = 0'&@CRLF
\$sCode &= '\$iLastTimeAgain = 0'&@CRLF
\$sCode &= '\$sKeys = ""'&@CRLF
\$sCode &= '\$sLastKey = ""'&@CRLF
\$sCode &= '\$sLastKeyAgain = ""'&@CRLF&@CRLF
For \$i = 48 To 57 Step 1; 0-9
\$sCode &= CodeTemplate(\$i)
Next
For \$i = 97 To 122 Step 1; a-z
\$sCode &= CodeTemplate(\$i)
Next
\$sCode &= 'HotKeySet(Chr(13), "KeyCheck")'&@CRLF
\$sCode &= 'Func KeyCheck()'&@CRLF
\$sCode &= ';ClipPut(ClipGet()&"|ENTER")'&@CRLF
\$sCode &= ';ClipPut(ClipGet()&"|"&\$iTime)'&@CRLF
\$sCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then'&@CRLF
\$sCode &= '     If StringLen(\$sKeys) >= 5 Then'&@CRLF
\$sCode &= '         TrayTip("CueCat Reader ("&Random(0, 1)&")", \$sKeys&@CRLF&\$iTime&@CRLF&\$iLastTime, 10)'&@CRLF
\$sCode &= '     EndIf'&@CRLF
\$sCode &= ' EndIf'&@CRLF
\$sCode &= ' \$sLastKeyAgain = ""'&@CRLF
\$sCode &= ' \$sLastKey = ""'&@CRLF
\$sCode &= ' \$iLastTimeAgain = 0'&@CRLF
\$sCode &= ' \$iLastTime = 0'&@CRLF
\$sCode &= ' \$iTime = 0'&@CRLF
\$sCode &= ' HotKeySet(Chr(13))'&@CRLF
\$sCode &= ' Send(Chr(13))'&@CRLF
\$sCode &= ' HotKeySet(Chr(13), "KeyCheck")'&@CRLF
\$sCode &= ' ClipPut(\$sKeys)'&@CRLF
\$sCode &= ' \$sKeys = ""'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'Func IncreaseTime()'&@CRLF
\$sCode &= ' \$iTime += 1'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'While 1'&@CRLF
\$sCode &= ' Sleep(250)'&@CRLF
\$sCode &= 'WEnd'&@CRLF

FileDelete(\$sOutputScript)
FileWrite(\$sOutputScript, \$sCode)

Now I'm trying to make it so that if someone were to just type on the keyboard, and the key intervals didn't match my interval specs, then it would just send the keys. I'm not having much luck with it.

Wha's happening is, if I push 1 key, nothing happens. If I then push another key, then the last key I pressed will send twice, and the last key I pressed will send. For example, I type "12" and "112" get's send after I press "2".

The scanning part/intercepting is working for the most part, as long as I don't push a key then scan something when the key cache has something in it, it'll report a mixed keys and code.

Here's the code that I have to generate what's doing that.

```#cs
HotKeySet("a", "Key_A")
Func Key_A()
If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then
If (\$iLastTimeAgain > \$iMaxDelay) Then
\$sKeys = \$sLastKeyAgain&\$sLastKey&"a"
Else
\$sKeys &= "a"
EndIf
\$sLastKeyAgain = \$sLastKey
\$sLastKey = "a"
\$iLastTimeAgain = \$iLastTime
\$iLastTime = \$iTime
Else
If \$sKeys Then
Opt("SendKeyDelay", (\$iMaxDelay * 2))
Send(\$sKeys)
Opt("SendKeyDelay", 1)
EndIf
\$sLastKeyAgain = ""
\$sLastKey = ""
\$sKeys = ""
\$iLastTimeAgain = 0
\$iLastTime = 0
HotKeySet("a")
Send("a")
HotKeySet("a", "Key_A")
EndIf
\$iTime = 0
EndFunc
#ce

Func CodeTemplate(\$iChr)
\$tCode = ""
\$tCode &= 'HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'");Setup the hotkey'&@CRLF
\$tCode &= 'Func Key_'&StringUpper(Chr(\$iChr))&'()'&@CRLF
\$tCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then;If time passed between the last key and this key was within the max allowed interval'&@CRLF
\$tCode &= '     If (\$iLastTimeAgain > \$iMaxDelay) Then;If the time befor that was over the max allwed interval'&@CRLF
\$tCode &= '         \$sKeys = \$sLastKeyAgain&\$sLastKey&"'&Chr(\$iChr)&'";Cache the keys starting with the last 2 keys'&@CRLF
\$tCode &= '     Else;Otherwise'&@CRLF
\$tCode &= '         \$sKeys &= "'&Chr(\$iChr)&'";Append to the cached keys'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= '     \$sLastKeyAgain = \$sLastKey;Move keys down the tree'&@CRLF
\$tCode &= '     \$sLastKey = "'&Chr(\$iChr)&'";Move keys down the tree'&@CRLF
\$tCode &= '     \$iLastTimeAgain = \$iLastTime;Move key intervals down the tree'&@CRLF
\$tCode &= '     \$iLastTime = \$iTime;Move key intervals down the tree'&@CRLF
\$tCode &= ' Else;Assuming that keys pressed are not from scanner'&@CRLF
\$tCode &= '     If \$sKeys Then;If there is a key cache'&@CRLF
\$tCode &= '         Opt("SendKeyDelay", (\$iMaxDelay * 2));Increase send key delay to avoid triggering a check for a scanned key'&@CRLF
\$tCode &= '         HotKeySet("'&Chr(\$iChr)&'");Clear out this hotkey to avoid re-activating it for the cache display'&@CRLF
\$tCode &= '         Send(\$sKeys);Send key cache'&@CRLF
\$tCode &= '         HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'");Re-enable this hotkey'&@CRLF
\$tCode &= '         Opt("SendKeyDelay", 1);Reset send key delay to optimal setting'&@CRLF
\$tCode &= '     EndIf'&@CRLF
\$tCode &= '     \$sLastKeyAgain = "";Clear key tree'&@CRLF
\$tCode &= '     \$sLastKey = "";Clear key tree'&@CRLF
\$tCode &= '     \$sKeys = "";Clear key tree'&@CRLF
\$tCode &= '     \$iLastTimeAgain = 0;Clear time tree'&@CRLF
\$tCode &= '     \$iLastTime = 0;Clear time tree'&@CRLF
\$tCode &= '     HotKeySet("'&Chr(\$iChr)&'");Disable hotkey for passthru'&@CRLF
\$tCode &= '     Send("'&Chr(\$iChr)&'");Pass thru this key'&@CRLF
\$tCode &= '     HotKeySet("'&Chr(\$iChr)&'", "Key_'&StringUpper(Chr(\$iChr))&'");Reset hotkey interception'&@CRLF
\$tCode &= ' EndIf'&@CRLF
\$tCode &= ' \$iTime = 0;Reset timer interval'&@CRLF
\$tCode &= 'EndFunc'&@CRLF&@CRLF
Return \$tCode
EndFunc

\$sCode = ""
\$sCode &= 'Opt("SendKeyDelay", 1);Its better this way'&@CRLF
\$sCode &= 'Opt("SendKeyDownDelay", 1);Its just better this way'&@CRLF&@CRLF
\$sCode &= '\$iMaxDelay = 5;Setup the key interval max delay to identify as scan key'&@CRLF
\$sCode &= '\$iTime = 0;Setup time tree'&@CRLF
\$sCode &= '\$iLastTime = 0;Setup time tree'&@CRLF
\$sCode &= '\$iLastTimeAgain = 0;Setup time tree'&@CRLF
\$sCode &= '\$sKeys = "";Setup key tree'&@CRLF
\$sCode &= '\$sLastKey = "";Setup key tree'&@CRLF
\$sCode &= '\$sLastKeyAgain = "";Setup key tree'&@CRLF&@CRLF
For \$i = 48 To 57 Step 1; 0-9
\$sCode &= CodeTemplate(\$i)
Next
For \$i = 97 To 122 Step 1; a-z
\$sCode &= CodeTemplate(\$i)
Next
\$sCode &= 'HotKeySet(Chr(13), "KeyCheck");Setup enter key interception'&@CRLF
\$sCode &= 'Func KeyCheck()'&@CRLF
\$sCode &= ' If (\$iTime >= 0 And \$iTime <= \$iMaxDelay) Or (\$iLastTime >= 0 And \$iLastTime <= \$iMaxDelay) Then;If the last 2 keys were within interval time'&@CRLF
\$sCode &= '     If StringLen(\$sKeys) >= 5 Then;If they key cache is > 5'&@CRLF
\$sCode &= '         TrayTip("CueCat Reader ("&Random(0, 1)&")", \$sKeys&@CRLF&\$iTime&@CRLF&\$iLastTime, 10);We assume this is a full scan'&@CRLF
\$sCode &= '     Else;Otherwise'&@CRLF
\$sCode &= '         Opt("SendKeyDelay", (\$iMaxDelay * 2));Increase send key delay to avoid triggering a check for a scanned key'&@CRLF
\$sCode &= '         Send(\$sKeys);Send key cache'&@CRLF
\$sCode &= '         Opt("SendKeyDelay", 1);Reset send key delay to optimal setting'&@CRLF
\$sCode &= '     EndIf'&@CRLF
\$sCode &= ' EndIf'&@CRLF
\$sCode &= ' \$sLastKeyAgain = "";Clear key tree'&@CRLF
\$sCode &= ' \$sLastKey = "";Clear key tree'&@CRLF
\$sCode &= ' \$sKeys = "";Clear key tree'&@CRLF
\$sCode &= ' \$iLastTimeAgain = 0;Clear time tree'&@CRLF
\$sCode &= ' \$iLastTime = 0;Clear time tree'&@CRLF
\$sCode &= ' \$iTime = 0;Cear time tree'&@CRLF
\$sCode &= ' HotKeySet(Chr(13));Clear hotkey'&@CRLF
\$sCode &= ' Send(Chr(13));Send it'&@CRLF
\$sCode &= ' HotKeySet(Chr(13), "KeyCheck");Set key intercept'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'AdlibEnable("IncreaseTime", 1);Set a timer'&@CRLF&@CRLF
\$sCode &= 'Func IncreaseTime()'&@CRLF
\$sCode &= ' \$iTime += 1;Increase timer by 1'&@CRLF
\$sCode &= 'EndFunc'&@CRLF&@CRLF
\$sCode &= 'While 1'&@CRLF
\$sCode &= ' Sleep(250);Duh'&@CRLF
\$sCode &= 'WEnd'&@CRLF

FileDelete(\$sOutputScript)
FileWrite(\$sOutputScript, \$sCode)

I know this is done pretty sloppily, I'm just trying to get it to work, then I'll go thru and clean it up. First place I'll start is with my key and time 'trees'.

Anyway, if someone can tell me what I'm doing wrong,I'd greatly appreciate it.

Odd code. Why are you concatenating your function in a Variable? I fail to see why.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

##### Share on other sites

Odd code. Why are you concatenating your function in a Variable? I fail to see why.

As I mentioned before, I'm using 36 hotkeys as an intercept instead of _ispressed, because it allows me to track the interval better.

Since I don't feel like writing all those hotkey sets and functions. The script I am providing here is actually the script that WRITES my final script that does what I want it to. All the functions are pretty much the same, just different characters.

Call me lazy, but I can rewrite 36 functions in a flash.

Edited by AcidicChip

##### Share on other sites

So here's what I have.

```#include <Array.au3>

Opt("SendKeyDelay", 1)
Opt("SendKeyDownDelay", 1)

Dim \$bIntercept = True
Dim \$aKeys[1]
Dim \$aTimes[1]
Dim \$iTime = 0
Dim \$iMaxDelay = 5

HotKeySet("a", "Key_A");Initiate intercept
Func Key_A()
If \$bIntercept Then;If we are set to intercept
If \$aTimes[0] <> "" Then;If there is not an empty time tree
If \$iTime <= \$iMaxDelay Then;If the last key and this key were within the max delay
EndIf
Else;If there is an empty time tree
\$aTimes[0] = \$iTime;Add first time to tree
\$aKeys[0] = "a";Add first key to tree
EndIf
Else;If we are not set to intercept
HotKeySet("a");Clear intercept
Send("a");Pass it thru
HotKeySet("a", "Key_A");Initiate intercept
EndIf
\$iTime = 0;Reset times
EndFunc

Func IncreaseTime()
\$iTime += 1;Increase timer by 1
\$sKeys = StringReplace(_ArrayToString(\$aKeys, ","), ",", "")
If Not \$sKeys And \$aKeys[0] <> "" Then
\$sKeys = \$aKeys[0]
EndIf
If \$iTime > \$iMaxDelay Then
\$bIntercept = False;Disable intercepts
Send(\$sKeys);Pass key tree
\$bIntercept = True;Enable intercepts
ReDim \$aKeys[1];Clear key tree
ReDim \$aTimes[1];Clear time tree
\$iTime = 0
EndIf
EndFunc

While 1
Sleep(250);Duh
WEnd```

What I'm trying to do is make it so that if "a" is sent (via keyboard) it will put it into a "key" cache, and if \$iMaxDelay is exceeded, then pass thru the "a" (or anything else in the key cache), otherwise add it to the "key" cache. Continue to do so until the \$iMaxDelay is exceeded in between "a" key sends/presses, then send out the key cache.

What this is doing is, when I press "a", it resends "a" continually. I think the problem is that \$bIntercept is not taking affect like I want it to when sending out the "key" cache.

Once I get this part working, I apply it to A-9, and add one for {ENTER}, and if {ENTER} is within the maxdelay with a key cache of over 5 characters, then it will assume it as a scan, not "send" it, and instead use the scan output for whatever I need.

So, anyone know how to fix this part?

Edited by AcidicChip

##### Share on other sites

The best I can tell, where I set \$bIntercept to True/False is where I should unset, and reset the hotkey.

So, I then think, loop thru each key in \$sKeys, and do it like this...

```FROM:
\$bIntercept = False;Disable intercepts
Send(\$sKeys);Pass key tree
\$bIntercept = True;Enable intercepts

TO:
For \$i = 1 To StringLen(\$sKeys) - 1 Step 1
HotKeySet(StringMid(\$sKeys, \$i, 1));Clear intercept
Send(StringMid(\$sKeys, \$i, 1));Pass it thru
HotKeySet(StringMid(\$sKeys, \$i, 1), "Key_"&StringUpper(StringMid(\$sKeys, \$i, 1)));Initiate intercept
Next```

But AutoIT doesn't like it, and I can only Eval variables, and not functions, so... Now what?

EDIT: I discovered Call, but I still can't get it right. Maybe I'm just wating my time, lol.

Edited by AcidicChip

##### Share on other sites

Also, how the CueCat is working is, when you plug it in, it reads as another keyboard device. Can I trap everything inputted from the "CueCat" keyboard?

## Create an account

Register a new account

×

• Wiki

• Back

• Git