I am not sure I have the answer to your problem, just a collection of
observations that hopefully steer you in the right direction.
According to your nopaste link, when you send "ON", the first four
keyboard events received by xev
are: press(Shift_L), press(O),
release(Shift_L), release(o). One may notice that there is no point in
releasing the Shift key if it's going to be pressed again right away,
but let's assume that simply holding Shift is not such a useful
optimization. The detail that strikes me is that the last two events
look backwards: you usually release the letter before releasing Shift.
As a result of releasing Shift first, the release event for the O key
reports lowercase "o" as a keysym. I tried this backward way of
releasing the keys on a real keyboard, but both gnome-terminal and gedit
correctly registered the uppercase letters.
Another detail apparent in the xev dump is that the two key presses
(Shit and O) happen at the exact same time. Ditto for the corresponding
key releases. Looking at the source of the Keyboard library, it appears
that both key presses are sent to the PC as a single "key report". Same
for the key releases. This is contrary to what a real keyboard does:
actuations on the Shift keys are reported immediately, irrespective of
whether other keys are actuated.
You may try to modify the Keyboard library so that the actuations on
Shift are sent in their own reports. Maybe something like this
(warning: completely untested):
diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp
index 4a948f6..9fbf7b6 100644
--- a/src/Keyboard.cpp
+++ b/src/Keyboard.cpp
@@ -239,6 +239,7 @@ size_t Keyboard_::press(uint8_t k)
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers |= 0x02; // the left shift modifier
+ sendReport(&_keyReport); // send the shift key by itself
k &= 0x7F;
}
}
@@ -270,6 +271,7 @@ size_t Keyboard_::press(uint8_t k)
size_t Keyboard_::release(uint8_t k)
{
uint8_t i;
+ bool has_shift = false;
if (k >= 136) { // it's a non-printing key (not a modifier)
k = k - 136;
} else if (k >= 128) { // it's a modifier key
@@ -281,7 +283,7 @@ size_t Keyboard_::release(uint8_t k)
return 0;
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
- _keyReport.modifiers &= ~(0x02); // the left shift modifier
+ has_shift = true;
k &= 0x7F;
}
}
@@ -295,6 +297,10 @@ size_t Keyboard_::release(uint8_t k)
}
sendReport(&_keyReport);
+ if (has_shift) {
+ _keyReport.modifiers &= ~(0x02); // the left shift modifier
+ sendReport(&_keyReport); // release shift after releasing the letter
+ }
return 1;
}
Alternatively, as suggested by @jstola in a comment, you may try to
press the Shift key by itself. Maybe you don't need to care about the
key release, or about any character but the first one (as it is the only
one that seems to cause problems). A minimal workaround to try would be:
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.println("ON");
xev
to see the keyboards events. When I press Shift-Y on my keyboard,xev
shows four distinct events: KeyPress(Shift_L), KeyPress(Y), KeyRelease(Y), KeyRelease(Shift_L). Do you see the same events in the same order? See also Keyboard input in the Arch Linux Wiki (instructive even if you are not using Arch).