forum

Home / DeveloperSection / Forums / Show image when key is pressed with jQuery

Show image when key is pressed with jQuery

Anonymous User 1918 08-Apr-2013
Hi Mindstickians!

I'm trying to make a simple app that when a key is pressed on the users keyboard an image appears respective to that letter. I would like to do this for the entire alphabet (a, b, c...)

if a is pressed a.jpg shows up on my page, if r was pressed r.jpg would appear and so on.

I was going to do this with a mega list of if else statements only im sure there must be another way?

var ctrlPressed = false;
$(window).keydown(function(evt) {
  if (evt.which == 17) { // ctrl
    ctrlPressed = true;
      alert('sdf');
  }
})

Thanks in advance!

Updated on 08-Apr-2013
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By