I am using ArcGIS JavaScript API and I want to show a message in console's log when I hold down "e"
and click on a graphic drawn by a user.
this.map.graphics.on ("click", lang.hitch(this, function(evt){
if (evt.keyCode == 69 ) {
console.log("e clicked ");
}
}));
I know that e's code is 69 but I think evt.keyCode == 69
need some changes.
anybody can help me?
-
which version of Js api you're using ?Bourbia Brahim– Bourbia Brahim2017年05月03日 23:12:39 +00:00Commented May 3, 2017 at 23:12
-
I am using arcgis js api 16 compact.Maria Gomez– Maria Gomez2017年05月04日 05:47:03 +00:00Commented May 4, 2017 at 5:47
-
please recheck if its arcgis js api 2 / 3 or version 4 ?Bourbia Brahim– Bourbia Brahim2017年05月04日 10:28:39 +00:00Commented May 4, 2017 at 10:28
-
It is not version 4 ( that support 3d ) it is 16. It means that support 2d.Maria Gomez– Maria Gomez2017年05月04日 12:24:23 +00:00Commented May 4, 2017 at 12:24
-
There is no version 16 of the ArcGIS API for JavaScript. Do you maybe mean 3.16?Bjorn Svensson– Bjorn Svensson2017年05月04日 14:15:39 +00:00Commented May 4, 2017 at 14:15
2 Answers 2
The click
doesn't know about any letter key pressed. It only knows if Ctrl/Shift/Meta keys where pressed while you clicked.
For your use case, I think you would have to first listen for key-down
and when the key pressed is e
, then you listen for the click.
Something like this should work, listens for a click and keypress of 'e'
.click(function(e) {
if (e.keyCode == 69) {
console.log("e clicked");
}
});
See also related stackoverflow, another
Edit: This may be a better solution: How to check if key is pressed during click event in JQuery adapted for 'e':
var Pressed = false;
$(window).keydown(function(evt) {
if (evt.which == 69) { // e
Pressed = true;
}
}).keyup(function(evt) {
if (evt.which == 69) { // e
Pressed = false;
}
});
yourfunction.click(function() {
if (Pressed) {
console.log("e clicked");
} else {
// do something else
}
});
Explore related questions
See similar questions with these tags.