I want to simulate keypresses in Javascript. There are no listener for those key presses. For example: The function will trigger key '32' (spacebar) and this should result in scrolling of page like pressing normal spacebar.
I tried keypress trigger from Simulating a Keypress Event from Javascript Console but it didn't worked.
Edit
Key presses are not limited to spacebar only. It can be combined keys like alt+Ctrl+D and the browser should respond to them like keypresses from physical keyboard.
If you're only looking to scroll the document, you can approximate a Spacebar or Pg Dn scroll by using 85% of window.innerHeight - no jQuery needed:
window.scrollBy(0, window.innerHeight * .85);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With