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?

  • which version of Js api you're using ? – Springer F May 3 '17 at 23:12
  • I am using arcgis js api 16 compact. – Maria Gomez May 4 '17 at 5:47
  • please recheck if its arcgis js api 2 / 3 or version 4 ? – Springer F May 4 '17 at 10:28
  • It is not version 4 ( that support 3d ) it is 16. It means that support 2d. – Maria Gomez May 4 '17 at 12:24
  • There is no version 16 of the ArcGIS API for JavaScript. Do you maybe mean 3.16? – Bjorn Svensson May 4 '17 at 14:15
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.

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
  }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.