[英]How can I make JavaScript press keys on the keyboard without me pressing them? js
Here's my code这是我的代码
window.addEventListener('keypress', mod, false);
window.addEventListener('keyup', mod, false);
function mod(i) {
var enter = 13;
if(i.keyCode === 49) {
//basically if key one is pressed then the enter key will be pressed without me touching the enter key
}
}
SOO, basically is what I'm trying to say is that if 1 is pressed on the keyboard, the enter key will be pressed. SOO,基本上就是我想说的是,如果在键盘上按下 1,则将按下回车键。 Please help, I've been trying to find solutions on this for a very long time
请帮忙,我一直在努力寻找解决方案很长时间
Take a look at this post about triggering keypress events programmatically.看看这篇关于以编程方式触发按键事件的帖子。 Basically, you will be able to pass a keyboard event into document.dispatchEvent() inside your if statement and it will trigger the keypress.
基本上,您将能够在 if 语句中将键盘事件传递给 document.dispatchEvent() ,它将触发按键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.