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.

Last updated:

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.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

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.Trackpad Gesture TestTest pinch zoom, two-finger scroll, swipes, force click and wheel delta modes live.Online Python CompilerRun Python 3 in your browser with input(), numpy, pandas, charts and share links.JSON EditorEdit JSON in a tree and as code side by side: add, rename, drag, change types, undo and download.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.File Info ViewerCheck file size, type, date and MD5/SHA hashes.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.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.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.RAID CalculatorUsable capacity, efficiency and fault tolerance for RAID 0, 1, 5, 6, 10, 50 and 60 arrays.JSONPath TesterTest JSONPath expressions live: filters, slices, wildcards and recursive search, with matches highlighted.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.Country Codes ListSearch ISO 3166 alpha-2, alpha-3 and numeric country codes with calling codes and TLDs.CSS Selector TesterTest CSS selectors on your HTML: highlighted matches, match count and specificity.Git Cheat SheetSearchable Git command reference by task, with copy buttons and an undo/rename/fix wizard.HAR File ViewerOpen a .har file to see a waterfall timeline, headers, bodies, timings and size totals.jq PlaygroundRun jq filters on JSON in your browser with live output, flags and an example library.Markdown Cheat SheetInteractive Markdown syntax reference: edit every example and see the live rendered preview.Regex ExplainerPaste a regular expression and get a plain-English breakdown, railroad diagram and flag notes.XPath TesterTest XPath expressions on XML or HTML: highlighted matches, node paths, values and examples.EML File ViewerOpen .eml email files to read the message, headers and raw source and save attachments.Graphviz Online ViewerWrite Graphviz DOT code and render graphs live; switch layout engines, export SVG or PNG.JavaScript Online CompilerWrite and run JavaScript in your browser with a console, timing, error lines and share links.Jupyter Notebook ViewerOpen .ipynb files and read code, Markdown, math, tables, plots and errors without Python.LaTeX Table GeneratorEdit a table like a spreadsheet or paste from Excel and get LaTeX tabular or booktabs code.Log File ViewerOpen huge log files with level colors, regex and time filters, JSON pretty-print and tail -f.Logic Gate SimulatorBuild logic circuits with AND, OR, NOT, XOR gates and flip-flops; see live outputs and truth tables.MSG File ViewerOpen Outlook .msg emails in your browser: sender, recipients, body, headers and attachments.Online Code EditorVS Code-style editor in your browser: tabs, 50+ languages, find/replace, autosave.ASCII Diagram EditorDraw boxes, arrows and text on a character grid and copy plain-text diagrams for code and READMEs.DBF File ViewerOpen dBase .dbf files and shapefile tables, search and sort records, export CSV or XLSX.MBOX File ViewerOpen .mbox mail archives: list and search messages, read them, save attachments, export EML.MDB File ViewerOpen Access .mdb and .accdb databases in your browser: list tables, view rows, export CSV.Shapefile ViewerView zipped shapefiles on a map with the attribute table, then export to GeoJSON or CSV.Online Hex EditorOpen any file as hex and ASCII, edit bytes, search, inspect values and save the result.PHP Online CompilerRun PHP 8 code in your browser with output, HTML preview, error lines and share links.PlantUML EditorWrite PlantUML and see sequence, class, activity and more diagrams live. Export SVG or PNG.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.Lottie ViewerOpen Lottie JSON or .lottie files to play, pause, scrub frames, change speed and see details.Diff ViewerPaste a git diff or .patch file and view it side by side or inline, with file navigation.EditorConfig GeneratorBuild an .editorconfig with indent, charset, line endings and trim rules per file pattern.Folder Compare ToolCompare two folders by file list, size and SHA-256 hash, then open a text diff of changed files.Glob Pattern TesterTest glob patterns like **/*.js, {a,b} and !exclusions against a list of file paths.JMESPath TesterEvaluate JMESPath expressions against JSON live, the query language used by the AWS CLI.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.Semantic Version CalculatorBump, compare, sort and test SemVer versions against npm ^, ~ and x ranges.XSLT TesterRun an XSLT 1.0 stylesheet on XML in your browser and see the output as HTML, XML or text.
See all 53 Code Playgrounds & Testers →