dmauro / Keypress

A keyboard input capturing utility in which any key can be a modifier key.
http://dmauro.github.io/Keypress/
Apache License 2.0
3.18k stars 313 forks source link

Suggestion: match keys via regex #88

Open mallocator opened 9 years ago

mallocator commented 9 years ago

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.

cdkisa commented 9 years ago

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/);
dmauro commented 9 years ago

Interesting.

dmauro commented 9 years ago

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.