100% In-Browser Execution

JavaScript Keycode Info

Press any key to get its JavaScript event codes.

Checking access...

Share this tool

Unlock Keyboard Events: The Keycode Info Tool

Introduction

Building an interactive web application often requires responding to user keyboard input. But did you know that every key you press sends a specific numerical code to the browser? Guessing these codes is frustrating and time-consuming. Whether you are building a complex web game, custom shortcuts, or accessibility features, knowing the exact keycode is essential.

What is this tool?

A Keycode Info tool is an interactive utility for developers that captures keyboard events and displays the corresponding JavaScript keycodes, key names, and event properties. By simply pressing any key on your keyboard, the tool instantly reveals data such as event.key, event.code, event.which, and event.keyCode.

Step-by-Step Guide on how to use it

  1. Open the Tool: Navigate to the Keycode Info interface.
  2. Press a Key: Strike any key on your physical keyboard.
  3. Analyze the Output: The screen will instantly display a large primary number (the traditional keycode).
  4. Inspect Properties: Look at the detailed table to find specific event properties like key (e.g., “Enter”), code (e.g., “Enter”), and whether modifier keys (Shift, Ctrl, Alt) were active during the press.
  5. Implement: Use these exact string values or numbers in your JavaScript event listeners (e.g., if(event.key === 'Enter') { ... }).

Practical Use Cases

  • Game Development: Mapping W, A, S, D or arrow keys to character movement in a web-based game.
  • Custom Hotkeys: Creating productivity shortcuts in a web app (e.g., pressing Ctrl + K to open a search bar).
  • Accessibility: Ensuring custom UI components like modals or dropdowns can be properly closed using the Escape key.

FAQ

Why are event.keyCode and event.which deprecated?

Modern web standards favor event.key and event.code because they are more reliable across different keyboard layouts and languages, whereas keyCode is inconsistent and heavily tied to physical layouts.

What is the difference between event.key and event.code?

event.key represents the actual character or action produced (e.g., ‘a’ or ‘A’ depending on Shift). event.code represents the physical physical key on the keyboard, regardless of language layout or modifier keys.

Can it detect modifier keys?

Yes, a good keycode tool will tell you if event.shiftKey, event.ctrlKey, event.altKey, or event.metaKey were true when the main key was pressed.

Related Dev-coding Tools Tools