µDOM/KB Keyboard Events Demo

µDOM/KB offers higher order keyboard event detection for specific keys.

All behaviors are boolean, i.e. their corresponding state is always true (on) or false (off).

Implemented behaviors include:

The callback associated with a given key and behavior will be called when the corresponding state has changed. They will be called with a single argument, a frozen object { keyname, behavior, state, event, }. The state attribute is either true or false; the event attribute contains the most recent event that triggered the event.

Browsers can only detect keyboard events while they are the focused (active) application (otherwise, each website in the world could be a potential key logger). Therefore, when you press keys such as Alt, Shift or CapsLock, there's no way to detect that (and update the below display) based on keyboard events unless this page is in focus. However, mouse events (and the more modern pointer events) are still detected as long as the mouse (pointer) is over the content section of the browser, and it turns out once you receive such a mouse event, you can query it for the modifier key status (and only the modifier keys such as Alt, AltGraph, Shift and so on).

Based on this, µDOM/KB offers Mouse-Based Modifier Change Detection (MBMCD). With MBMCD, you can receive events that detail changes in the current status of modifier keys; these then can be used to generate keydown and keyup events that work exactly as if you had pressed the respective keys with the application in focus.

The MBMCD switch below allows you to select whether to use mouse-based updates to the right-hand part of the table. The leftmost column (with rounded corners) always shows the effects of MBMCD events with a red border where a modifier is pressed, and a grey border when it is released. To observe the effect, focus the window of another application (or the browser's dev tools) and press a modifier key such as Control or Shift. Then, while holding that key, move the mouse pointer back. As soon as the mouse re-enters the content area, the respective cells will be updated as if the key action had just occurred. This feature, therefore, can make key-based state management a bit more reliable.

togglelatchptlatchtlatchntlatch
Alt Alt Alt Alt Alt Alt
AltGraph AltGraph AltGraph AltGraph AltGraph AltGraph
Control Control Control Control Control Control
Meta Meta Meta Meta Meta Meta
Shift Shift Shift Shift Shift Shift
CapsLock CapsLock CapsLock CapsLock CapsLock CapsLock
Space Space Space Space Space Space
y y y y y y
Y Y Y Y Y Y

Latest toggle event: