-1

I am currently working on a calculator and wondered if there is a way to link keypresses to buttons so when I click a button, it simuliates the key being pressed and sends that info to the textbox.

When I google, all the info I get is enabling buttons by keypresses but not the other way around.

If someone could help me cause my code is already a mess with all the conversations and keypress events.

armn
  • 7
  • 1
  • You can use jQuery - `keydown(function(e) => { ... }` and there you can specify `e.keyCode == 32` as `32` is for space bar. Get key code from here https://css-tricks.com/snippets/javascript/javascript-keycodes/ – GMAC Mar 11 '21 at 16:33
  • why are you not just adding a space to the input directly? – epascarello Mar 11 '21 at 16:44

1 Answers1

0

I believe this is answered in this Stackoverflow thread: Is it possible to simulate key press events programmatically?.

To add it to the textbox you can listen to the keydown event and add the character accordingly.

Simpmon
  • 26
  • 2