7

I want to trigger f11 event of keyboard using javascript or jquery, can anyone tell me how to do this ?

Ravinder Singh
  • 3,113
  • 6
  • 30
  • 46

5 Answers5

9

You can try using this one: http://andrew.hedges.name/experiments/fullscreen/

jacoor
  • 760
  • 5
  • 9
5

You can't make people's computers type things through javascript. It violates the sandboxing environment of browsers. I assume that you are trying to make a window go full screen though. This SO question covers that.

How to make the window full screen with Javascript (stretching all over the screen)

Community
  • 1
  • 1
mrtsherman
  • 39,342
  • 23
  • 87
  • 111
4

I'm use this code:

function go_full_screen(){
  var elem = document.documentElement;
  if (elem.requestFullscreen) {
    elem.requestFullscreen();
  } else if (elem.msRequestFullscreen) {
    elem.msRequestFullscreen();
  } else if (elem.mozRequestFullScreen) {
    elem.mozRequestFullScreen();
  } else if (elem.webkitRequestFullscreen) {
    elem.webkitRequestFullscreen();
  }
}
<a href="#" onClick="go_full_screen();">Full Screen / Compress Screen</a>
Santos L. Victor
  • 628
  • 8
  • 13
-1

To trigger event Keypress of F11 key like from keyboard, we need this..

Call this function on any event..

function mKeyF11(){
    var e = new Event('keypress');
    e.which = 122; // Character F11 equivalent.
    e.altKey=false;
    e.ctrlKey=false;
    e.shiftKey=false;
    e.metaKey=false;
    e.bubbles=true;
    document.dispatchEvent(e);
}

This is pure Javascript function and don't need jQuery to support it..

Update: Chrome prevents JavaScript key-press. Source

For chrome we can use the following.

if (document.documentElement.webkitRequestFullscreen) {
    document.documentElement.webkitRequestFullscreen();
}
MarmiK
  • 5,639
  • 6
  • 40
  • 49
-3

Working code sample:

document.addEventListener("keyup", keyUpTextField, false);
function keyUpTextField (e) 
{
    var keyCode = e.keyCode;
    if(keyCode==122){/*ejecutaAlgo*/}
}   
Michał
  • 2,456
  • 4
  • 26
  • 33