Here is an example of enumerating 2 keycodes. After adding this block to your `keymap.c` you will be able to use `FOO` and `BAR` inside your keymap.
-```
+```c
enum my_keycodes {
FOO = SAFE_RANGE,
BAR
This example does two things. It defines the behavior for a custom keycode called `FOO`, and it supplements our Enter key by playing a tone whenever it is pressed.
-```
+```c
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case FOO:
The `record` argument contains information about the actual press:
-```
+```c
keyrecord_t record {
-+-keyevent_t event {
-| +-keypos_t key {
-| | +-uint8_t col
-| | +-uint8_t row
-| | }
-| +-bool pressed
-| +-uint16_t time
-| }
+ keyevent_t event {
+ keypos_t key {
+ uint8_t col
+ uint8_t row
+ }
+ bool pressed
+ uint16_t time
+ }
}
```
### Example `led_set_user()` Implementation
-```
+```c
void led_set_user(uint8_t usb_led) {
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
PORTB |= (1<<0);
# Matrix Initialization Code
-Before a keyboard can be used the hardware must be initialized. QMK handles initialization of the keyboard matrix itself, but if you have other hardware like LED's or i²c controllers you will need to set up that hardware before it can be used.
+Before a keyboard can be used the hardware must be initialized. QMK handles initialization of the keyboard matrix itself, but if you have other hardware like LED's or i²c controllers you will need to set up that hardware before it can be used.
### Example `matrix_init_user()` Implementation
This example, at the keyboard level, sets up B1, B2, and B3 as LED pins.
-```
+```c
void matrix_init_user(void) {
// Call the keymap level matrix init.
# Keyboard Idling/Wake Code
-If the board supports it, it can be "idled", by stopping a number of functions. A good example of this is RGB lights or backlights. This can save on power consumption, or may be better behavior for your keyboard.
+If the board supports it, it can be "idled", by stopping a number of functions. A good example of this is RGB lights or backlights. This can save on power consumption, or may be better behavior for your keyboard.
-This is controlled by two functions: `suspend_power_down_*` and `suspend_wakeup_init_*`, which are called when the system is board is idled and when it wakes up, respectively.
+This is controlled by two functions: `suspend_power_down_*` and `suspend_wakeup_init_*`, which are called when the system is board is idled and when it wakes up, respectively.
### Example suspend_power_down_user() and suspend_wakeup_init_user() Implementation
This example, at the keyboard level, sets up B1, B2, and B3 as LED pins.
-```
+```c
void suspend_power_down_user(void)
{
rgb_matrix_set_suspend_state(true);
# Layer Change Code
-This runs code every time that the layers get changed. This can be useful for layer indication, or custom layer handling.
+This runs code every time that the layers get changed. This can be useful for layer indication, or custom layer handling.
### Example `layer_state_set_*` Implementation
This example shows how to set the [RGB Underglow](feature_rgblight.md) lights based on the layer, using the Planck as an example
-```
+```c
uint32_t layer_state_set_user(uint32_t state) {
switch (biton32(state)) {
case _RAISE: