tomsseisums
tomsseisums

Reputation: 13377

Handling specialKeys with HotKeys plugin

I'm trying to get https://github.com/tzuryby/jquery.hotkeys to work, but:

$('#myInput').on({
    'keydown.space keydown.left keydown.right keydown.- keydown..' : function(e)
    {
        console.log( e.which );
    }
});

The above snippet responds to space, left and right buttons. No hyphen and neither of dots (the one near ctrl, and the numpad one) invoke the event.

And, hence, the question,

How do I target special keys like dot + numpad dot, numpad add + plus, numpad subtract + hyphen, quote, colon etc.?

Upvotes: 0

Views: 413

Answers (2)

Sheridan Bulger
Sheridan Bulger

Reputation: 1214

To use a period with hotkeys, I added 190: "period" to specialKeys in jquery.hotkeys.js Then I can use "period" for the keydown event. I'm assuming the same would work for a hyphen.

Upvotes: 1

davehale23
davehale23

Reputation: 4372

According to this and this, keypress doesn't fire on special characters in the version of 'hotkeys' that you are using. I'd recommend switching to this similar library that was actually a fork of the tzuryby library and written by John Resig.

You can capture the period key like this fiddle.

Upvotes: 1

Related Questions