Toolvist

Probador de keycodes de JavaScript

Pulsa cualquier tecla y ve al instante su keyCode, code y key de JavaScript. Probador de keycodes online para crear atajos y manejadores de teclado.

event.key
—
event.code
—
keyCode
—
which
—
Desplazamiento Ctrl Alt Meta

Probador de keycodes de JavaScript gratuito

El probador de keycodes muestra la key, el code y el keyCode de cualquier tecla que pulses. Haz clic en el cuadro y escribe: los detalles del evento aparecen al instante para usarlos en tu JavaScript.

The values it reports are the ones a JavaScript Minifier leaves untouched, and the handler logic around them can be compared with the Diff Checker / Text Compare. For the escape sequences that keyboard events produce, the String Escape / Stringify tool shows the literal forms.

Cómo usar Probador de keycodes

  1. 1 Click into the input area to give it focus.
  2. 2 Press any key. The event details appear immediately.
  3. 3 Read three separate values: `key`, `code` and, for legacy purposes, `keyCode`.
  4. 4 Hold modifiers to see how they are reported alongside the key.

Cómo usarlo

Enfoca el área de entrada y pulsa cualquier tecla. Verás event.key, event.code, event.keyCode y qué teclas modificadoras están pulsadas.

  • Muestra key, code y keyCode
  • Detecta Shift, Ctrl, Alt y Meta
  • Muy práctico para configurar manejadores de eventos de teclado

Preguntas frecuentes

What is the difference between `key` and `code`?

`key` describes what the key produces — the character, taking modifiers and the keyboard layout into account. `code` describes the physical key at a fixed position, independent of layout. So `key` equals `a`, `A` or `á` depending on the layout and the shift state, while `code` is always `KeyA` for that physical key.

Which one should I use in my code?

`code` for anything positional, such as a game where WASD should map to the same physical keys regardless of layout, and `key` for anything about the character produced. `keyCode` is deprecated and should not be used in new code — it is inconsistent between browsers and was never standardised.

Why does my handler not fire for some keys?

Because certain keys are intercepted by the browser or the operating system before the page sees them. Function keys, the browser's own shortcuts, and combinations such as closing a tab cannot be suppressed reliably. Design around those rather than fighting them.

Herramientas para desarrolladores relacionadas

Ver todo en Herramientas para desarrolladores →