Keyboard and IME events
Sees every key pressed while the page has focus, plus IME composition text.
In one line
Can see each key you press while the page has focus
Sees every key pressed while the page has focus, plus IME composition text.
A page that has focus gets each keydown with the key and its physical code, and exact timing. Typing rhythm can identify a person; composition events reveal the language they type in.
What it can and can't do
What the user does: Nothing. It happens as you type while the page is open and in front
It can
- See which key you pressed and the exact time
- Tell the difference between a typed letter and a shortcut like Ctrl plus C
- Learn your typing rhythm, which can help tell people apart
- See text from input method editors, which can show the language you type in
It cannot
- See keys pressed in other tabs or other apps
- See anything while the page is in the background
- Show a permission pop up; there is none
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 1 | 2008-12-11 | None |
| Edge | Supported | 12 | 2015-07-29 | None |
| Firefox | Supported | 1.5 | 2005-11-29 | None |
| Safari | Supported | 1.2 | 2004-02-02 | None |
| Safari on iPhone | Supported | 1 | 2007-06-29 | All iOS browsers use WebKit |
| Chrome on Android | Supported | 18 | 2012-06-27 | None |
| Samsung Internet | Supported | 1.0 | 2013-04-27 | None |
How a site asks for it
| API | keydown, keyup, beforeinput, input, compositionstart/update/end; KeyboardEvent.key, .code, .timeStamp |
| Browser compat keys | api.KeyboardEventapi.InputEventapi.CompositionEvent |
| How access is granted | none |
| What the user sees | None (no browser prompt) |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| Activation | none |
| How long it lasts | While the document has focus |
| How to take it back | Nothing to revoke (no permission is stored) |
| Inside an iframe | Keys go to the focused frame only; cross-origin iframes do not leak keys to the parent |
Typical flow
- Person types in the page
- keydown and input events fire
- Page reads key, code, isComposing and data
Data you get
What comes back: Key events with timestamps
Shape: event
How often: per keystroke
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
key | string | None | character or named key | exact |
code | string | None | physical key position | exact |
timeStamp | float | ms | from page load | 100 us in Chrome, about 1 ms in Firefox and Safari |
Technical limits
- No key events for text typed in other tabs, apps, the address bar or OS dialogs
- Event timeStamp is a DOMHighResTimeStamp: 100 microseconds in Chrome, coarser in Firefox and Safari (about 1 ms)
- Password fields still fire keydown (the page owner can read what is typed there)
- During IME composition keydown carries key Process (keyCode 229); the composed text comes through compositionend and beforeinput
- Browsers cannot hide key timing; keystroke dynamics identify users at roughly 1 to 5 percent equal error rate in research
The story
What it is
The page sees every key you press while it is focused, including timing.
For you
You press keys and the page reacts: a game character moves, a shortcut opens a menu, a search box suggests words. You do not see that each key and its exact timing was noticed. The page only sees keys while it is the active window.
For makers
Keys drive games, shortcuts, forms and chat. Makers also use typing speed and rhythm for fraud and bot checks, and some analytics tools record keystrokes in forms.
Where you see it
| Type | Example | Apps |
|---|---|---|
| games | A browser shooter reads WASD, space and shift every frame so your character moves and jumps. | Krunker.io, Slither.io |
| games | A cloud gaming site such as GeForce NOW sends each key press to the remote machine to play a PC game in the browser. | GeForce NOW, Xbox Cloud Gaming |
| creative | A design tool uses key shortcuts such as V for move and Space to pan. | Figma, Canva |
| banking | A bank login checks typing rhythm to judge whether the same person is typing as always. | None named |
| analytics | A session recording tool replays how visitors typed in a form and where they gave up. | Hotjar, FullStory |
| security | A bot detector flags forms filled in perfectly even typing speed with no pauses. | None named |
| accessibility | A web app offers keyboard only control for people who cannot use a mouse. | None named |
Risks
- Typing rhythm identifies people
- Keystrokes can be recorded
Good uses and abuse
Legitimate uses
- Games
- Shortcuts
- Rich editing
- Accessibility
Known abuse
- Keylogging typed form data in injected scripts
- Behavioral biometrics (typing cadence)
- Session replay capture of keystrokes
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 4 of 5 | How revealing the data is |
| Utility | 5 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | 5 | Rough identifying entropy, when known |
History
- 2016, Chrome 51: KeyboardEvent.code standardized in Chrome
- 2019-09, Chrome 77: beforeinput event with inputType values
Related capabilities
Related
- Keyboard layout map. Can learn which keyboard layout you use, such as QWERTY or AZERTY
- EditContext (custom text input). Can run its own text editor that still gets your keyboard and emoji input
Sources
How well checked: Based on official documentation.