I’m trying to catch an RFID read using the Perspective key events to go straight to the idP login.
The RFID badges are an 8 - 10 character hex code followed by a line feed. While I can catch the code, as soon as I try include the line feed, nothing works.
This is the regex: [A-Fa-f0-9]{8,10}[\n?\r] and it works perfectly in regex testers, such as regexr.com.
That doesn't look like the correct pattern. If you're looking for an OS-agnostic linefeed, you would want: [A-Fa-f0-9]{8,10}\r?\n - Windows uses CRLF, so \r\n, Unix uses \n alone. You explicitly don't want a character set [] around that, since the square brackets change the escaping logic such that your pattern is asking for a hex string followed by any one character \n, \r, or ? - not an optional newline.
Building on that, if you want to still only match the code but retain the condition where it is followed by a new line, you can leverage a lookahead assertion, e.g. [A-Fa-f0-9]{8,10}(?=\r?\n).
Ugh, you’re right, there is something strange here. It seems that the regex is matching against some string representation of the typed key, not the actual underlying character. A regex like this works when you press enter: .+(Enter)
I’m of the opinion this is a bug (and filed a ticket to that effect) but there may be some underlying browser…strangeness, I’ll say, at work here that I’m not aware of.
This is expected behavior, all. At the core of the regex match is the data that we receive from a JavaScript KeyboardEvent because this executes in the scope of the browser. We’re assembling a character sequence to match against from an input source (your barcode scanner) that creates KeyboardEvents. A “new line” character shows up as a key press for the “Enter” key.
https://keycode.info/ is a pretty decent way to test what KeyboardEvent data your sequence would produce. It tests a key at a time, but knowing what your sequence looks like, you could type it out on your keyboard to generate the KeyboardEvent and observe the event.key value in the tool.
I have a question regarding your scanning solution. Do you always select a input field before you scan the RFID tag, or are you able to trigger the Key event without?
It continuously matches and calls system.perspective.login on matching 8-10 hexadecimal characters followed by enter.
It would also match and call the login if a user were to type this, we deemed that unlikely enough. The convenience of just tapping twice is more than worth it.
I would have preferred an existing session to be logged out if another user taps, but that is not the behaviour as described in this thread:
Hi, I've tried a couple of places but where do I configure the keystroke? I have a similar deployment as the original post but with an actual barcode scanner. The scanner is set to scan then send and send an Enter keystroke.
My regex is as follow: [5|R][0|T]...........\d\d\d\d(?=Enter)
Then I'm binding the first array of data to a string tag that is on a PLC but when I scann it doesn't write anything to it.