PDA

View Full Version : Using KeyMap



zloi
24 Jul 2012, 1:15 AM
Hi everyone!
i have a trouble when using Ext.util.KeyMap: i need to hotkeys (Ctrl+F2 and F2)


var toolbar = Ext.create('Ext.toolbar.Toolbar', {
items: [
{
xtype:'button',
text:'File',

}
]
});

var panel = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
tbar: toolbar,
html: 'blah'
});

var el = Ext.getDoc();
var _keyMap = Ext.create('Ext.util.KeyMap', el);

var obj = {
key : Ext.EventObject.F2,
fn : function() {alert('F2');}
};
_keyMap.addBinding(obj);
obj = {
key : Ext.EventObject.F2,
ctrl : true,
fn : function() {alert('Ctrl + F2');}
};
_keyMap.addBinding(obj);

when I doing this and pressing CTRL + F2 combination a get both messages. What should I do to get only one message when pressing Ctrl+F2. http://jsfiddle.net/zloi_kot/gTezx/
Thanks!

Farish
24 Jul 2012, 2:25 AM
set ctrl: false explicitly for F2.

sword-it
24 Jul 2012, 2:49 AM
HI!

you may try what Farish said, if it doesn't work for you, try to store keystroke in a variable, and you may compare if ctrl was pressed or not, if preseed then do alert('ctrl+f2'), if not alert('f2').

Sample (for G(71) & U(85)):-



Ext.ns('Ext.pressedKeys');
// 71 -> G
// 85 -> U
Ext.getDoc().on({
keydown : function(e, f, g){
if(e.getCharCode() == 71){
Ext.pressedKeys['G'] = true;
}
}
,keyup : function(e){
if(e.getCharCode() == 85 && Ext.pressedKeys['G'] == true){
console.log('g and u');
}
Ext.pressedKeys['G'] = false;
}
});



Check this:-http://www.sencha.com/forum/showthread.php?112845-KeyNav-KeyMap-gt-two-normal-keys-at-the-same-time

zloi
24 Jul 2012, 3:37 AM
thanks!! setting ctrl to false helped me. in docs is written that by default ctrl, alt, and shift is undefined, so I need to make them false manualy.