0

I have a game I made with HTML5, CSS, and JavaScript. I have images of joystick arrows. I would like users to be able to click my joystick arrows and have it work as if the arrows on the keyboard were pressed. I wrote the code like this but it doesn't work:

var $rt_arrow = $('.rt_arrow') $rt_arrow.on('click' , function (e) { e.keyCode == 39 } 

How do I make keyCode 39 fire when the image of the right arrow is clicked?

1 Answer 1

1

Maybe it would be a clearer approach to write a callback function and assign it to the keyboard right arrow and to the right arrow.

function goRight() { console.log('I go right');} $('.rt_arrow').on('click', goRight); $(document).on('keydown', function(e) { if ( e.key === 'ArrowRight' ) { goRight(); } }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.