View Full Version : KeyMap Help

19 Aug 2009, 5:17 AM

I'm trying to add shortcut / Access Key to my application.

I have some little questions:

1) what is the best way to add a shortcut for a button ?
I have a Buttton with an handler linked to the "click" event.
I would have a shortcut that simulate user push the button
I believe it is a very common feature
The only way I fount is to create a new Ext.KeyMap object: not possible directly in Button definition... or I make a mistake ? there is a simple way?

Also if there isnt' a fast way...

I read a blog article from http://extjs.com/blog/2008/09/23/keyboard-handling/
It seems very similar to my case but I have some issue:

var keys = [];
for (var i = 0; i < buttons.length; i++) {
var btn = buttons;
// fkey property contains a string referencing the Ext constants (ie: Ext.EventObject.F1)
var fk = eval(button.fkey);
btn.handler = this.handleKey.createDelegate(this, [fk]);
key: fk,
handler: this.handleKey.createDelegate(this, [fk]),
stopEvent: true,
scope: this
At the end et the keys[] into the panel (using keys config attribute).. and... at this point I don't understant the code
btn.handler = this.handleKey.createDelegate(this, [fk]);

For each button it get the fkey attribute (the shortcut) and change the button handler with a delegate function.. but what is "this.handleKey" ?handler for a button recieves "a button and an EventObject ", instead handler for a KeyMap recieves " a Key and an EventObject "... two different signature...

2) I cannot add keys to a Panel to avoid some "focus" issue,
I should add it to a container (or to the document)... but
"keys config" exists only on Panel or subclasses...
a workaround it to use the KeyMap constructor... e.g.

new Ext.KeyMap("my-element", {
key: 13, // or Ext.EventObject.

any other ways?

How can I remove a KeyMap ? e.g. If I add it to the document, I should remove it after an ajax request...


22 Aug 2009, 5:14 AM
No one use KeyMap?

22 Aug 2009, 5:21 AM
You can either destroy or disable a keymap (depending on whether you want to reuse it).

ps. You might find this user extension (http://www.extjs.com/forum/showthread.php?t=66682) useful.

1 Sep 2009, 1:14 AM
You can either destroy.... a keymap

How can I destroy a keymap ?

the destroy() function doesn't exists.. I try also to invoke the Ext.destroy(myKeyMap) or Ext.destroyMembers() but listeners are not destroyed...