/    Sign up×
Community /Pin to ProfileBookmark

Hi folks,

I was wondering if there was a way to gather keystroke metrics in JS such as the timing between two consecutive key presses, the number of keys pressed at once, etc.

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@DokOct 11.2008 — timing between two consecutive key presses[/QUOTE]To record the time of each keystroke you can do
[CODE]var time = [];

document.onkeydown =
function(e) {
time.push(e.timeStamp)
};[/CODE]

This does not apply to IE. Timestamps for events are measured in milliseconds since boottime.
the number of keys pressed at once[/QUOTE]The browser only registers the first key you press no matter how many you press at a time except for the modifyer keys shift, alt and control.
Copy linkTweet thisAlerts:
@DokOct 11.2008 — To add support for IE
[CODE]document.onkeydown =
function(e) {
// If IE
if (!e)
time.push(new Date());
else
time.push(e.timeStamp)
};[/CODE]

Note that the timestamps in IE will be milliseconds since the Epoch (midnight, 1st of Jan. 1970)
Copy linkTweet thisAlerts:
@canadiancoderauthorOct 11.2008 — Thank you, that should get me started!
×

Success!

Help @canadiancoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...