Skip to main content

Implementing non-default keyboard shortcuts in OpenlayersOpenlayers2

Following on from this thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEventhandleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong? Many thanks!

Implementing non-default keyboard shortcuts in Openlayers

Following on from this thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong? Many thanks!

Implementing non-default keyboard shortcuts in Openlayers2

Following on from this thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong?

replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/
Source Link

Following on from this threadthis thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong? Many thanks!

Following on from this thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong? Many thanks!

Following on from this thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong? Many thanks!

Source Link
MappaGnosis
  • 34k
  • 2
  • 67
  • 130

Implementing non-default keyboard shortcuts in Openlayers

Following on from this thread, I am trying to implement @Aragon's suggestion and add some keyboard shortcuts to OpenLayers via a handleKeyEvent method in OpenLayers.Handler.Keyboard. This ought to be a simple task that many people implement but for some reason I'm just not getting it.

var keyboardControl = new OpenLayers.Control();

var keyHandler = new OpenLayers.Handler.Keyboard(keyboardControl, {
    handleKeyEvent: function(evt) {
            alert("You pressed a key!");
            switch(evt.keyCode) {
                case 87:
                    doSomething([0, 1]);
                case 83:
                    doSomething([0,-1]);
                case 65:
                    doSomething([1,0]);
                case 68:
                    doSomething([-1,0])
            }
        },
});

function doSomething(vals){
    alert("Something will happen here eventually...");
};

map.addControl(keyboardControl);

I get no errors but neither of my alerts get fired. What am I doing wrong? Many thanks!