简体   繁体   中英

How do you use Keypress package with Meteor?

I'm trying to use keypress.js with meteor so that anytime i press a letter I am getting that letter displayed.

Template.letters.events({
var listener = new Keypress.Listener();
Session.set("letter", Session.get("listener") + 1);
}

});

I'm pretty sure this is not how I am suppose to do this..any help would be appreciated

You don't really need Keypress.js for this. Seems like that library is for detecting specific, complex key combinations. You should be able to do this:

$(window).keypress(function(e) {
  Session.set('letter', String.fromCharCode(e.which));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM