Keypress
Keypress copied to clipboard
Suggestion: match keys via regex
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.
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/);
Interesting.
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.