Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I handle key events in meteor?

Tags:

meteor

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.

like image 470
Ben Taitelbaum Avatar asked Jun 02 '12 16:06

Ben Taitelbaum


1 Answers

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:

  1. keydown
  2. keypress
  3. 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...

like image 181
Tamara Wijsman Avatar answered Oct 22 '22 16:10

Tamara Wijsman