P
P
Phantomrus2016-09-01 16:00:34
Arduino
Phantomrus, 2016-09-01 16:00:34

How to simulate pressing the Space key on Arduino?

Hello!
There is a button on the web page. If it is currently the selected element on the page, pressing the Spacebar will press the button. (You can select it either by clicking on it with the mouse or using Tab, going through all the elements on the page)
Statement of the problem: It is necessary that the Arduino emulates pressing the Space key on clap and the button (already selected) is pressed.
There are no problems with initiating the cotton action. Difficulty with keyboard emulation.
Arduino Leonardo can pretend to be a keyboard. The Keyboard.press() function emulates pressing and holding a key. However, as far as I understand, the button on the page waits for the Space key to be pressed, and not for the character " " (#32 in ASCII) to be passed to it.The assumption turned out to be wrong. Emulation of 32 characters works as it should. It is enough to use Keyboard.press(' ') And if using Keyboard.press() I can simulate pressing Ctrl or Backspace, then the Space emulation has stumped me.
Tell me, is there a solution to this problem?
Sorry, couldn't formulate the problem less confusingly. Ready to answer questions.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tayanov, 2016-09-01
@Phantomrus

Keyboard.press(' '); did you try it for fun?

M
Mercury13, 2016-09-01
@Mercury13

Strange: if the arduina is a USB keyboard, then it transmits exactly the pressing of the physical space key.
However, you have a space in the quotes " " here. Most likely, this is exactly the error: with poor type checking inherent in C, the address of the string "space" will be passed to the function (which requires char).
Should Keyboard.press(' ');or Keyboard.write(' ');. In single quotes. That is an integer.
In addition, Keyboard.press only presses the button, and figure out how to “release” this button. At least, my “chanterelle” requires exactly RELEASE of the space. As an option - the same Keyboard.write, which presses and releases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question