As you can see I'm just trying to output all characters if I comment the line #include mouse.h everything works as expected. If I uncomment this line I get the wrong characters.
I see the same things as posted in my first post. With the line commented out I get the right result. With the lne included I get the same "wrong" result.
Ok I tried some different things and it seems the problem is not with the libraries.
It's in the computer: when I test it with a Windows laptop everything works just fine, but on my chromebook (where I want to use this sketch) it gives this strange behaviour.
I will keep on looking for a solution, but it looks like this forum isn't the right place.
Thanks J-M-L for your advice, if you have a clue I would be glad to learn it if not I will be looking in other places.
One possible thing to try... I have heard of cases where a very short key press does not always get counted. I don't know why that might cause problems only with the shift modifier but you can try this:
Replace: keyboard.write(value);
With
That trick doesn't work. But thanks for your answer.
After some more trying I think the problem lies with the buffer keyboard.h uses.
In this code the first character is always written with shift pressed, but then shift is released automatically on a chromebook.
On a windows laptop the output is as expected with shift always pressed.
When I want to write a character with shift pressed I can use shift for every single character. I'm going to try and prgram around this problem. That should be feasible.
The .write() function does a .press() immediately followed by a .release(). The .press() function sets the shift flag in the USB report if the character should be shifted and the .release() function clears the shift flag in the USB report if the character was a shifted character. Since the shift flags and key codes arrive in the same message I don't see how the key can be properly interpreted as un-shifted. Looks like a software bug in the Chromebook.
I've ran into this exact issue while automating CrOS enrollment with the Leonardo chip.
I'm not sure I agree with the assessment that it's a software bug with CrOS. Removing Mouse.h immediately fixes the issue. Somewhere between Mouse.h and Keyboard.h is causing improper casing. As far as I know CrOS handles shift/caps lock the same as every OS. The only difference is Chromebooks do not include a CAPS LOCK key.
I'd say the bug is with the Keyboard.h and Mouse.h instead of the actual operating system. Is there a way to submit a report?