JSFiddle - React, Tailwind, and code Playground
HTML
<div>
Click here and try<br/>
Hadouken => ▼ ► A<br/>
Shouryuuken => ▼ ► ▼ ► A
</div>
CSS
div
{
width: 300px;
height: 200px;
background: silver;
}
JavaScript
(function($){
$.fn.kb = function(evt, map, fn, options)
{
var _this = this;
this.modifiers = [17, 18, 19];
var combos = this.data("Combos") || {};
function AddToTree(tree, array)
{
for (var i = 0, length = array.length; i < length; ++i)
{
tree = tree[array[i].toLowerCase()] = ((i == length - 1) ? fn : tree[array[i].toLowerCase()] || {});
}
}
AddToTree(combos, map.Keys);
this.data("Combos", combos);
map = $.extend({ Modifiers: [], Keys: [] }, map);
var KeysTimerKey = "KeysTimer" + map.Modifiers.join("") + map.Keys.join("");
var KeysCombo = "KeysCombo";// + map.Modifiers.join("") + map.Keys.join("");
options = $.extend({NoInput:true, Delay: 350, PreventDefault:false}, options);
var specialKeys = { 27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll',
20: 'capslock', 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',
35:'end', 33: 'pageup', 34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down',
109: '-',
112:'f1',113:'f2', 114:'f3', 115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8',
120:'f9', 121:'f10', 122:'f11', 123:'f12', 191: '/'};
var FromCharCode =
function(code)
{
if (specialKeys[code] != undefined)
return specialKeys[code];
return String.fromCharCode(code);
};
this.bind
(
evt,
function(e)
{
if (_this.modifiers.indexOf(e.keyCode) == -1)
{
if (options.NoInput && ["input", "textarea"].indexOf(e.target.tagName.toLowerCase()) > -1) return;
var ctrl = map.Modifiers.join("$").match(/ctrl/i) != null;
var shift = map.Modifiers.join("$").match(/shift/i) != null;
...