javascript Chrome 扩展程序发送密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6296048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome Extension Send Key
提问by Hassan Voyeau
Is there a way to simulate a key press from a chrome extension? For example when I click the extension button I can specify that keys 'ABC' be sent to browser window.
有没有办法从 chrome 扩展程序模拟按键?例如,当我单击扩展按钮时,我可以指定将键“ABC”发送到浏览器窗口。
采纳答案by serg
Unfortunately no (it is a javascript problem, Chrome API doesn't provide any help).
不幸的是没有(这是一个 javascript 问题,Chrome API 不提供任何帮助)。
All you can do is dispatch a keypress event (see this questionfor example), but you can't emulate actual button press. If parent page listens to keypress events, then it will catch it (this event won't have all the info as a real button press event, so it might still not work), otherwise nothing would happen.
您所能做的就是发送一个按键事件(例如,请参阅此问题),但您无法模拟实际的按钮按下。如果父页面监听 keypress 事件,那么它会捕获它(这个事件不会将所有信息作为真正的按钮按下事件,所以它可能仍然不起作用),否则什么都不会发生。
回答by yonran
Right now, you have to read the HTML5 spec and simulate everything that the browser would do. Here was my last attempt at it.
现在,您必须阅读 HTML5 规范并模拟浏览器会执行的所有操作。这是我最后一次尝试。