]> git.donarmstrong.com Git - qmk_firmware.git/blob - docs/feature_unicode.md
Add function to support split-keyboard in rgblight.[ch]. (#5020)
[qmk_firmware.git] / docs / feature_unicode.md
1 # Unicode Support
2
3 There are three Unicode keymap definition methods available in QMK:
4
5 ## `UNICODE_ENABLE`
6
7 Supports Unicode up to `0x7FFF`. This covers characters for most modern languages, as well as symbols, but it doesn't cover emoji. The keycode function is `UC(c)` in the keymap file, where _c_ is the code point's number (preferably hexadecimal, up to 4 digits long). For example: `UC(0x45B)`, `UC(0x30C4)`.
8
9 ## `UNICODEMAP_ENABLE`
10
11 Supports Unicode up to `0x10FFFF` (all possible code points). You need to maintain a separate mapping table `const uint32_t PROGMEM unicode_map[] = {...}` in your keymap file. The keycode function is `X(i)`, where _i_ is an array index into the mapping table. The table may contain at most 1024 entries.
12
13 You may want to have an enum to make referencing easier. So, you could add something like this to your keymap file:
14
15 ```c
16 enum unicode_names {
17   BANG,
18   IRONY,
19   SNEK,
20 };
21
22 const uint32_t PROGMEM unicode_map[] = {
23   [BANG]  = 0x203D,  // ‽
24   [IRONY] = 0x2E2E,  // ⸮
25   [SNEK]  = 0x1F40D, // 🐍
26 };
27 ```
28
29 Then you can use `X(BANG)` etc. in your keymap.
30
31 ## `UCIS_ENABLE`
32
33 Supports Unicode up to `0x10FFFF` (all possible code points). As with `UNICODEMAP`, you need to maintain a mapping table in your keymap file. However, there are no built-in keycodes for this feature — you will have to add a keycode or function that calls `qk_ucis_start()`. Once this function's been called, you can type the corresponding mnemonic for your character, then hit Space or Enter to complete it, or Esc to cancel. If the mnemonic matches an entry in your table, the typed text will automatically be erased and the corresponding Unicode character inserted.
34
35 For instance, you would define a table like this in your keymap file:
36
37 ```c
38 const qk_ucis_symbol_t ucis_symbol_table[] = UCIS_TABLE(
39   UCIS_SYM("poop", 0x1F4A9), // 💩
40   UCIS_SYM("rofl", 0x1F923), // 🤣
41   UCIS_SYM("kiss", 0x1F619)  // 😙
42 );
43 ```
44
45 You call `qk_ucis_start()`, then type "rofl" and hit Enter. QMK should erase the "rofl" text and input the laughing emoji.
46
47 ### Customization
48
49 There are several functions that you can define in your keymap to customize the functionality of this feature.
50
51 * `void qk_ucis_start_user(void)` – This runs when you call the "start" function, and can be used to provide feedback. By default, it types out a keyboard emoji.
52 * `void qk_ucis_success(uint8_t symbol_index)` – This runs when the input has matched something and has completed. By default, it doesn't do anything.
53 * `void qk_ucis_symbol_fallback (void)` – This runs when the input doesn't match anything. By default, it falls back to trying that input as a Unicode code.
54
55 You can find the default implementations of these functions in [`process_ucis.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_ucis.c).
56
57 ## Input Modes
58
59 Unicode input in QMK works by inputting a sequence of characters to the OS, sort of like a macro. Unfortunately, the way this is done differs for each platform. Specifically, each platform requires a different combination of keys to trigger Unicode input. Therefore, a corresponding input mode has to be set in QMK.
60
61 The following input modes are available:
62
63 * **`UC_OSX`**: Mac OS X built-in Unicode hex input. Supports code points up to `0xFFFF` (`0x10FFFF` with `UNICODEMAP`).
64
65   To enable, go to _System Preferences > Keyboard > Input Sources_, add _Unicode Hex Input_ to the list (it's under _Other_), then activate it from the input dropdown in the Menu Bar.
66   By default, this mode uses the left Option key (`KC_LALT`), but this can be changed by defining [`UNICODE_OSX_KEY`](#input-key-configuration) with another keycode.
67
68   **Note:** Using the _Unicode Hex Input_ input source may disable some Option based shortcuts, such as: Option + Left Arrow (`moveWordLeftAndModifySelection`) and Option + Right Arrow  (`moveWordRightAndModifySelection`).
69
70 * **`UC_LNX`**: Linux built-in IBus Unicode input. Supports code points up to `0x10FFFF` (all possible code points).
71
72   Enabled by default and works almost anywhere on IBus-enabled distros. Without IBus, this mode works under GTK apps, but rarely anywhere else.
73
74 * **`UC_WIN`**: _(not recommended)_ Windows built-in hex numpad Unicode input. Supports code points up to `0xFFFF`.
75
76   To enable, create a registry key under `HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad` of type `REG_SZ` called `EnableHexNumpad` and set its value to `1`. This can be done from the Command Prompt by running `reg add "HKCU\Control Panel\Input Method" -v EnableHexNumpad -t REG_SZ -d 1` with administrator privileges. Afterwards, reboot.
77   This mode is not recommended because of reliability and compatibility issues; use the `UC_WINC` mode instead.
78
79 * **`UC_BSD`**: _(non implemented)_ Unicode input under BSD. Not implemented at this time. If you're a BSD user and want to help add support for it, please [open an issue on GitHub](https://github.com/qmk/qmk_firmware/issues).
80
81 * **`UC_WINC`**: Windows Unicode input using [WinCompose](https://github.com/samhocevar/wincompose). As of v0.8.2, supports code points up to `0xFFFFF` (all currently assigned code points).
82
83   To enable, install the [latest release](https://github.com/samhocevar/wincompose/releases/latest). Once installed, WinCompose will automatically run on startup. Works reliably under all version of Windows supported by the app.
84   By default, this mode uses the right Alt key (`KC_RALT`), but this can be changed in the WinCompose settings and by defining [`UNICODE_WINC_KEY`](#input-key-configuration) with another keycode.
85
86 ### Switching Input Modes
87
88 There are two ways to set the input mode for Unicode: by keycode or by function. Keep in mind that both methods write to persistent storage (EEPROM), and are loaded each time the keyboard starts. So once you've set it the first time, you don't need to set it again unless you want to change it, or you've reset the EEPROM settings.
89
90 You can switch the input mode at any time by using one of the following keycodes. The easiest way is to add the ones you use to your keymap.
91
92 |Keycode                |Alias    |Input mode   |Description                              |
93 |-----------------------|---------|-------------|-----------------------------------------|
94 |`UNICODE_MODE_FORWARD` |`UC_MOD` |             |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|
95 |`UNICODE_MODE_REVERSE` |`UC_RMOD`|             |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|
96 |`UNICODE_MODE_OSX`     |`UC_M_OS`|`UC_OSX`     |Switch to Mac OS X input.                |
97 |`UNICODE_MODE_LNX`     |`UC_M_LN`|`UC_LNX`     |Switch to Linux input.                   |
98 |`UNICODE_MODE_WIN`     |`UC_M_WI`|`UC_WIN`     |Switch to Windows input.                 |
99 |`UNICODE_MODE_BSD`     |`UC_M_BS`|`UC_BSD`     |Switch to BSD input (not implemented).   |
100 |`UNICODE_MODE_WINC`    |`UC_M_WC`|`UC_WINC`    |Switch to Windows input using WinCompose.|
101
102 You can also switch the input mode by calling `set_unicode_input_mode(x)` in your code, where _x_ is one of the above input mode constants (e.g. `UC_LNX`). Since the function only needs to be called once, it's recommended that you do it in `eeconfig_init_user` (or a similar function). For example:
103
104 ```c
105 void eeconfig_init_user(void) {
106   set_unicode_input_mode(UC_LNX);
107 }
108 ```
109
110 ### Audio Feedback
111
112 If you have the [Audio feature](feature_audio.md) enabled on the board, you can set melodies to be played when you press the above keys. That way you can have some audio feedback when switching input modes.
113
114 For instance, you can add these definitions to your `config.h` file:
115
116 ```c
117 #define UNICODE_SONG_OSX  COIN_SOUND
118 #define UNICODE_SONG_LNX  UNICODE_LINUX
119 #define UNICODE_SONG_BSD  MARIO_GAMEOVER
120 #define UNICODE_SONG_WIN  UNICODE_WINDOWS
121 #define UNICODE_SONG_WINC UNICODE_WINDOWS
122 ```
123
124 ### Additional Customization
125
126 Because Unicode is such a large and variable feature, there are a number of options that you can customize to work better on your system.
127
128 #### Start and Finish input functions
129
130 The functions for starting and finishing Unicode input on your platform can be overridden locally. Possible uses include customizing input mode behavior if you don't use the default keys, or adding extra visual/audio feedback to Unicode input.
131
132 * `void unicode_input_start(void)` – This sends the initial sequence that tells your platform to enter Unicode input mode. For example, it presses Ctrl+Shift+U on Linux and holds the Option key on Mac.
133 * `void unicode_input_finish(void)` – This is called to exit Unicode input mode, for example by pressing Space or releasing the Option key.
134
135 You can find the default implementations of these functions in [`process_unicode_common.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_unicode_common.c).
136
137
138 #### Input Key Configuration
139
140 Additionally, you can customize the keys used to trigger the unicode input for macOS and WinCompose by adding defines to your `config.h`
141
142 ```c
143 #define UNICODE_OSX_KEY  KC_LALT
144 #define UNICODE_WINC_KEY KC_RALT
145 ```
146
147 #### Input Method Cycling
148
149 Also, you can choose which input methods are availble for cycling through.  By default, this is disabled. But if you want to enabled it, then limiting it to just those modes makes sense.  Note that `UNICODE_SELECTED_MODES` define is comma delimited.
150
151 ```c
152 #define UNICODE_SELECTED_MODES UC_OSX, UC_LNX, UC_WIN, UC_BSD, UC_WINC
153 ```
154
155 ## `send_unicode_hex_string`
156
157 To type multiple characters for things like (ノಠ痊ಠ)ノ彡┻━┻, you can use `send_unicode_hex_string()` much like `SEND_STRING()` except you would use hex values separate by spaces.
158 For example, the table flip seen above would be `send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B")`
159
160 There are many ways to get a hex code, but an easy one is [this site](https://r12a.github.io/app-conversion/). Just make sure to convert to hexadecimal, and that is your string.
161
162 ## Additional Language Support
163
164 In `quantum/keymap_extras/`, you'll see various language files - these work the same way as the alternative layout ones do. Most are defined by their two letter country/language code followed by an underscore and a 4-letter abbreviation of its name. `FR_UGRV` which will result in a `ù` when using a software-implemented AZERTY layout. It's currently difficult to send such characters in just the firmware.
165
166 ## International Characters on Windows
167
168 ### AutoHotkey allows Windows users to create custom hotkeys among others.
169
170 The method does not require Unicode support in the keyboard itself but depends instead of [AutoHotkey](https://autohotkey.com) running in the background.
171
172 First you need to select a modifier combination that is not in use by any of your programs.
173 CtrlAltWin is not used very widely and should therefore be perfect for this.
174 There is a macro defined for a mod-tab combo `LCAG_T`.
175 Add this mod-tab combo to a key on your keyboard, e.g.: `LCAG_T(KC_TAB)`.
176 This makes the key behave like a tab key if pressed and released immediately but changes it to the modifier if used with another key.
177
178 In the default script of AutoHotkey you can define custom hotkeys.
179
180     <^<!<#a::Send, ä
181     <^<!<#<+a::Send, Ä
182
183 The hotkeys above are for the combination CtrlAltGui and CtrlAltGuiShift plus the letter a.
184 AutoHotkey inserts the Text right of `Send, ` when this combination is pressed.
185
186 ### US International
187
188 If you enable the US International layout on the system, it will use punctuation to accent the characters.
189
190 For instance, typing "`a" will result in à.
191
192 You can find details on how to enable this [here](https://support.microsoft.com/en-us/help/17424/windows-change-keyboard-layout).