Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track modifier keys using javascript/jquery?

My requirement is just easy: user press Ctrl key some notification appear on my page, and when released the notifications just disappear, so i need to track modifier keys such as Ctrl. Unfortunately i google and didn't find any clues, some famous keyboard libs such as Mousetrap and keymaster seem also does not cover this topic.

Any ideas?

like image 520
Mike Avatar asked Mar 23 '13 04:03

Mike


1 Answers

Modifier keys trigger keydown (but not keypress). Then you can simply check the flags defined on the event object. shiftKey, altKey, ctrlKey, metaKey, etc.

A full list is here: http://api.jquery.com/category/events/event-object/

like image 182
Dave Avatar answered Oct 07 '22 22:10

Dave