Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

BUG: Hotstring without ending character not working for the first time after script reload/startup


  • Please log in to reply
3 replies to this topic
codecube
  • Members
  • 7 posts
  • Last active: Apr 26 2015 05:01 PM
  • Joined: 22 Apr 2015

My version is 1.1.21.03 64bit.

 

I use Autohotkey hotstring fuctionality with a magnatic card reader which acts like a keyboard device, to identify card string input, and extract card number, then output card number only.

Card string output from the card reader starts with "%B" and ends with a enter ({Enter}). I wrote script to let the hotstring be triggered by %B.

However it does not work for the first time I swipe the card right after Autohotkey is freshly started, or script is reloaded. After the first time, starting from the second time or onward when I swipe the card, it works just fine. If I test the script by manually key in the string by actual keyboard, it fails the similar way the first time (see below for examples). It does not matter how long time I wait after the script reload/AHK restart. I tried 5 minutes and still no luck. The first time hotstring triggering always fails (if set with no ending character). So it's definitely an AHK bug.

 

For example, the raw card string coming out of card reader is like:

%B374326297171234^SMITH/JOHN

 

And I would like the hotstring to be triggered when %B is read, and instead output the card number only, i.e., 374326297171234.

My script is like:

 

:*:%B::
Input, cardNumber, ,{Enter}
CARET_POS := InStr(cardNumber, "^")
if(CARET_POS != 0)
{
    cardNumber := Trim(SubStr(cardNumber, 1, CARET_POS - 1))
}
Send %cardNumber%
return

 

It makes no difference how long time I wait after fresh start or reload. I tried waiting 5 minutes after script reload and the result is the same - first time swiping always fails.

 

The first time output from AHK if I swipe the card will be:

%374326297171234^SMITH/JOHN{Enter}

 

It's almost identical with the raw string except with the missing "B" in the string.

 

If I type by keyboard manually (first time) the string     %B374326297171234^SMITH/JOHN

in notepad, I get

374326297171234^SMITH/JOHN

(the auto-backspacing happens after I type in %B, but it does not read my input after that until I type {Enter}, but rather direclty output whatever I enter).

 

So I have 3 different scenarios with different behavior - first time hotstring triggering has issues by using card reader, or by keyboard, with differrent behaviour. Second time and thereafter hotstring triggering works  just fine.

 

This can be reproduced every time I try. It's definitely a AHK bug.



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If it's "definitely a AHK bug", then I should be able to reproduce it. I cannot, therefore I think your claim is unfounded. It is certainly too early to be ruling out your system and other software on your system.

Can anyone else reproduce it?

What does KeyHistory show after you swipe the card for the first time? Does it show the missing 'B' keystroke or backspace?

codecube
  • Members
  • 7 posts
  • Last active: Apr 26 2015 05:01 PM
  • Joined: 22 Apr 2015

found a workaround that worked:

 

:*b0:%B::
Input, cardNumber, ,{Enter}
CARET_POS := InStr(cardNumber, "^")
if(CARET_POS != 0)
{
cardNumber := Trim(SubStr(cardNumber, 1, CARET_POS - 1))
}
SendRaw %cardNumber%
cardNumberLength := StrLen(cardNumber)
Loop, %cardNumberLength%
{
Send {Left}
}
Send {Backspace}{Backspace}{End}
return


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
You can use Send {Left %cardNumberLength%} instead of a loop.