5

Hi want to simulate the press of the keys CTRL+F1 when i do click on a button. For example:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.js">
        function simulateKeyPress(){

        }
    </script>

    <button class="boton3d" onclick="simulateKeyPress()"> 
           <img src="img/phone.png">       
    </button> 

Thanks...

Subodh Ghulaxe
  • 18,333
  • 14
  • 83
  • 102
Victtor888
  • 61
  • 1
  • 1
  • 3
  • 3
    Have you googled? http://stackoverflow.com/questions/596481/simulate-javascript-key-events – Satpal Feb 24 '14 at 08:21

2 Answers2

3

You can try:

  var e = jQuery.Event("keydown");
  e.which = 112;       // # F1 code value
  e.ctrlkey = true;     // control key pressed
  $(document).trigger(e);// trigger event on document
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
1

you can use .keypress method : doc

Sample :

$("#MyDiv").keypress();

Will trigger a keypress on #MyDiv. If you'd like to also select which key was pressed, you can use .trigger : doc

var e = $.Event("keydown", { keyCode: 112}); 
$("body").trigger(e);

you can find all the key here : http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

hope this help you.

Francois Borgies
  • 2,378
  • 31
  • 38
  • Thanks, but i need simulate that when i do a click on the button simulate the press of the keys CTRl+F1 in the os Windows. And your solution i understand that is for throught an event when you press any key. – Victtor888 Feb 24 '14 at 09:05
  • here also not working – Thielicious Aug 16 '17 at 12:10