views:

36

answers:

4

is it possible to show/hid a div on a webpage if say three keys are pressed in the correct order on a normal keyboard.... Im trying to hide my login div in drupal and only want it to show if I press say three keys on the keyboard. Dosnt matter if it shows up in source.

any thoughts/links?

cheers

+1  A: 

You have to intercept the keypress event (or keyup) and then check which key was pressed (see http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed) To handle a key sequence you have to store the pressed key codes into an array and then check it against your defined sequence.

mamoo
+1  A: 

You can try js-hotkeys.

jQuery.Hotkeys plugin lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination. It takes one line of code to bind/unbind a hot key combination.

Example: Binding 'Ctrl+c'

$(document).bind('keydown', 'ctrl+c', fn); 

Next step is to show/hide your div in the function you pass in.

Bart
A: 

If you poll for key presses and store them in array then match that with the correct array once this happens show the div then clear your stored array. Close the div and start the process again.

matpol
A: 

This "cheat code" jQuery plugin should make what you're asking especially simple.

Stefan Kendall
Use js-hotkeys if you need hotkeys, and not elaborate passwords. Your original post was unclear as to what functionality you desired.
Stefan Kendall
cheers Stefan, I think this will do nicely...many thanks for your response (and all the others, really quick!)
ade