Trigger a buttonpress with a keypress in react

Does anyone now how to use a keypress to trigger a button press in react… I have the following code but it doesnt work.

Well, for your code, it looks like you’re missing the .bind in the constructor for your HandleKeyPress function which is why it doesn’t work for the key press event on your input. Adding that and all you’ve created seems to work fine.

Now regarding detecting key presses, I wouldn’t suggest doing it in an <input> for something like this, because then the drum would work only when that input is highlighted. Maybe instead add your event listener for keydown to the document after your React app is loaded.

Thanks i got it working. I forgot about the event listeners so much to remember.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.