jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
https://jaywcjlove.github.io/hotkeys-js
MIT License
6.61k stars 406 forks source link

Numberpad Keys #96

Open ray73864 opened 5 years ago

ray73864 commented 5 years ago

Is there anyway to define a key specific to one on the numberpad?

For instance, I would like to define a key to the asterisk on the number pad, or to the forward slash key on the numberpad, etc... that would work differently to the regular ones.

The current library I use which requires jQuery allows me to specify the numberpad ones as 'np'+key (eg. npminus, npplus, npasterisk, etc...).

ray73864 commented 5 years ago

I suppose the other question is, is there a way to add extra keys without having to modify the sourcecode?

Possibly using the keycode itself instead?

jaywcjlove commented 5 years ago

@ray73864 This idea can be. I have no way to achieve it for the time being. There is no way to debug. #89

ray73864 commented 5 years ago

Not sure if this helps, but this is the jQuery one I have been using for the last 7yrs, works fine, but i'm seeing a less and less need for jQuery so trying to move to more vanilla libraries.

https://github.com/jollytoad/jquery.keys/blob/ondemand/src/keys.core.js

You can see all the key definitions at the bottom of the file.

ray73864 commented 5 years ago

I can use hotkeys('*', fn) for this for now.

/  = 111
*  = 106
-  = 109
+ = 107

Looks like there may be a difference between Firefox and other browsers with regards to the decimal point on the numpad, where FF defines it as 108 and other browsers define it as 110, but FF appears to do that with several other keys on the keyboard too.

ishan576 commented 4 years ago

I just added Numpad keys to _modifer variable and seems to work for me. The user will have to specify both the keys while initializing the hotkey

`

"num_0": 96,
"num_1": 97,
"num_2": 98,
"num_3": 99,
"num_4": 100,
"num_5": 101,
"num_6": 102,
"num_7": 103,
"num_8": 104,
"num_9": 105,
"num_multiply": 106,
"num_add": 107,
"num_enter": 108,
"num_subtract": 109,
"num_decimal": 110,
"num_divide": 111,`

Usage: hotkeys('-,=,1,2,num_subtract,num_add,num_1,num_2', 'numpadScope');