According to the docs, I should be able to handle key events like keypress
in the same way I can handle the click
event, but I feel like I'm missing something.
I've done the following:
> meteor create keypressTest
> cd keypressTest
> sed -e 's/click input/keypress body/' -i .bak keypressTest.js
> meteor
But when I press keys, nothing shows up in the console like it does when handling the click event.
Are there any examples of working key handling in meteor? I know I can do a workaround in jquery, but would prefer to stick to the clean template events if I can.
Please note that keypress is deprecated and you might want to use textinput instead.
I do however note that keydown
and keyup
are not deprecated, so using one of those might work more reliable than using keypress
. Note that the documentation specifies the order:
keydown
keypress
keyup
If you want to act upon the press you could use keydown
; if you want to act upon the lift, use keyup
. I would prefer the latter given that it still allows you to cancel the keypress by switching to another application before lifting it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With