-2

I need a real, keyboard press simulation.Not one that is only selector specific. I need a way to simulate an actual enter button press on the keyboard, in JavaScript. This way the enter press will work the same every where i decide to trigger it , hence making it an actual enter button on a keyboard, simulation. Please help :) (I am using this in imacros and recording wont cut it because it is specific and not universal)

  • 1
    Can you provide some detail / context about what it is you are trying to do with this? If this is for testing, you may want to consider using a more realistic test environment like Selenium Webdriver. – Michael Aaron Safyan Aug 21 '16 at 05:57
  • Hello, I hope you are not the down voter. :D " I need a way to simulate an actual enter button press on the keyboard, in JavaScript" i am trying to build a keyboard that only has an enter button. :D – Roboman7 Aug 21 '16 at 06:05
  • Nope, wasn't the downvoter. For a fake keyboard, since you probably have the input element handy that you are appending characters to, I would suggest simply calling the "click()" function on that input element. If you don't already have that element, document.activeElement may help. – Michael Aaron Safyan Aug 21 '16 at 14:36

1 Answers1

0

For security reasons, browsers won't allow you to simply simulate the pressing of a key from a browser context. If this were possible, then a user could load a web page and the javascript on the web page could take over the keyboard and do nasty things to the computer.

For a more detailed explanation, as well as some alternatives, see this post.

Community
  • 1
  • 1
BobRodes
  • 5,990
  • 2
  • 24
  • 26