Skip to content
Advertisement

Detect keypress combination series with Javascript

For the Easter holiday, I’m wanting to have a little surprise “Easter Egg Hunt” on a site I develop for. Two of these five Easter Eggs I’m hiding will be keypress ordained. This won’t be like a “Press CTRL and TAB at the same time” type deal but will be a “Pres UP three times and then RIGHT three times” type of thing. This will be looking for a series of keypresses instead of just two pressed at once. I’ve got this function set up, but for some odd reason it isn’t working like it should.

NOTE: The script below is looking for the following keypress series:
surprise1 – LEFT (x3), RIGHT (x3), UP (x3), DOWN (x3)
surprise2 – SHIFT (x3), TAB (x3), CTRL (x3)

JavaScript

Mind telling me exactly as to why that isn’t working? It seems like to me it should work.

Advertisement

Answer

Try this: I’m using https://github.com/madrobby/keymaster jquery plugin

JavaScript

Demo: http://jsfiddle.net/codef0rmer/BSdCq/

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement