Favorites

JavaScript Key Code and Event Inspector

Find the key code of any key and see exactly what JavaScript receives. Press a key to get its event.key, event.code and the older keyCode, along with which modifier keys are held, where the key is on the keyboard and whether it’s repeating, plus a ready-to-copy event listener for it.

Switch to Mouse & pointer and click, right-click, scroll, drag or touch the test area to see every coordinate, button, pressure and tilt value, and watch the event log to learn the order events fire in, from pointerdown through mousedown to click. It works with a mouse, a touchscreen or a pen, and everything stays in your browser.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Press any key Click here first if nothing happens.

    Event properties

    Click a value to copy it

    JavaScript

    Event
    Match by
    
    		

    Event log

    Press a key or use the test area, and events appear here, newest first.

      For every on… attribute you can use in HTML, see HTML Event Attributes.

      ☕
      Enjoying this site?

      Help keep it running with a small coffee donation. Every bit of support is appreciated!

      Buy us a coffee

      About this tool

      key, code or keyCode?

      • event.key is what the key means: the character typed, such as 'a' or 'A', or a name such as 'Enter'. Use it for shortcuts and typed text.
      • event.code is the physical key, such as 'KeyA', and stays the same on every keyboard layout. Use it for games, where WASD should be in the same place for everyone.
      • keyCode and which are deprecated numbers. They still work, but they differ between browsers and layouts, so new code should use key or code.

      Common key codes

      keycodekeyCode
      EnterEnter13
      EscapeEscape27
      " " (Space)Space32
      TabTab9
      BackspaceBackspace8
      DeleteDelete46
      ArrowLeftArrowLeft37
      ArrowUpArrowUp38
      ArrowRightArrowRight39
      ArrowDownArrowDown40
      ShiftShiftLeft / ShiftRight16
      ControlControlLeft / ControlRight17
      AltAltLeft / AltRight18
      MetaMetaLeft / MetaRight91
      a / AKeyA65
      z / ZKeyZ90
      0Digit048
      9Digit957
      F1F1112
      F12F12123

      The order mouse events fire in

      A single click with a mouse fires this sequence, which you can watch in the event log:

      pointerdown → mousedown → pointerup → mouseup → click

      On a touchscreen, the touchstart and touchend events come first, and the mouse events and click follow after the finger lifts, for compatibility with older sites. A right-click adds contextmenu, and a second quick click adds dblclick.

      Pointer events: one API for every device

      Pointer events cover a mouse, a pen and every finger on a touchscreen, so you only need one set of listeners. pointerType tells you which device it was, pointerId tells fingers apart, and pens add pressure, tiltX and tiltY.

      area.addEventListener('pointerdown', (event) => {
        area.setPointerCapture(event.pointerId);
      });

      For drag-and-drop or drawing, add touch-action: none to the element in CSS so the browser doesn’t scroll instead.

      Frequently Asked Questions

      How do I find the key code for a key in JavaScript?

      Click the capture area on the Keyboard tab and press the key. The tool shows its event.key, event.code and the older keyCode number, along with the modifier keys and a ready-made addEventListener snippet you can copy.

      What’s the difference between event.key and event.code?

      event.key is the character or meaning of the key, so it changes with Shift and with the keyboard layout: the same key gives 'q' on an English keyboard and 'a' on a French one. event.code is the physical key, so it’s 'KeyQ' on both. Use key for shortcuts and text, and code when the position of the key matters, as in games.

      Is keyCode deprecated?

      Yes. keyCode, which and charCode are deprecated because their values differ between browsers, operating systems and keyboard layouts. Browsers still support them for older sites, but new code should use event.key or event.code.

      Why does event.key show ‘Process’ or keyCode 229?

      An input method editor (IME), such as the ones used to type Chinese, Japanese or Korean, or some mobile keyboards, is handling the key press. While it’s composing text, event.isComposing is true, and you should usually ignore those key events.

      How do I detect a keyboard shortcut such as Ctrl + S?

      Listen for keydown and check both the modifier and the key: if ((event.ctrlKey || event.metaKey) && event.key === 's'). Checking metaKey as well makes it work with ⌘ on a Mac. Call event.preventDefault() to stop the browser’s own Save dialog. Press the shortcut here to get the code.

      Why can’t I detect some key combinations?

      Some shortcuts are handled by the operating system or the browser before the page sees them, such as Ctrl + W, Ctrl + Tab, Alt + Tab or the Windows key on its own, so no event reaches JavaScript. Some keyboards also can’t report certain combinations of keys pressed at the same time.

      What is the difference between button and buttons?

      event.button is the single button that was pressed or released: 0 for the main (usually left) button, 1 for the middle, 2 for the right, 3 for back and 4 for forward. event.buttons lists every button held down at that moment as a sum of flags: 1 left, 2 right, 4 middle, 8 back and 16 forward. Use buttons during a pointermove to tell whether the user is dragging.

      What is the difference between clientX, pageX, offsetX and screenX?

      They measure the same point from different places. clientX is from the left of the browser window, pageX is from the left of the whole page including any scrolling, offsetX is from the left of the element itself, and screenX is from the left of your screen. The Y versions work the same way from the top.

      Should I use mouse events or pointer events?

      Use pointer events for new code. They work with a mouse, a pen and touch through the same listeners, add details such as pressure and tilt, and support pointer capture for dragging. Mouse events still fire after pointer events, so older code keeps working.

      Is anything I type sent anywhere?

      No. The tool only reads events in your browser to show them on the page, and nothing is sent to a server or stored, apart from your settings, which are kept in your browser.

      ☕
      Enjoying this site?

      Help keep it running with a small coffee donation. Every bit of support is appreciated!

      Buy us a coffee