Closed night-crawler closed 11 years ago
I'll have to look into this. I may want to avoid adding support for the function keys because they often control browser behavior that cannot be prevented by javascript.
I haven't done any work yet to support other keyboard layouts or languages, so I suppose it's to be expected that there will be some quirks.
When i use hotkey num_7, i.e., it fires when i use non-existant hotkey, i.e. ctrl num_7
I'm not sure I'm understanding this entirely. Could you go into a little more detail about this please. Are you saying you can only get the num_7 to fire if you are holding down the control key?
Ok, i have the following code:
function unbind_hotkey(hotkey){
if (hotkey in HOTKEYS){
keypress.unregister_combo(HOTKEYS[hotkey]);
}
}
function bind_hotkey(hotkey, command){
var combo = {
'keys': hotkey,
'on_keydown': function(event){
event.preventDefault();
send_mud(command);
},
'is_exclusive': true
};
unbind_hotkey(hotkey);
HOTKEYS[hotkey] = combo;
keypress.register_combo(combo);
}
And the usage:
bind_hotkey('num_4', 'запад');
bind_hotkey('num_8', 'север');
bind_hotkey('num_5', 'юг');
bind_hotkey('num_6', 'восток');
bind_hotkey('num_subtract', 'вверх');
bind_hotkey('num_add', 'вниз');
bind_hotkey('num_7', 'кол м.имп'); // <---
When i press ctrl num_7
, it fires the num7
handler. But there's no handler for ctrl num_7
.
Does it fire if you hit num_7 on its own?
Combos will fire if additional keys are pressed (and it doesn't match another combo and is_exclusive) though perhaps I should add an option for that as well.
Does it fire if you hit num_7 on its own?
Yes.
P.S. I'm writing a JS mud client, so hotkeys is a very important part of it. And it seems, that your's library is more suitable for this thing, than others.
Yeah, that's not a bug, if you were to for instance add a new hotkey for "ctrl num_7" and make it exclusive, num_7 would NOT fire with ctrl down.
I'll add a new property you can add to combos that requires that they are the only keys down.
JS MUD client sounds sick :D, keep me informed! I built this kind of specifically for a JS roguelike I'm working on, so it's focused on more game-like things so I suppose it makes sense that it's fitting for a MUD client.
You may try it: http://jsmc.force.fm/
But still work is in progress. On client-side it uses web-sockets and python Tornado as a socket-websocket intermediate proxy. Site on django. When almolst will be done, i think, i will public it on github.
I just pushed version 1.0.6 which has an undocumented feature. If you set is_solitary to true for a combo, it will only fire if there are no other keys pressed. For instance, if you want the combo to activate when num_7 is pressed and not when ctrl + num_7 is pressed, simply do this (using your code sample):
function bind_hotkey(hotkey, command){
var combo = {
'keys': hotkey,
'on_keydown': function(event){
event.preventDefault();
send_mud(command);
},
'is_exclusive': true,
'is_solitary':true
};
unbind_hotkey(hotkey);
HOTKEYS[hotkey] = combo;
keypress.register_combo(combo);
}
This feature enforces that a combo will only fire when no other keys except those that define the combo are pressed.
I've tried to use
f4
,f_2
, etc. It does not recognize it. With monkey patching i've added those keys into_keycode_dictionary
. It seems, that it worked.If it not my mistake, please add this functionality.
Also have bugs with decimal at numpad detection after a switching keyboard layout from english to russian.
When i use hotkey
num_7
, i.e., it fires when i use non-existant hotkey, i.e.ctrl num_7
.