keecode logokeecode

4

100

Number Pad 4

event.keyCode

100

event.key

4

event.code

Numpad4

Unicode

Code Examples

Copy and paste these examples to detect the 4 key in your JavaScript code

Recommended modern approach

// Modern approach (recommended)
document.addEventListener('keydown', (e) => {
  if (e.key === '4') {
    console.log('4 key pressed!');
    // Your code here
  }
});

Related Keys

Other keys commonly used together or in similar contexts