From 3487f5ebb8fe41a270643e51e70eed3664f1bd93 Mon Sep 17 00:00:00 2001 From: Andre Paiusco <2374887+Paiusco@users.noreply.github.com> Date: Mon, 6 May 2024 16:30:26 +0200 Subject: [PATCH] Update readme/manual Extra update on stdin indentation --- Client/tool_stdin.c | 84 +++++++++++++++++++++--------------------- README.md | 18 ++++++--- manpage/ydotool.1.scd | 2 + manpage/ydotoold.8.scd | 15 ++++++++ 4 files changed, 71 insertions(+), 48 deletions(-) diff --git a/Client/tool_stdin.c b/Client/tool_stdin.c index bab7d73..7d7c7e1 100644 --- a/Client/tool_stdin.c +++ b/Client/tool_stdin.c @@ -4,7 +4,7 @@ #include "ydotool.h" #define FLAG_UPPERCASE 0x80000000 -#define FLAG_CTRL 0x40000000 +#define FLAG_CTRL 0x40000000 static const int32_t ascii2keycode_map[128] = { // 00 - 0f @@ -83,47 +83,47 @@ int tool_stdin(int argc, char **argv) { printf("Type anything (CTRL-C to exit):\n"); while (1) { - char buffer[4] = {0}; - read(STDIN_FILENO, buffer, 3); - - printf("Key code: %d %d %d\n", buffer[0], buffer[1], buffer[2]); - - char c = buffer[0]; - - // Convert char to keycode and flags based on the ascii2keycode_map - int kdef = ascii2keycode_map[(int)c]; - - if ((int)buffer[0] == 27 && (int)buffer[1] == 91 && (int)buffer[2] >= 65 && (int)buffer[2] <= 76) { - kdef = ascii2ctrlcode_map[(int)buffer[2] - 65]; - } - - if (kdef == -1) continue; // Skip unsupported characters - printf(" Maps to: %d\n", kdef); - - uint16_t kc = kdef & 0xffff; // Extract keycode - bool isUppercase = (kdef & FLAG_UPPERCASE) != 0; - bool isCtrl = (kdef & FLAG_CTRL) != 0; - - // Emit key events - if (isUppercase) { - printf(" Sending shift\n"); - uinput_emit(EV_KEY, KEY_LEFTSHIFT, 1, 1); // Press shift for uppercase - } - if (isCtrl) { - printf(" Sending ctrl\n"); - uinput_emit(EV_KEY, KEY_LEFTCTRL, 1, 1); // Press ctrl - } - uinput_emit(EV_KEY, kc, 1, 1); // Key down - usleep(opt_key_hold_ms * 1000); // Hold key - uinput_emit(EV_KEY, kc, 0, 1); // Key up - if (isCtrl) { - uinput_emit(EV_KEY, KEY_LEFTCTRL, 0, 1); // Release ctrl - } - if (isUppercase) { - uinput_emit(EV_KEY, KEY_LEFTSHIFT, 0, 1); // Release shift for uppercase - } - - usleep(opt_key_delay_ms * 1000); // Delay between keys + char buffer[4] = {0}; + read(STDIN_FILENO, buffer, 3); + + printf("Key code: %d %d %d\n", buffer[0], buffer[1], buffer[2]); + + char c = buffer[0]; + + // Convert char to keycode and flags based on the ascii2keycode_map + int kdef = ascii2keycode_map[(int)c]; + + if ((int)buffer[0] == 27 && (int)buffer[1] == 91 && (int)buffer[2] >= 65 && (int)buffer[2] <= 76) { + kdef = ascii2ctrlcode_map[(int)buffer[2] - 65]; + } + + if (kdef == -1) continue; // Skip unsupported characters + printf(" Maps to: %d\n", kdef); + + uint16_t kc = kdef & 0xffff; // Extract keycode + bool isUppercase = (kdef & FLAG_UPPERCASE) != 0; + bool isCtrl = (kdef & FLAG_CTRL) != 0; + + // Emit key events + if (isUppercase) { + printf(" Sending shift\n"); + uinput_emit(EV_KEY, KEY_LEFTSHIFT, 1, 1); // Press shift for uppercase + } + if (isCtrl) { + printf(" Sending ctrl\n"); + uinput_emit(EV_KEY, KEY_LEFTCTRL, 1, 1); // Press ctrl + } + uinput_emit(EV_KEY, kc, 1, 1); // Key down + usleep(opt_key_hold_ms * 1000); // Hold key + uinput_emit(EV_KEY, kc, 0, 1); // Key up + if (isCtrl) { + uinput_emit(EV_KEY, KEY_LEFTCTRL, 0, 1); // Release ctrl + } + if (isUppercase) { + uinput_emit(EV_KEY, KEY_LEFTSHIFT, 0, 1); // Release shift for uppercase + } + + usleep(opt_key_delay_ms * 1000); // Delay between keys } return 0; diff --git a/README.md b/README.md index 53c7a54..52f6429 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ydotool will then be rewritten in JavaScript afterwards, to enable more people t The man page is not always up to date. Please use `--help` to ensure correctness. ## ChangeLog -This project is now refactored. (v1.0.0) +This project is now refactored. (from v1.0.0) Changes: - Rewritten in pure C99 @@ -35,10 +35,13 @@ Good News: ## Usage Currently implemented command(s): +- `click` - Click on mouse buttons +- `mousemove` - Move mouse pointer to absolute position - `type` - Type a string - `key` - Press keys -- `mousemove` - Move mouse pointer to absolute position -- `click` - Click on mouse buttons +- `debug` - Print the socket, number of parameters and parameter values +- `bakers` - Show the honorable bakers +- `stdin` - Sends the key presses as it was a keyboard (i.e from ssh) See [PR #229](https://github.com/ReimuNotMoe/ydotool/pull/229) ## Examples Switch to tty1 (Ctrl+Alt+F1), wait 2 seconds, and type some words: @@ -65,9 +68,13 @@ Mouse repeating left click: ydotool click --repeat 5 --next-delay 25 0xC0 +Repeat the keyboard presses from stdin: + + ydotool stdin + ## Notes #### Runtime -This program requires access to `/dev/uinput`. **This usually requires root permissions.** +`ydotoold` (daemon) program requires access to `/dev/uinput`. **This usually requires root permissions.** #### Available key names See `/usr/include/linux/input-event-codes.h` @@ -84,7 +91,7 @@ In order to solve this problem, a persistent background service, ydotoold, is ma Since v1.0.0, the use of ydotoold is mandatory. ## Build -**CMake 3.4+ is required.** +**CMake 3.22+ is required.** ### Compile @@ -126,7 +133,6 @@ device:ydotoold-virtual-device { #### Use a hardware-configurable keyboard [As mentioned here](https://github.com/ReimuNotMoe/ydotool/issues/43#issuecomment-605921288), consider using a hardware-based configuration that supports using a custom layout without configuring it in software. -## Older Notes ### Current situation This project is now being maintained **thanks to all the people that are supporting this project!** diff --git a/manpage/ydotool.1.scd b/manpage/ydotool.1.scd index cfcce05..7e7db10 100644 --- a/manpage/ydotool.1.scd +++ b/manpage/ydotool.1.scd @@ -25,6 +25,8 @@ Currently implemented command(s): Move mouse pointer to absolute position *click* Click on mouse buttons +*stdin* + Resend all keypresses as a keyboard (i.e. from ssh) # KEYBOARD COMMANDS *key* [*-d*,*--key-delay* __] [__ ...] diff --git a/manpage/ydotoold.8.scd b/manpage/ydotoold.8.scd index 5c33cb4..15ce4f9 100644 --- a/manpage/ydotoold.8.scd +++ b/manpage/ydotoold.8.scd @@ -20,8 +20,23 @@ ydotoold \- daemon for *ydotool*(1) *-P*, *--socket-perm arg* __ Set socket permission. + *-o*, *--socket-own=UID:GID* + Socket ownership. + + *-m*, *--mouse-off* + Disable mouse (EV_REL) + + *-k*, *--keyboard-off* + Disable keyboard (EV_KEY) + + *-T*, *--touch-on* + Enable touchscreen (EV_ABS) + *-h*, *--help* Display help and exit. + + *-V*, *--version* + Show version information. # AUTHOR