2
98
Number Pad 2
event.keyCode
98
event.key
2
event.code
Numpad2
Unicode
②
Code Examples
Copy and paste these examples to detect the 2 key in your JavaScript code
Recommended modern approach
// Modern approach (recommended)
document.addEventListener('keydown', (e) => {
if (e.key === '2') {
console.log('2 key pressed!');
// Your code here
}
});Related Keys
Other keys commonly used together or in similar contexts