arduino-libraries / Keyboard

GNU Lesser General Public License v3.0
223 stars 157 forks source link

Keyboard types "2n" instead of an apostrophe #66

Closed brendanballon closed 2 years ago

brendanballon commented 2 years ago

Like the title says, when I write an apostrophe it types "2n". I cannot figure this out and it happens on other operating systems other than Mac.

edgar-bonet commented 2 years ago

What kind of apostrophe are you trying to type? ASCII quote (U+0027 = ')? Right single quotation mark (U+2019 = )?

What keyboard layout is configured on your computer? What keyboard layout did you set with Keyboard.begin()?

edgar-bonet commented 2 years ago

I managed to reproduce the issue. The “apostrophe” was actually the non-ASCII character “right single quotation mark” (U+2019 = ). Here is a test sketch:

#include <Keyboard.h>

void setup() {
    Keyboard.begin();
    delay(5000);
    Keyboard.print("’");
}

void loop(){}

The character is written in UTF-8 as the sequence (0xe2, 0x80, 0x99). These all being non-ASCII codes, they are interpreted by the library as “special” keys, namely:

Since this library only supports ASCII, I think the issue could be closed as invalid. On the other hand, the documentation does not state explicitly the limitation to only ASCII, so this could be an issue to be filed against the documentation.

Edit: looking at that manual again, it seems the documenttaion of Keyboard.write() is explicit enough:

Only ASCII characters that are on the keyboard are supported. [...] For a complete list of ASCII characters, see ASCIITable.com.