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