Google文件模拟键盘 [英] Google Docs simulate keyboard
问题描述
我需要使用JavaScript在Google文档中模拟键盘,以便能够在光标位置上打印或擦除字符.
不幸的是,模拟按键事件的解决方案对我不起作用.我尝试了有无jQuery.
经过一番调查,我发现Google文档具有虚拟键盘.单击虚拟键可调用此功能:
I need to simulate keyboard in google docs with using JavaScript to be able print or erase characters on cursor position.
Unfortunately solutions with simulating keypress event didn't work for me. I tried with and without jQuery.
After some investigation I detected that Google Docs have virtual keyboard. Clicks on virtual keys calls this function:
C.MOa = function(a) {
this.dispatchEvent(new Q(Td, {keyCode: a}))
};
其中Td
是字符串"action",而Q
是一些Event类.
用Java脚本发送此事件的正确方法是什么?还有其他方法可以在Google文档中模拟键盘吗?
Where Td
is a string "action" and Q
some Event class.
What is the correct way to send this event with java script? Is there other ways to simulate keyboard in Google Docs?
推荐答案
像Google文档一样,似乎具有特殊的iframe来处理键盘事件.这里是它的内容:
Seems like Google Docs have special iframe to handle keyboard events. Here is it’s contents:
<html>
<head></head>
<body spellcheck="false" role="textbox" aria-label="Document content" contenteditable="true" style="background-color: transparent;"></body>
</html>
只需将键盘事件发送到此文档即可在Google文档上打印字符.
Just dispatch keyboard events to this document to print characters on google doc.
这篇关于Google文件模拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!