1

so I want to simulate the key combo Shift+Home via javascript. I want that key combo effect to be applied in a input box so the text inside it will be highlighted(but that isn't happening)...

<!DOCTYPE html>
<html>

<input type = text id="BLAH" value="Hello">
<script>

var e= document.createEvent("KeyboardEvent"); 
e.initKeyEvent("keydown", true, true, null , false, false, true, false, 36, 0);
document.getElementById("BLAH").dispatchEvent(e);

</script>
</html>

What am I doing wrong? (I am using Firefox, that's why I use initKeyEvent and not InitKeyboardEvent)

misticone
  • 11
  • 4
  • You can achieve this with javascript without simulating user keypresses. http://stackoverflow.com/questions/4067469/selecting-all-text-in-html-text-input-when-clicked – Håken Lid Aug 05 '15 at 21:40
  • 1
    I know that I can but I really need it to be done this way. – misticone Aug 05 '15 at 21:54
  • Did you happen to figure it out? [I'm stuck in a very similar issue](http://discourse.codenewbie.org/t/figuring-out-how-to-simulate-key-press-on-jsnes/1352). – cregox Nov 16 '15 at 15:10

0 Answers0