Questions tagged «keypress»

在控件具有焦点的情况下按下键时发生。

10
在python中检测按键?
我正在用python开发一个秒表类型的程序,我想知道如何检测是否按下了一个键(例如p表示暂停,s表示停止),而我不希望它像raw_input这样等待用户输入,然后继续执行。有人知道如何在while循环中执行此操作吗? 另外,我想做这个跨平台的,但是如果那不可能,那么我的主要开发目标是linux

7
onKeyDown事件不适用于React中的div
我想在React中的div上使用keyDown事件。我做: componentWillMount() { document.addEventListener("keydown", this.onKeyPressed.bind(this)); } componentWillUnmount() { document.removeEventListener("keydown", this.onKeyPressed.bind(this)); } onKeyPressed(e) { console.log(e.keyCode); } render() { let player = this.props.boards.dungeons[this.props.boards.currentBoard].player; return ( <div className="player" style={{ position: "absolute" }} onKeyDown={this.onKeyPressed} // not working > <div className="light-circle"> <div className="image-wrapper"> <img src={IMG_URL+player.img} /> </div> </div> </div> ) } 它工作正常,但我想以React风格做更多。我试过了 onKeyDown={this.onKeyPressed} 在组件上。但是它没有反应。我记得它在输入元素上起作用。 码笔 …

11
停止输入/书写后如何触发输入文本中的事件?
我想在我停止在输入文本框中键入(而不是在键入时)字符之后触发事件。 我尝试过: $('input#username').keypress(function() { var _this = $(this); // copy of this object for further usage setTimeout(function() { $.post('/ajax/fetch', { type: 'username', value: _this.val() }, function(data) { if(!data.success) { // continue working } else { // throw an error } }, 'json'); }, 3000); }); 但是此示例为每个键入的字符产生超时,如果输入20个字符,我将收到20个AJAX请求。 在这个小提琴上,我用简单的警报而不是AJAX演示了相同的问题。 有没有解决的办法,或者我只是用一种不好的方法呢?

6
jQuery按键箭头键
我正在尝试捕获jQuery中的箭头按键,但是没有事件被触发。 $(function(){ $('html').keypress(function(e){ console.log(e); }); }); 这会为字母数字键生成事件,但是删除,箭头键等不会生成事件。 我没有抓到这些错在做什么?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.