user14177: I'm playing with the Arduino Leonardo Keyboard.print() command, but I'm facing a annoying problem: 
When I print a double quote, it will not appear and also will make to disappear the next character (i.e.):
Keyboard.print("echo \"This is a demo\"");

Output:
echo his is a demo

And when I use this line:
Keyboard.print("echo -This is \"a demo-");

Output (note the umlaut over the a instead of getting "a):
echo 'This is ä demo'

I suspect that the problem is that my computer is configured to use Spanish layout. 
What source code file can I change to fix this? I can't find the defines used by Keyboard.print()

user510: 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


user4143: The Arduino assumes a US keyboard layout.  The thing with keyboards is they don't actually send the letters or symbols that are printed on the keys.  Instead the send a scan code that defines where on the keyboard the key is.  It is then up to the computer to convert those scan codes into actual letters and symbols, and that is performed by the keyboard mapping selected in the operating system.
Some special keys are known as dead keys.  These don't actually print a character on their own - instead they are used to modify the next key pressed - for instance the key which occupies the space a " would be on a US keyboard, on a Spanish keyboard, is a dead key which modifies the next key by adding an umlaut to it.
Since the Arduino doesn't know that you have a Spanish mapping, when you send a " it just sends what it believes is the location of that character on a keyboard, and of course it gets that wrong since it assumes the wrong keyboard layout.
So there are two things you can do to "fix" it:

Change your keyboard layout to US, but that will mean your normal keyboard will stop working properly.
Change how the Arduino thinks the keyboard is laid out, but that means lots of work to find the right scan codes.

The Arduino's keyboard layout is stored in the file HID.cpp in the Arduino core (hardware\avr\cores\arduino or somewhere like that - I forget off hand) and is the _asciimap array.  It is a list of the first 128 ASCII characters and the keyboard scancode mappings for them, including modifier keys like Shift.  You will have to find the scan codes for the keys you want to map on your keyboard layout and change the codes in that list.  For instance, the character " is listed as:
0x34|SHIFT,    // "

Which is scan code 0x34 (52 decimal) coupled with the SHIFT modifier.  You will have to discover (maybe Google can help) what the 0x34 should be changed to so that it moves the " to wherever it is on a Spanish keyboard.

14177: <p>I'm playing with the Arduino Leonardo <code>Keyboard.print()</code> command, but I'm facing a annoying problem: </p>

<p>When I print a double quote, it will not appear and also will make to disappear the next character (i.e.):</p>

<pre><code>Keyboard.print("echo \"This is a demo\"");
</code></pre>

<p>Output:</p>

<pre><code>echo his is a demo
</code></pre>

<p>And when I use this line:</p>

<pre><code>Keyboard.print("echo -This is \"a demo-");
</code></pre>

<p>Output (note the umlaut over the <code>a</code> instead of getting <code>"a</code>):</p>

<pre><code>echo 'This is ä demo'
</code></pre>

<p>I suspect that the problem is that my computer is configured to use Spanish layout. </p>

<p>What source code file can I change to fix this? I can't find the defines used by <code>Keyboard.print()</code></p>
 510: <p>In your particular case, the double quote <strong><em>is to be entered</em></strong> (using the <a href="https://docs.microsoft.com/en-us/globalization/keyboards/kbdsp.html" rel="nofollow noreferrer">Spanish keyboard layout</a>) by <kbd>Shift</kbd> + the physical key labelled <kbd>2</kbd>. On a <a href="https://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.svg" rel="nofollow noreferrer">US keyboard</a>, <kbd>Shift</kbd> + the physical key labelled <kbd>2</kbd> is "@".</p>

<p>Thus, this simply will get the desired result (the Arduino library assumes a US keyboard layout):</p>

<pre><code>Keyboard.print("echo @This is a demo@");
</code></pre>

<h3>More general solution</h3>

<p>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).</p>

<p>If the <em>physical key</em> (and modifier key, if any) <em>exists</em> on <a href="https://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.svg" rel="nofollow noreferrer">the US keyboard</a> to get the character typed out using the non-US keyboard layout, then this method works fine.</p>

<pre><code>To get   Use   Notes
--------------------------------------------
;        &lt;     Will result in Shift action
:        &gt;     Will result in Shift action
(        *     Will result in Shift action
)        (     Will result in Shift action
/        &amp;     Will result in Shift action
?        _     Will result in Shift action
=        )     Will result in Shift action
&amp;        ^     Will result in Shift action

-        /
+        -
_        ?

"        @     Will result in Shift action

,        ,     The same
.        .     The same
#        #     The same
</code></pre>

<h3>Even more general solution</h3>

<p>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 <kbd>&lt;</kbd>, <kbd>></kbd>, <kbd>\</kbd>, and <kbd>|</kbd>), and it is <strong><em>not</em></strong> possible to use <a href="https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardprint/" rel="nofollow noreferrer">Keyboard.print()</a>.</p>

<p>Instead, use the low-level <a href="https://www.arduino.cc/en/Reference/HID" rel="nofollow noreferrer">HID().SendReport()</a> function - with <a href="https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=56" rel="nofollow noreferrer">code 100</a> (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().</p>

<h3>Alternative solution</h3>

<p>Some operating systems enable entering characters using the keyboard and a numeric code.</p>

<p>This is at the expense of making it operating-system dependent (but making it independent of the active keyboard layout).</p>

<p>For example, <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>U</kbd> <a href="https://askubuntu.com/questions/88347/how-can-i-type-ascii-characters-like-alt-numpad-in-windows">on Linux</a> (GUI only, dependent on the window manager(?)). For the particular problem (the Unicode code point for <code>"</code> is <em>0022</em>), without any functional abstraction to reduce the redundancy:</p>

<pre><code>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();
</code></pre>

<p>Unicode code points <a href="https://unicode-table.com/en/" rel="nofollow noreferrer">can be found at unicode-table.com</a>.</p>

<h3>Media keys</h3>

<p>Even though the media keys are listed in <a href="https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf#page=56" rel="nofollow noreferrer">the table</a> (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 href="https://arduino.stackexchange.com/questions/8934/send-keyboard-media-keys-with-keyboard-library/75466#75466">a solution</a>.</p>

<h3>Platform</h3>

<p>This was tested with:</p>

<ul>
<li><a href="https://arduino.stackexchange.com/questions/8934/send-keyboard-media-keys-with-keyboard-library/75466#75466">Arduino Leonardo</a></li>
<li>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 "<code>"</code>". It was also verified that the <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>U</kbd> method worked.</li>
<li>Linux, <a href="https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_19.10_(Eoan_Ermine)" rel="nofollow noreferrer">Ubuntu&nbsp;19.10</a> (Eoan Ermine), but with <a href="https://en.wikipedia.org/wiki/GNOME" rel="nofollow noreferrer">the buggy GNOME</a> replaced by <a href="https://en.wikipedia.org/wiki/Cinnamon_(desktop_environment)" rel="nofollow noreferrer">Cinnamon</a>.</li>
<li>The Arduino Leonardo connected to an <em>extra current</em> port of a <a href="https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_19.10_(Eoan_Ermine)" rel="nofollow noreferrer">D-Link</a> USB hub (necessary, for unknown reasons - probably a local problem)</li>
<li>Arduino IDE v. 1.18.10</li>
</ul>
 4143: <p>The Arduino assumes a US keyboard layout.  The thing with keyboards is they don't actually send the letters or symbols that are printed on the keys.  Instead the send a <em>scan code</em> that defines <em>where</em> on the keyboard the key is.  It is then up to the computer to convert those scan codes into actual letters and symbols, and that is performed by the keyboard mapping selected in the operating system.</p>

<p>Some special keys are known as <em>dead keys</em>.  These don't actually print a character on their own - instead they are used to modify the next key pressed - for instance the key which occupies the space a " would be on a US keyboard, on a Spanish keyboard, is a dead key which modifies the next key by adding an umlaut to it.</p>

<p>Since the Arduino doesn't know that you have a Spanish mapping, when you send a " it just sends what it believes is the location of that character on a keyboard, and of course it gets that wrong since it assumes the wrong keyboard layout.</p>

<p>So there are two things you can do to "fix" it:</p>

<ol>
<li>Change your keyboard layout to US, but that will mean your normal keyboard will stop working properly.</li>
<li>Change how the Arduino thinks the keyboard is laid out, but that means lots of work to find the right scan codes.</li>
</ol>

<p>The Arduino's keyboard layout is stored in the file <code>HID.cpp</code> in the Arduino core (<code>hardware\avr\cores\arduino</code> or somewhere like that - I forget off hand) and is the <code>_asciimap</code> array.  It is a list of the first 128 ASCII characters and the keyboard scancode mappings for them, including <em>modifier keys</em> like Shift.  You will have to find the scan codes for the keys you want to map on your keyboard layout and change the codes in that list.  For instance, the character " is listed as:</p>

<pre><code>0x34|SHIFT,    // "
</code></pre>

<p>Which is scan code 0x34 (52 decimal) coupled with the SHIFT modifier.  You will have to discover (maybe Google can help) what the 0x34 should be changed to so that it moves the " to wherever it is on a Spanish keyboard.</p>
