Home › Developer Tools › JavaScript Keycode Finder

JavaScript Keycode Finder

Press any key to see everything a JavaScript KeyboardEvent reports: event.key, event.code, the legacy keyCode and which, the key location and modifier state. Copy any value or a ready-made keydown handler, and look up common codes in the table below.

Press any key to get its JavaScript keycode

Click here first if nothing happens. On a phone, tap the box below to open the keyboard.

Shift Ctrl Alt Meta ⌘/⊞ Caps Lock

Code snippet


    

Event log

EventkeycodekeyCodeMods
Key presses appear here.

Key code reference

Keyevent.keyevent.codekeyCode

Click a row to copy its event.code. Firefox differs for ; (59), = (61) and - (173).

Advertisement
Advertisement

How to use the JavaScript Keycode Finder

  1. Press any key on your keyboard. The big number is the keyCode and the cards show every property of the event.
  2. Try combinations such as Shift+A or Ctrl+S: the modifier pills light up and event.key shows the resulting character.
  3. Click a card to copy its value, for example the event.code string.
  4. Copy the code snippet: choose whether to match by event.key or event.code and paste the handler into your project.
  5. Look up a key without pressing it by searching the reference table.

key, code, keyCode and which compared

PropertyWhat it tells youExample (Shift + 2 on a US keyboard)Status
event.keyThe character or key name produced, after layout and modifiers"@"Recommended
event.codeThe physical key, independent of layout"Digit2"Recommended
event.keyCodeA numeric code, mostly based on the unshifted key50Deprecated
event.whichSame as keyCode for keydown and keyup50Deprecated
event.location0 standard, 1 left, 2 right, 3 numpad0Current

Choosing key or code

Use event.key when the meaning matters: keyboard shortcuts such as Ctrl+S, closing a dialog with Escape, submitting with Enter, or reading typed characters. It respects the user's keyboard layout, so a French user pressing the key labelled "Z" gets "z".

Use event.code when the position matters: WASD movement in a game, piano or drum keys, or any layout where the physical arrangement is the point. On an AZERTY keyboard the WASD keys are labelled ZQSD but still report KeyW, KeyA, KeyS and KeyD.

Avoid keyCode and which in new code. They remain for old browsers and existing scripts, but values differ between browsers for some punctuation keys and are ambiguous for non-US layouts.

Common pitfalls

  • The space bar's event.key is a single space character " ", not "Space". Its event.code is "Space".
  • With Shift held, letter keys report an upper-case event.key ("A"), so compare with event.key.toLowerCase() for case-insensitive shortcuts.
  • On macOS use event.metaKey (⌘) where Windows and Linux use event.ctrlKey for shortcuts like save and copy.
  • The keypress event is deprecated. Use keydown for keys and the input event for text changes.
  • Check event.isComposing (or keyCode 229) to ignore key events while an input method is composing Chinese, Japanese or Korean text.

Frequently asked questions

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

event.key is the value the key produces, taking layout and modifiers into account: "a", "A", "Enter" or "é". event.code is the physical key position, independent of layout: the key next to Tab is always "KeyQ", even on an AZERTY keyboard where it types "a". Use key for text and shortcuts by character, code for game controls such as WASD.

Is keyCode deprecated?

Yes. keyCode and which are deprecated in the UI Events specification and their values vary between browsers and keyboard layouts. They still work in all browsers for compatibility, but new code should use event.key or event.code.

What is the keyCode for Enter, Escape and Space?

Enter is 13, Escape is 27, Space is 32, Tab is 9 and Backspace is 8. The arrow keys are 37 (left), 38 (up), 39 (right) and 40 (down). With modern code, compare event.key to "Enter", "Escape", " " (a space), "Tab" or "ArrowLeft".

Why do some keys show different keyCodes in Firefox?

A few punctuation keys differ: in Firefox semicolon is 59, equals is 61 and minus is 173, while Chrome, Edge and Safari use 186, 187 and 189. The Meta (Windows / Command) key is 91 in Chromium browsers and 224 in older Firefox versions. event.code avoids these differences.

What does event.location mean?

It tells you which copy of a key was pressed: 0 for a standard key, 1 for the left one (left Shift, Ctrl, Alt or Meta), 2 for the right one and 3 for the numeric keypad.

Why does my phone show keyCode 229 or "Unidentified"?

Many virtual keyboards on Android use an input method (IME) that reports keydown with keyCode 229 and key "Unidentified" while composing text. Listen to the input or beforeinput event to read the typed text on mobile.

Why can't I detect some keys like Fn or Print Screen?

The Fn key is handled inside the keyboard and never reaches the browser. Some keys and shortcuts are reserved by the operating system or browser, such as Print Screen on some systems, Ctrl+W or Alt+Tab, so a web page cannot receive or block them.

Related tools

Regex TesterTest and debug regular expressions live.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.HTML Entity Encoder / DecoderEscape and unescape HTML entities, named or numeric.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.Password GeneratorCreate strong passwords and passphrases.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Hash GeneratorGenerate MD5, SHA-1, SHA-256 and SHA-512 hashes of text or files.MD5 Hash GeneratorGenerate MD5 hashes of text, lines or files and verify checksums.SHA-256 Hash GeneratorSHA-256 and HMAC-SHA256 hashes of text, lines or files, in hex or Base64.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.Base64 Encoder DecoderEncode or decode Base64 text and files, and make data URIs.URL Encoder DecoderPercent-encode or decode URLs, query strings and form data.XML FormatterBeautify, validate and minify XML with a collapsible tree view.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.ZIP File CreatorCompress files and folders into a ZIP.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.Bcrypt Hash Generator & CheckerCreate bcrypt password hashes and check a password against a hash.UTM Campaign URL BuilderAdd UTM tracking parameters to links and make a QR code.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Meta Tag GeneratorCreate SEO, Open Graph and X meta tags with live previews.Robots.txt GeneratorBuild a robots.txt file with rules, sitemap lines and AI-bot blocking presets.Sitemap GeneratorTurn a list of URLs into a valid XML sitemap file.Open Graph PreviewPaste OG tags and preview how links look on Facebook, X and LinkedIn.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Binary TranslatorConvert text to binary, hex, octal and back.Email ValidatorCheck email lists and spot disposable addresses.Website Down CheckerCheck if a website is down for everyone.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.File Info ViewerCheck file size, type, date and MD5/SHA hashes.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.Deep Link GeneratorCreate links that open directly in apps.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.HMAC GeneratorGenerate and verify HMAC signatures with SHA-256, SHA-512, SHA-1 or MD5.URL ParserBreak a URL into its parts and edit query string parameters with a live rebuild.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.CRC32 Checksum CalculatorCalculate CRC-32, CRC-32C, CRC-16 and Adler-32 checksums of text or large files.User Agent ParserSee your user agent and parse any UA string into browser, OS, engine and device.YouTube Embed Code GeneratorCreate responsive YouTube embed code with start time, autoplay, loop and privacy mode.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JWT DecoderDecode JSON Web Tokens, read the claims and expiry, and verify HS256 signatures.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.JWT GeneratorCreate and sign HS256, HS384 or HS512 JSON Web Tokens in your browser and verify them.What Is My BrowserSee your browser, version, OS, engine, screen and which web features it supports.Font ViewerPreview TTF, OTF, WOFF and WOFF2 fonts with sample text, waterfall, glyphs and metadata.Markdown EditorWrite Markdown with a toolbar, live split preview, autosave and .md or HTML export.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.HTTP Status CodesSearch every HTTP status code with plain-English meanings, causes, fixes and RFC references.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.Password Strength CheckerSee how strong a password really is, how long it takes to crack and how to improve it.Subnet CalculatorCalculate IPv4 network, broadcast, host range, masks and host count, and split subnets.SERP Snippet PreviewPreview your title tag and meta description with pixel-accurate truncation on desktop and mobile.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.Caesar CipherEncode and decode Caesar shift ciphers and crack unknown shifts with a ranked brute force.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.Vigenère CipherEncrypt and decrypt Vigenère and Autokey ciphers, and crack unknown keys with frequency analysis.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Atbash CipherEncode and decode Atbash ciphers (A↔Z, B↔Y) in Latin or Hebrew, with a live letter mapping table.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.Bulk URL OpenerOpen a list of URLs in new tabs at once or in batches, with cleanup, dedupe and delay.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.Hreflang Tag GeneratorCreate hreflang tags, sitemap entries and Link headers for every language and region, validated.ASCII TableFull ASCII code chart 0–255 in decimal, hex, octal, binary and HTML, with search and copy.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.Canonical Tag GeneratorNormalize URLs and create rel=canonical tags and HTTP headers, for one page or a whole list.Unicode Character LookupFind Unicode characters by name or code point and copy them with UTF-8, HTML and code escapes.CSS Flexbox GeneratorBuild flexbox layouts visually: set container and item properties, then copy the CSS and HTML.Twitter Card GeneratorCreate X / Twitter Card meta tags with Open Graph fallbacks, character counters and a live preview.Punycode ConverterConvert international domain names, emails and URLs between Unicode and xn-- Punycode, in bulk.CSS Grid GeneratorDraw CSS grid layouts: set tracks and gaps, drag to name areas, then copy the CSS and HTML.PX to REM ConverterConvert px to rem or em and back, with a 1-100px table and a whole-CSS converter.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON Escape / UnescapeEscape text for a JSON string, unescape \n and \" back to text, or stringify a whole object.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.Glassmorphism CSS GeneratorDesign frosted-glass UI cards with blur, transparency and border sliders, then copy the CSS.CSS Text Shadow GeneratorLayer CSS text shadows with a live preview and neon, 3D, outline and retro presets.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.DNS LookupLook up A, AAAA, MX, TXT, NS, CNAME, SOA and CAA records with TTLs over secure DNS.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Binary to HexConvert binary to hex instantly with steps and signed mode.Hex to BinaryConvert hex to binary instantly with steps and signed mode.