📜 ⬆️ ⬇️

jQuery.keyboard v0.1.0


I have in mind at least two projects that will require active control using the keyboard. Therefore, I sat down and wrote a convenient and beautiful plugin for jQuery, which I spread for general access under the free LGPL license.

Initially, I wrote it almost without using jQuery, but almost at the end of the development I rewrote everything as a plugin. The fact is that I actively use this framework in my projects, that's why it is more convenient for me. Those who do without jQuery, I left my previous work, but they will have to file a file. If someone does something beautifully, then I think everyone will be grateful to him.

This is my first jQuery plugin, so valid criticism is welcome. Perhaps I wrote something wrong - corrections are being made in the form of patches.

Examples

$( document )
.
keyboard ( '5' , function () {
alert ( '5' );
})
.
keyboard ([ 'ctrl' , 'alt' ], function () {
alert ( 'ctrl alt' );
})
.
keyboard ([ 'x' , 'c' , 'v' ], function () {
alert ( 'just xcv' );
},
true /* If only this keys are active */ );

$(
'textarea' ). keyboard ( 'ctrl enter' , sendmsg );

//
$( document ). keyboard ( 'ctrl alt' );

In my opinion, everything is very simple and obvious.
The third parameter is a single value. If 1 (true) is passed, then there will be a check whether any other keys are pressed except for the required ones. For example, “ctrl-enter” is selected. The user pinches "ctrl-alt-enter". In the absence of this parameter, the action will be performed, if the parameter is true, the action will not be performed.
If the type of the passed parameter or array element is number (but not a string with a number), then it will be interpreted as event.keyCode
The entries "['key1', 'key2']" and "'key1 key2'" are equivalent
')

Unsolved problem


1. If the user holds down a key (for example, “shift”), then pressing other keys will perform an action that is hung on this key (in this case, “shift”). It costs by setting the third parameter to true, but you will need to come up with a more beautiful solution.

Links

Google code project

Demo
Discussion of the next version
In the archive, in the source, there are my achievements without using jQuery

Source: https://habr.com/ru/post/76424/


All Articles