Skip to content

JavaScript Detect Keyboard current press using EventListener "keydown"

Notifications You must be signed in to change notification settings

nielsoffice/JSDetectKeyboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

JSDetect_Keyboard


JavaScript Detect Keyboard current press using EventListener "keydown"
Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event

   
   document.addEventListener('keydown', function (e) {

    // Detect which keyboard are currently press
    // Read the keyboard property { isTrusted: true, key: 'enter', code: 'keyEnter' }
    console.log(e);
    // access property via dot notation JS ex. e.key
    console.log(e.key);

    // Usage: 
    if(e.key === 'Escape') {
       console.log(e.key);
       // do something! ...
    }

   });
   


Also EventListener "Keyup"
Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Element/keyup_event

 // JavaScript Event
 https://developer.mozilla.org/en-US/docs/Web/Events

About

JavaScript Detect Keyboard current press using EventListener "keydown"

Topics

Resources

Stars

Watchers

Forks