0

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?

Bjorn Svensson
3,58521 silver badges38 bronze badges
asked May 3, 2017 at 2:57
5
  • which version of Js api you're using ? Commented May 3, 2017 at 23:12
  • I am using arcgis js api 16 compact. Commented May 4, 2017 at 5:47
  • please recheck if its arcgis js api 2 / 3 or version 4 ? Commented May 4, 2017 at 10:28
  • It is not version 4 ( that support 3d ) it is 16. It means that support 2d. Commented May 4, 2017 at 12:24
  • There is no version 16 of the ArcGIS API for JavaScript. Do you maybe mean 3.16? Commented May 4, 2017 at 14:15

2 Answers 2

1

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.

answered May 4, 2017 at 14:56
0

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
 }
});
answered May 4, 2017 at 15:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.