Google Docs simulates a keyboard

I need to simulate a keyboard in google docs using JavaScript in order to be able to print or erase characters at the cursor position.
Unfortunately, solutions with simulated keypress event did not work for me. I've tried with and without jQuery.
After some investigation, I found that there is a virtual keyboard in Google Docs. Pressing the virtual keys calls this function:

C.MOa = function(a) {
  this.dispatchEvent(new Q(Td, {keyCode: a}))
};

      

Where Td

is the string "action" and Q

some class of event.
What is the correct way to send this event using a java script? Are there other ways to simulate keyboard in Google Docs?

+3


source to share


1 answer


It seems that Google Docs has a dedicated iframe to handle keyboard events. Here are its contents:

<html>
    <head></head>
    <body spellcheck="false" role="textbox" aria-label="Document content" contenteditable="true" style="background-color: transparent;"></body>
</html>

      



Just send keyboard events to this doc to print characters in google doc.

+1


source







All Articles