PDA

View Full Version : Global keypress



orgreeno
3 Apr 2012, 9:34 AM
Using Designer 2, what is the best way to listen for a keypress event for the entire app? Can I add a keypress listener to the main panel? Or listen for keypress DOM events?

aconran
3 Apr 2012, 10:44 AM
Probably subscribing to the key event on the body.
eg
Ext.getBody().on

You could set this up in your Application launch method.

orgreeno
3 Apr 2012, 1:20 PM
Should this fire the alert?
launch: function() {
alert("launched");
Ext.create('MyApp.view.main_panel', {fullscreen: true});
}
The app loads but the alert does not fire.

build 355
sencha touch project

aconran
3 Apr 2012, 3:52 PM
It should. I just tested a simple application by doing the following:

Start a touch 2.0 project
Drag out a Panel
Add a launch method to Application
add an alert to the launch method

Save and preview the project in the browser.

the code generated for Application was:


Ext.Loader.setConfig({
enabled: true
});

Ext.application({
views: [
'MyPanel'
],
name: 'MyApp',

launch: function() {
alert('launch');
Ext.create('MyApp.view.MyPanel', {fullscreen: true});
}

});