简体   繁体   English

您如何在Meteor中使用Keypress包?

[英]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. 我正在尝试将keypress.js与流星一起使用,以便每当我按下一个字母时,都会显示该字母。

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. 您实际上并不需要Keypress.js。 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));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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