///
Ext.onReady(function () {
var viewport = Ext.create('Ext.container.Viewport', {
layout: {
type: 'vbox',
align: 'stretch'
},
padding : 10,
items: [{
bar: [{
text: 'Add (F2)'
}],
frame: true, . autoEl : {
tag: 'div',
tabindex: 0
}
}, {
XType: 'Panel',
ID: 'Panelb',
Title: 'Shortcut key test B',
tbar: [{
text: 'Add (F2)'
}],
frame: true,
flex: 1,
html: 'Hello, the table or form shown here. ',
}]
});
Ext.create('Ext.util.KeyMap', {
target: 'panelA',
key: Ext.EventObject.F2,
fn: function (key, ev) {
alert('Add A'); 🎜> Ext. Create ('EXT.UTIL.KEYMAP', {
Target: 'Panelb',
Key: Ext.eventobject.f2,
Fn: Function (key, EV) {
Alert ('Add to B');
ev.stopEvent();
return false;
}
});
});
Actual results
Pressing F2 directly after opening the browser has no effect; opening the browser and clicking A or B with the mouse and then pressing F2 will have the effect.
The third implementation
To solve the problem of recognizing shortcut keys without clicking the div after opening the browser, you need to manually call the foucs() method.
Code example
///
Ext.onReady(function () {
var viewport = Ext.create('Ext.container.Viewport', {
layout: {
type: 'vbox',
align: 'stretch'
},
padding : 10,
items: [{
bar: [{
text: 'Add (F2)'
}],
frame: true, . autoEl : {
tag: 'div',
tabindex: 0
}
}, {
XType: 'Panel',
ID: 'Panelb',
Title: 'Shortcut key test B',
tbar: [{
text: 'Add (F2)'
}],
frame: true,
flex: 1,
html: 'Hello, the table or form shown here. ',
}]
});
Ext.create('Ext.util.KeyMap', {
target: 'panelA',
key: Ext.EventObject.F2,
fn: function (key, ev) {
alert('Add A'); 🎜> Ext. Create ('EXT.UTIL.KEYMAP', {
Target: 'Panelb',
Key: Ext.eventobject.f2,
Fn: Function (key, EV) {
Alert ('Add to B');
ev.stopEvent();
return false;
}
});
Ext.get('panelB'). focus();
});
Actual results
Open the browser and press F2 directly to have the effect; open the browser and click A or B with the mouse and then press F2 It works.