I followed this tutorial on how to set up arduino uno as an HID keyboard device, while some parts required more research, it was fairly straightforwards. I got it set up, but when I analyzed the key events, i noticed an anomaly:
keydown keyCode=71 (G) which=71 (G) charCode=0
keypress keyCode=0 which=103 (g) charCode=103 (g)
keyup keyCode=71 (G) which=71 (G) charCode=0
keydown keyCode=70 (F) which=70 (F) charCode=0
keypress keyCode=0 which=102 (f) charCode=102 (f)
(This was repeated on every loop())
In pressing a key, the previously pressed key, while not actually released, is read to have been released.
Here is my code (modified from tutorial):
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
setup()
{
Serial.begin(9600);
delay(200);
}
void loop()
{
delay(2000);
buf[2] = 10;
Serial.write(buf, 8);
buf[2] = 9;
Serial.write(buf, 8);
releaseKey();
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
}
So I wanted to know if there was a way to have multiple keys (say, F and G) be pressed together or separately, and stay pressed together. Then release them one at a time.
First please get rid of the smiley faces by using code tags instead of quote tags in your post.
Your example does not do press but write. Assuming it works the same as on the HID files the write function does this:
size_t Keyboard_::write(uint8_t c)
{
uint8_t p = press(c); // Keydown
uint8_t r = release(c); // Keyup
return (p); // just return the result of press() since release() almost always returns 1
}
So you can see that write does a press and a release.
It doesn't, if I set it to send only one key (even repeating it), there is no keyup event until I halt the program (and even then there is only one).
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
void [color=#CC6600]setup/color
{
Serial.[color=#CC6600]begin/color;
[color=#CC6600]randomSeed/color;
[color=#CC6600]delay/color;
}
?
It doesn't, if I set it to send only one key (even repeating it), there is no keyup event until I halt the program (and even then there is only one).
Which processor on the Uno are you using for this? The Atmega328P or the Atmega16u4?
the Atmega16u2, on arduino uno r3
What board do you have set in the IDE? What library(s) are you using for the keyboard access?
The IDE is set to Ardiono Uno, as for librarys, all my code is there, and I am flashing the arduino-keyboard-0.3.hex to make it show up as an HID.