Keypress icon indicating copy to clipboard operation
Keypress copied to clipboard

Suggestion: match keys via regex

Open mallocator opened this issue 9 years ago • 3 comments

You could enhance the matching by using regexes to match the input keys. I'm imagining some combos like

// match key with any modifier
listener.register_regexcombo(/(shift|ctrl|alt) s/)

// match all non-special characters
listener.register_regexcombo(/[a-z0-9]/i)

// match all characters
listener.register_regexcombo(/./)

// match (easier) konami code sequence
listener.register_regexcombo(/(up ){2}(down ){2}(left right ){2}(a b|b a) space/)

Or maybe you don't even need an extra function and can just detect if the input is a regex or not and go form there.

I've been looking for a catch all and this would solve that.

mallocator avatar Apr 04 '15 19:04 mallocator

This is exactly the functionality that I am looking for! I want to be able to match on barcodes such as UPC-A "06867916619\n" when a code is scanned.

// match UPC-A barcode
listener.register_regexcombo(/[0-9]{12,14}\n/);

Or, other codes such as: "1234-123-1234\n"

// match UPC-A barcode
listener.register_regexcombo(/[0-9]{4}-[0-9]{3}-[0-9]{4}\n/);

cdkisa avatar Apr 29 '15 17:04 cdkisa

Interesting.

dmauro avatar Apr 29 '15 17:04 dmauro

To be honest this would be a pretty big undertaking. If someone is interested in making a branch with regex support I would absolutely try my best to get it merged in.

dmauro avatar Aug 16 '15 17:08 dmauro