RobertWHurst / Keystrokes

Keystrokes as an easy to use library for binding functions to keys and key combos. It can be used with any TypeScript or JavaScript project, even in non-browser environments.
MIT License
158 stars 6 forks source link

bindKey and bindKeyCombo support array combination #25

Closed qiongshusheng closed 1 year ago

qiongshusheng commented 1 year ago

Keystroke can, like KeyboarJs, support merging strings and data, as shown in the following example:

KeyboarJs: keyboardJS.bind('a + b > c', (e) => { console.log('a and b then c is pressed'); }); keyboardJS.bind(['a + b > c', 'z + y > z'], (e) => { console.log('a and b then c or z and y then z is pressed'); });

Keystroke: bindKey('a', , () => console.log('You\'re pressing "a"')) bindKey(['a', 'b'] () => console.log('You\'re pressing "a" or "b"'))

RobertWHurst commented 1 year ago

Hi @qiongshusheng, thanks for the suggestion. Indeed this is a feature that KeyboardJS has that I left out of Keystrokes. I didn't introduce it because I thought I'd keep things simple to start with, and see if someone asks for it. Now that you have, I'll add it.

Check out PR #26. I'll merge and publish in the next day or so.

qiongshusheng commented 1 year ago

@RobertWHurst Thank you very much for your reply and contribution. I will replace KeyboardJs with Keystrokes in my project. After the array is supported, can you combine bindKey and bindKeyCombo into one interface? In this way, it is easier to use the interface without distinguishing whether it is a key combination or not?