Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

665
Views
Simulate keypress (ctrl+v) and send the KeyboardEvent to a div in Angular2 or JavaScript

I have a div:

<div class="paste-area-content"
  #pasteDiv contenteditable="true" 
  (paste)="onPaste($event)"
  (input)="unsupportedBrowserPaste()">
</div>

If the focus is on it and I press Ctrl+V, then call the onPaste function with a ClipboardEvent and etc., the picture from the clipboard appears in the div.

Now I'd like to use a <button> to do the same process. So I thought I'd simulate the keypress when the button is clicked, and send the KeyboardEvent to the div.

I tried a lot of similar solutions but none of them worked or they are just deprecated. The last try was:

var event = new KeyboardEvent('keypress', {
  bubbles: true,
  cancelable: true,
  ctrlKey: true,
  key : "v",
  code : "86"
});
this.printedArticleImagePasteComponent.simulatePaste(event);

public simulatePaste(event: KeyboardEvent) {
  this.pasteDiv.nativeElement.dispatchEvent(event);
}

It doesn't work of course. How is it possible to solve this?

The second idea was: get the picture from the clipboard, create a ClipboardEvent manually, set the ClipboardEvent.clipboardData.items. But window.clipboardData.getData doesn't work.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!