Search code examples
javascriptextjshotkeys

ExtJS add hotkey


I want to add hotkey functionality to my page.

Ext.onReady(function () {
    Ext.util.KeyMap(document, {
        key: 'abc',
        handler: function () {
            alert("Hotkey was pressed!");
        }
    });
});

But the event doesn't occurs.


Solution

  • Ext 3.3.1 :

    Ext.onReady(function () {
        new Ext.KeyMap(document, {
            key: 'abc',
            fn: function () {
                alert("Hotkey was pressed!");
            }
        });
    });
    

    in Ext 4.0.2.a :

    Ext.onReady(function () {
        var map = new Ext.util.KeyMap(document,{
                //key : "abc" //doesn't work (mybe a bug)
                key: [65,66,67], // this works,
                fn: function(){ alert('a, b or c was pressed'); }
            }
        );
    });