Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read keyboard state outside of keyboard event?

Is there a way to read keyboard state outside of a keyboard event handler? Specifically, I need to check if the shift key is down during page load. I am using jQuery.

like image 856
Landon Kuhn Avatar asked Feb 17 '11 23:02

Landon Kuhn


People also ask

What is e keycode === 13?

Keycode 13 is the Enter key.

How do keyboards handle events?

Handle single key events To handle an individual key press, implement onKeyDown() or onKeyUp() as appropriate. Usually, you should use onKeyUp() if you want to be sure that you receive only one event. If the user presses and holds the button, then onKeyDown() is called multiple times.

What is a key event in a text?

An event which indicates that a keystroke occurred in a component. This low-level event is generated by a component object (such as a text field) when a key is pressed, released, or typed.

Which event is generated when keyboard key is pressed?

The keydown event is fired when a key is pressed. Unlike the deprecated keypress event, the keydown event is fired for all keys, regardless of whether they produce a character value. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered.


1 Answers

There is no querying of keyboard state in JavaScript. Wish there was. You have listen to events and track state yourself.

like image 66
jpsimons Avatar answered Oct 17 '22 14:10

jpsimons