I want to be able to activate the buttons using the keyboard instead of the mouse

I want to be able to activate the buttons using the keyboard instead of the mouse
0

#1

My Simon game is coming together, but I’d like to be able let the user use keyboard buttons as well as mouseclicks to activate the buttons. Right now I have it working with the mouse, but it just annoys me that I can’t figure out how to let the user do it with the keyboard. I’ve been googling all kinds of things and can’t seem to find the best way to do it. I’m sure it’s something easy, so if somebody could just point me in the direction, I would appreciate it.

I thought I might be getting close with event.which, but all the examples I found are with an input box. I would like for the user to be able to press a designated key to activated one of the buttons. I tried changing the id to “document”, but that didn’t seem to work:

$(document).on( “keydown”, function() {
console.log(event.which );
});

…didn’t seem to do what I wanted.


#2

I believe this is what you’re searching for


#3

Indeed, it is. Thank you so much!


#4

I guess I was getting close!