|
4 | 4 | #include "ydotool.h" |
5 | 5 |
|
6 | 6 | #define FLAG_UPPERCASE 0x80000000 |
7 | | -#define FLAG_CTRL 0x40000000 |
| 7 | +#define FLAG_CTRL 0x40000000 |
8 | 8 |
|
9 | 9 | static const int32_t ascii2keycode_map[128] = { |
10 | 10 | // 00 - 0f |
@@ -83,47 +83,47 @@ int tool_stdin(int argc, char **argv) { |
83 | 83 | printf("Type anything (CTRL-C to exit):\n"); |
84 | 84 |
|
85 | 85 | while (1) { |
86 | | - char buffer[4] = {0}; |
87 | | - read(STDIN_FILENO, buffer, 3); |
88 | | - |
89 | | - printf("Key code: %d %d %d\n", buffer[0], buffer[1], buffer[2]); |
90 | | - |
91 | | - char c = buffer[0]; |
92 | | - |
93 | | - // Convert char to keycode and flags based on the ascii2keycode_map |
94 | | - int kdef = ascii2keycode_map[(int)c]; |
95 | | - |
96 | | - if ((int)buffer[0] == 27 && (int)buffer[1] == 91 && (int)buffer[2] >= 65 && (int)buffer[2] <= 76) { |
97 | | - kdef = ascii2ctrlcode_map[(int)buffer[2] - 65]; |
98 | | - } |
99 | | - |
100 | | - if (kdef == -1) continue; // Skip unsupported characters |
101 | | - printf(" Maps to: %d\n", kdef); |
102 | | - |
103 | | - uint16_t kc = kdef & 0xffff; // Extract keycode |
104 | | - bool isUppercase = (kdef & FLAG_UPPERCASE) != 0; |
105 | | - bool isCtrl = (kdef & FLAG_CTRL) != 0; |
106 | | - |
107 | | - // Emit key events |
108 | | - if (isUppercase) { |
109 | | - printf(" Sending shift\n"); |
110 | | - uinput_emit(EV_KEY, KEY_LEFTSHIFT, 1, 1); // Press shift for uppercase |
111 | | - } |
112 | | - if (isCtrl) { |
113 | | - printf(" Sending ctrl\n"); |
114 | | - uinput_emit(EV_KEY, KEY_LEFTCTRL, 1, 1); // Press ctrl |
115 | | - } |
116 | | - uinput_emit(EV_KEY, kc, 1, 1); // Key down |
117 | | - usleep(opt_key_hold_ms * 1000); // Hold key |
118 | | - uinput_emit(EV_KEY, kc, 0, 1); // Key up |
119 | | - if (isCtrl) { |
120 | | - uinput_emit(EV_KEY, KEY_LEFTCTRL, 0, 1); // Release ctrl |
121 | | - } |
122 | | - if (isUppercase) { |
123 | | - uinput_emit(EV_KEY, KEY_LEFTSHIFT, 0, 1); // Release shift for uppercase |
124 | | - } |
125 | | - |
126 | | - usleep(opt_key_delay_ms * 1000); // Delay between keys |
| 86 | + char buffer[4] = {0}; |
| 87 | + read(STDIN_FILENO, buffer, 3); |
| 88 | + |
| 89 | + printf("Key code: %d %d %d\n", buffer[0], buffer[1], buffer[2]); |
| 90 | + |
| 91 | + char c = buffer[0]; |
| 92 | + |
| 93 | + // Convert char to keycode and flags based on the ascii2keycode_map |
| 94 | + int kdef = ascii2keycode_map[(int)c]; |
| 95 | + |
| 96 | + if ((int)buffer[0] == 27 && (int)buffer[1] == 91 && (int)buffer[2] >= 65 && (int)buffer[2] <= 76) { |
| 97 | + kdef = ascii2ctrlcode_map[(int)buffer[2] - 65]; |
| 98 | + } |
| 99 | + |
| 100 | + if (kdef == -1) continue; // Skip unsupported characters |
| 101 | + printf(" Maps to: %d\n", kdef); |
| 102 | + |
| 103 | + uint16_t kc = kdef & 0xffff; // Extract keycode |
| 104 | + bool isUppercase = (kdef & FLAG_UPPERCASE) != 0; |
| 105 | + bool isCtrl = (kdef & FLAG_CTRL) != 0; |
| 106 | + |
| 107 | + // Emit key events |
| 108 | + if (isUppercase) { |
| 109 | + printf(" Sending shift\n"); |
| 110 | + uinput_emit(EV_KEY, KEY_LEFTSHIFT, 1, 1); // Press shift for uppercase |
| 111 | + } |
| 112 | + if (isCtrl) { |
| 113 | + printf(" Sending ctrl\n"); |
| 114 | + uinput_emit(EV_KEY, KEY_LEFTCTRL, 1, 1); // Press ctrl |
| 115 | + } |
| 116 | + uinput_emit(EV_KEY, kc, 1, 1); // Key down |
| 117 | + usleep(opt_key_hold_ms * 1000); // Hold key |
| 118 | + uinput_emit(EV_KEY, kc, 0, 1); // Key up |
| 119 | + if (isCtrl) { |
| 120 | + uinput_emit(EV_KEY, KEY_LEFTCTRL, 0, 1); // Release ctrl |
| 121 | + } |
| 122 | + if (isUppercase) { |
| 123 | + uinput_emit(EV_KEY, KEY_LEFTSHIFT, 0, 1); // Release shift for uppercase |
| 124 | + } |
| 125 | + |
| 126 | + usleep(opt_key_delay_ms * 1000); // Delay between keys |
127 | 127 | } |
128 | 128 |
|
129 | 129 | return 0; |
|
0 commit comments