How to trigger f11 keyboard event using javascript or jquery?

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

+6
source share
4 answers
+8
source

You cannot force computer users to enter things through javascript. This violates the sandbox environment of browsers. I assume that you are trying to make the window full screen. This SO question covers this.

How to make a full-screen window using Javascript (stretch across the screen)

+4
source

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

Call this function whenever you press a button or event that we select.

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); } 

Note: this is a Javascript function and jQuery is not required to support it.

0
source

Example working code:

 document.addEventListener("keyup", keyUpTextField, false); function keyUpTextField (e) { var keyCode = e.keyCode; if(keyCode==122){/*ejecutaAlgo*/} } 
-2
source

Source: https://habr.com/ru/post/902280/


All Articles