Sandah Aung Sandah Aung - 1 year ago 59
HTML Question

Text input to web page without text fields

Can a web page detect keyboard input without text input fields or with text input fields unfocused?

Answer Source

add an event listener to the document (run the example, and click on it to activate it, otherwise its document won't have the focus, this is intended to work on a standalone page rather than embedded frame)

document.addEventListener('keydown', keydownCallback, false);

function keydownCallback(e) {
  console.log(e.keyCode + ': "' + String.fromCharCode(e.keyCode) + '"');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download