0

I made a chrome extension and I'm trying to see if it's possible to simulate keys being pressed OR pasting the clipboard. I don't want to set the value of an element, and I'm not trying to detect keypresses. I just want it to perform the action of a key being pressed. I'm using jQuery as well, so feel free to use that if necessary.

I have tried almost all of the answers here and none worked: Is it possible to simulate key press events programmatically?

Help will be greatly appreciated!

Edit: Also, for some of these, I've been getting an error saying ".trigger is not a function"

Edit 2: According to this post, it sounds like the events thing I've been trying only triggers the event on the website if they're listening for it, but doesn't actually type the letter. Is that correct? Chrome Extension Send Key

1 Answers1

0

$(function() {
    var e = $.Event('keypress');
    e.which = 65; // Character 'A'
    $('.link').trigger(e);
});

$('.link').on('keypress',function(e){alert(JSON.stringify(e))})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="link">clickme</a>
Claytronicon
  • 1,437
  • 13
  • 14