In your particular case, the double quote is to be entered (using the Spanish keyboard layout) by Shift + the physical key labelled 2. On a US keyboard, Shift + the physical key labelled 2 is "@".
Thus, this simply will get the desired result (the Arduino library assumes a US keyboard layout):
Keyboard.print("echo @This is a demo@");
More general solution
More generally, strings can be encoded as in the following table (the exact mappings depend on the particular keyboard layout - this will work for many European keyboard layouts).
If the physical key (and modifier key, if any) exists on the US keyboard to get the character typed out using the non-US keyboard layout, then this method works fine.
To get Use Notes
--------------------------------------------
; < Will result in Shift action
: > Will result in Shift action
( * Will result in Shift action
) ( Will result in Shift action
/ & Will result in Shift action
? _ Will result in Shift action
= ) Will result in Shift action
& ^ Will result in Shift action
- /
+ -
_ ?
" @ Will result in Shift action
, , The same
. . The same
# # The same
Even more general solution
Even more generally, some keys are not on the US keyboard (e.g. the 102th key on European keyboards for the original PC keyboards, often with <, >, \, and |), and it is not possible to use Keyboard.print().
Instead, use the low-level HID().SendReport() function - with code 100 (decimal) for the first parameter for the 102th key. See the library source code, Keyboard.cpp (/libraries/Keyboard/src/Keyboard.cpp), for how to use HID().SendReport().
Alternative solution
Some operating systems enable entering characters using the keyboard and a numeric code.
This is at the expense of making it operating-system dependent (but making it independent of the active keyboard layout).
For example, Ctrl + Shift + U on Linux (GUI only, dependent on the window manager(?)). For the particular problem (the Unicode code point for "
is 0022), without any functional abstraction to reduce the redundancy:
Keyboard.print("echo ");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('u');
Keyboard.releaseAll();
Keyboard.print("0022");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
Keyboard.print("This is a demo");
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('u');
Keyboard.releaseAll();
Keyboard.print("0022");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
Unicode code points can be found at unicode-table.com.
Media keys
Even though the media keys are listed in the table (e.g. code 128 for "Volume Up" on page 53), they do not work using the method described in the previous section. But there is a solution.
Platform
This was tested with:
- Arduino Leonardo
- The Spanish keyboard layout was added to the Linux settings and activated. There were 14 different ones to choose from, but I used the one labelled "Spanish". It was verified that "@" actually resulted in an output of "
"
". It was also verified that the Ctrl + Shift + U method worked.
- Linux, Ubuntu 19.10 (Eoan Ermine), but with the buggy GNOME replaced by Cinnamon.
- The Arduino Leonardo connected to an extra current port of a D-Link USB hub (necessary, for unknown reasons - probably a local problem)
- Arduino IDE v. 1.18.10