Have you thought of having a functionality which allows your users to save the inputs using Ctrl+S key combination or by pressing Ctrl+P and print the page. Isn't it a nice feature? Indeed it is. So in this post, I will show you how you can have various key combinations to perform various tasks on your webpage using jQuery. This is possible with a new jQuery plugin called "jwerty".
jwerty is a JS library which allows you to bind, fire and assert key combination strings against elements and events. It normalises the poor std api into something easy to use and clear.
jwerty is a small library, weighing in at around 1.5kb bytes minified and gzipped (~3kb minified). jwerty has no dependencies, but is compatible with jQuery, Zepto or Ender if you include those packages alongside it.
To use this plugin specify the key combination and a callback function which will be used key combination is pressed. Case and whitespace do not matter. + is used to add keys to make a single combo. jwerty.key will attach an event listener and fire callbackFunction when jwertyCode matches. The event listener is attached to document, meaning it will listen for any key events on the page (a global shortcut listener).
Feel free to contact me for any help related to jQuery, I will gladly help you.
jwerty is a JS library which allows you to bind, fire and assert key combination strings against elements and events. It normalises the poor std api into something easy to use and clear.
jwerty is a small library, weighing in at around 1.5kb bytes minified and gzipped (~3kb minified). jwerty has no dependencies, but is compatible with jQuery, Zepto or Ender if you include those packages alongside it.
How to use it?
To use this plugin specify the key combination and a callback function which will be used key combination is pressed. Case and whitespace do not matter. + is used to add keys to make a single combo. jwerty.key will attach an event listener and fire callbackFunction when jwertyCode matches. The event listener is attached to document, meaning it will listen for any key events on the page (a global shortcut listener).
//Code Starts jwerty.key('ctrl+shift+P', function () { [...] }); //Code EndsFor example, if you wanted to look for the key combination of control + shift + P, then one of the following would represent that (you can use shorthand names or symbols for keys that need it):
'ctrl+shift+p' OR 'control+shift+P' OR '⌃+⇧+P'If you wanted either control + shift + P or command + shift + P then you would use the / key to separate the two:
'ctrl+shift+p/cmd+shift+P'If you wanted to only fire an event when the user has typed ctrl+shift+p followed by the P key, on it's own again, then you need to use the , key, like so:
'ctrl+shift+p, p'There are many more options and events associated with this plugin.
Feel free to contact me for any help related to jQuery, I will gladly help you.
No comments:
Post a Comment