├── README.md └── text_to_macro.py /README.md: -------------------------------------------------------------------------------- 1 | # RK Keyboard Macro JSON Generator 2 | 3 | This Python script generates JSON macros for RK keyboards. It was tested with the **RK L75 keyboard** and is intended for use with the [RK Gaming WebHID Configurator](https://drive.rkgaming.com/). 4 | 5 | ## Features 6 | 7 | * Converts arbitrary text into valid JSON macro objects. 8 | * Supports: 9 | 10 | * Lowercase and uppercase letters (Shift handled automatically). 11 | * Digits (0–9). 12 | * Space and common punctuation. 13 | * Shift-modified characters such as `! @ # $ % ^ & * ( ) _ + { } | : \" ~ < > ?`. 14 | * Allows configurable delay (in milliseconds) between press/release actions. 15 | 16 | ## How It Works 17 | 18 | Each character is translated into an array of **press** and **release** actions in JSON format, matching the WebHID configurator’s expected structure: 19 | 20 | ```json 21 | { 22 | "action": 0, // 0 = Press, 1 = Release 23 | "type": 0, // 0 = Normal key, 1 = Modifier (Shift) 24 | "delay": 30, // Delay in ms 25 | "key": 32, // HID key code 26 | "index": 0 // Action order 27 | } 28 | ``` 29 | 30 | Shifted characters (e.g., `_`, `A`, `!`) automatically include Shift press/release events with `"type": 1`. 31 | 32 | ## Usage 33 | 34 | 1. Ensure you have Python 3 installed. 35 | 2. Save the script (`macro_json_generator.py`). 36 | 3. Run it in a terminal: 37 | 38 | ```bash 39 | python macro_json_generator.py 40 | ``` 41 | 4. Enter your desired text and delay when prompted. 42 | 5. Copy the generated JSON output and paste it into the RK WebHID Configurator. 43 | 44 | ## Example 45 | 46 | Input: 47 | 48 | ``` 49 | Text: Hello_123! 50 | Delay: 30 51 | ``` 52 | 53 | Output (truncated): 54 | 55 | ```json 56 | [ 57 | {"action":0,"type":1,"delay":30,"key":225,"index":0}, 58 | {"action":0,"type":0,"delay":30,"key":11,"index":1}, 59 | {"action":1,"type":0,"delay":30,"key":11,"index":2}, 60 | {"action":1,"type":1,"delay":0,"key":225,"index":3}, 61 | ... 62 | ] 63 | ``` 64 | 65 | ## Notes 66 | 67 | * Designed for **US QWERTY layout**. Other layouts may produce different results. 68 | * Currently supports common ASCII symbols. Extended characters are not included. 69 | * Tested with RK L75, but should work with other RK keyboards using the WebHID tool. 70 | 71 | ## License 72 | 73 | This project is released under the MIT License. 74 | -------------------------------------------------------------------------------- /text_to_macro.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | # Basic HID key mapping for letters (a-z) 4 | # HID usage IDs for letters: 'a' = 4, 'b' = 5, ..., 'z' = 29 5 | hid_map = {chr(i + 97): i + 4 for i in range(26)} 6 | 7 | # Correct mapping for numbers (USB HID): 8 | # '1' -> 30, '2' -> 31, ..., '9' -> 38, '0' -> 39 9 | digits_map = {str(i): 29 + i for i in range(1, 10)} 10 | digits_map['0'] = 39 11 | hid_map.update(digits_map) 12 | 13 | # Add space 14 | hid_map[" "] = 44 15 | 16 | # Add base punctuation (unshifted) 17 | hid_map.update({ 18 | "-": 45, 19 | "=": 46, 20 | "[": 47, 21 | "]": 48, 22 | "\\": 49, 23 | ";": 51, 24 | "'": 52, 25 | "`": 53, 26 | ",": 54, 27 | ".": 55, 28 | "/": 56, 29 | }) 30 | 31 | # Special shifted symbols mapping (character -> base key HID) 32 | shift_map = { 33 | "_": 45, # shift + '-' 34 | "!": 30, # shift + '1' 35 | "@": 31, 36 | "#": 32, 37 | "$": 33, 38 | "%": 34, 39 | "^": 35, 40 | "&": 36, 41 | "*": 37, 42 | "(": 38, 43 | ")": 39, 44 | "+": 46, # shift + '=' 45 | "{": 47, # shift + '[' 46 | "}": 48, # shift + ']' 47 | "|": 49, # shift + '\\' 48 | ":": 51, # shift + ';' 49 | "\"": 52, # shift + '"' 50 | "~": 53, # shift + '`' 51 | "<": 54, # shift + ',' 52 | ">": 55, # shift + '.' 53 | "?": 56, # shift + '/' 54 | } 55 | 56 | SHIFT_KEY = 225 # HID code for Left Shift 57 | 58 | 59 | def text_to_macro(text, delay): 60 | actions = [] 61 | index = 0 62 | 63 | for char in text: 64 | needs_shift = False 65 | 66 | if char in shift_map: 67 | needs_shift = True 68 | keycode = shift_map[char] 69 | elif char.isalpha() and char.isupper(): 70 | needs_shift = True 71 | keycode = hid_map[char.lower()] 72 | elif char in hid_map: 73 | keycode = hid_map[char] 74 | else: 75 | raise ValueError(f"Character '{char}' not supported in HID map.") 76 | 77 | if needs_shift: 78 | # Press Shift (type 1) 79 | actions.append({ 80 | "action": 0, 81 | "type": 1, 82 | "delay": delay, 83 | "key": SHIFT_KEY, 84 | "index": index 85 | }) 86 | index += 1 87 | 88 | # Press key (type 0) 89 | actions.append({ 90 | "action": 0, 91 | "type": 0, 92 | "delay": delay, 93 | "key": keycode, 94 | "index": index 95 | }) 96 | index += 1 97 | 98 | # Release key 99 | actions.append({ 100 | "action": 1, 101 | "type": 0, 102 | "delay": delay, 103 | "key": keycode, 104 | "index": index 105 | }) 106 | index += 1 107 | 108 | if needs_shift: 109 | # Release Shift (type 1) 110 | actions.append({ 111 | "action": 1, 112 | "type": 1, 113 | "delay": 0, 114 | "key": SHIFT_KEY, 115 | "index": index 116 | }) 117 | index += 1 118 | 119 | return actions 120 | 121 | 122 | if __name__ == "__main__": 123 | text = input("Enter text to convert into macro: ") 124 | delay = int(input("Enter delay in ms between actions: ")) 125 | 126 | macro = text_to_macro(text, delay) 127 | print(json.dumps(macro, indent=4)) 128 | --------------------------------------------------------------------------------