Arduino Leonardo and Nonstandard Characters

I’m trying to create a small button that, when I push it, writes a Lenny face using the Keyboard.write() function. I’m unable to get it to work, it often outputs random characters and stuff. I’ve tried having it press down ALT while typing in numbers, but it didn’t work.

( ͡° ͜ʖ ͡°) ← Lenny face

First you have to find out what characters to type: http://knowyourmeme.com/memes/͡-͜ʖ-͡-lenny-face

**Code Point (Base 16) ** **Name ** **Chart **
28 left parenthesis Basic Latin (ASCII)[35]
20 space Basic Latin (ASCII)[35]
361 combining double inverted breve Combining Diacritical Marks[38]
B0 degree sign Latin-1 Supplement[36]
20 space Basic Latin (ASCII)[35]
35C combining double breve below Combining Diacritical Marks[38]
296 Latin letter inverted glottal stop IPA Extensions[37]
20 space Basic Latin (ASCII)[35]
361 combining double inverted breve Combining Diacritical Marks[38]
B0 degree sign Latin-1 Extensions[36]
29 right parenthesis Basic Latin (ASCII)[35]

The “Basic Latin (ASCII)” characters from the US_ENGLISH keyboard are easy, you can just send the ASCII. The other characters have to be entered as a numerical character code. That means pressing the ALT key and holding it while typing digits ON THE KEYPAD (different from the usual digit keys). You should probably write a function that takes a Unicode value (left column) and converts it into the required sequence of ALT-shifted keypad digits. You will have to look in the USB standard to find the keycodes for the keypad digits.

johnwasser:
First you have to find out what characters to type: http://knowyourmeme.com/memes/͡-͜ʖ-͡-lenny-face

Code Point (Base 16) Name Chart
28 left parenthesis Basic Latin (ASCII)[35]
20 space Basic Latin (ASCII)[35]
361 combining double inverted breve Combining Diacritical Marks[38]
B0 degree sign Latin-1 Supplement[36]
20 space Basic Latin (ASCII)[35]
35C combining double breve below Combining Diacritical Marks[38]
296 Latin letter inverted glottal stop IPA Extensions[37]
20 space Basic Latin (ASCII)[35]
361 combining double inverted breve Combining Diacritical Marks[38]
B0 degree sign Latin-1 Extensions[36]
29 right parenthesis Basic Latin (ASCII)[35]

The “Basic Latin (ASCII)” characters from the US_ENGLISH keyboard are easy, you can just send the ASCII. The other characters have to be entered as a numerical character code. That means pressing the ALT key and holding it while typing digits ON THE KEYPAD (different from the usual digit keys). You should probably write a function that takes a Unicode value (left column) and converts it into the required sequence of ALT-shifted keypad digits. You will have to look in the USB standard to find the keycodes for the keypad digits.

Here’s the code I’m using as a test. In theory, this should write a smiley face(:relaxed:).

Keyboard.press(86); //Alt
delay(500);
Keyboard.press(225); //Keypad 1o
delay(500);
Keyboard.releaseAll();

However all it does is generate V’s and U’s.

The reference I found says the smiley face is Alt-9786. You need to press Alt, then press and release keypad-9, keypad-7, keypad-8 and keypad-6 before releasing Alt. Modifier keys are 129 to 135 and you have to add 136 to any other scancode so it won't be mistaken for ascii or a modifier key. The keypad digit USB scancodes are 98 for Keypad-0 and 89 through 97 for Keypad-1 through Keypad-9. Don't forget to add 136 to each!

laptopdude90, the keyboard emulation emulates a keyboard. It is not possible to copy-paste something on the computer, it is like typing on a keyboard. It can do everything like a normal keyboard, even the things that are not documented, but it still is only a keyboard.

How to type Unicode characters in Windows (from Wikipedia):

http://en.wikipedia.org/wiki/Unicode_input#In_Microsoft_Windows

In Microsoft Windows[edit] A prerequisite for this input method is that the registry key "HKEY_CURRENT_USER\Control Panel\Input Method" contains a string type (REG_SZ) value called "EnableHexNumpad", which has the value data 1. Users need to log off/in on Windows 8.1/8.0, Windows 7, and Vista or reboot on earlier systems after editing the registry for this input method to start working. Unicode characters can be entered by holding down Alt, pressing the + on the numeric keypad, followed by the hex code - using the numeric keypad for digits from 0 to 9 and letter keys for A to F digits - and then releasing Alt.[2] The RichEdit control on Microsoft Windows (as used in for example WordPad) supports the following input method: one first enters the character’s hexadecimal code (between two and six hexadecimal digits), then immediately presses Alt+x. For example, entering f1 and then pressing the combination will produce the character ñ. Unless it is six hexadecimal digits long, the code must not be preceded by any digit or letters a–f as they will be treated as part of the code to be converted. For example, entering af1 followed by Alt+x will produce ૱ (U+0AF1), but entering a0000f1 followed by Alt+x will produce a ñ. This also works in Microsoft Word 2002/2003 for Windows.