如何使用Javascript模拟按键? [英] How to simulate keypress using Javascript?

查看:74
本文介绍了如何使用Javascript模拟按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用JavaScript模拟按键?例如,如何模拟Ctrl + Alt + ArrowKey?我想模拟特殊键.有没有可用的API/框架?

Is it possible to simulate key press using JavaScript? For example, How can I simulate Ctrl+Alt+ArrowKey? I want to simulate special keys. Is there any API/Framework available?

可以说,我正在构建基于Web的虚拟键盘.

Lets say, I am building a web based virtual keyboard.

推荐答案

如果您的目标是实现sendKeys函数(将击键直接发送到键盘缓冲区的函数)的浏览器模拟,那么您将无法实现这.在浏览器中触发按键事件会将事件发送到DOM处理程序,而不是键盘缓冲区.因此,要在浏览器中模拟实际的工作键盘并将笔画发送到键盘缓冲区是不可能的,而这不会造成浏览器进入操作系统的安全漏洞.

If your goal is to achieve a browser analog of a sendKeys function (a function where you send keystrokes directly to the keyboard buffer) then you will be unable to achieve this. Triggering key events in a browser sends events to DOM handlers not the keyboard buffer. For this reason simulating an actual working keyboard in the browser which sends strokes to the keyboard buffer is impossible without a security breaching hole from the browser into the OS.

这篇关于如何使用Javascript模拟按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆