开发者

showing divs using keyboard commands

开发者 https://www.devze.com 2022-12-27 15:14 出处:网络
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....

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 ma开发者_运维技巧tter if it shows up in source.

any thoughts/links?

cheers


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.


You have to intercept the keypress event (or keyup) and then check which key was pressed (see 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消