Skip to content

Commit

Permalink
Update readme/manual
Browse files Browse the repository at this point in the history
Extra update on stdin indentation
  • Loading branch information
Paiusco committed May 6, 2024
1 parent d1fe910 commit 3487f5e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 48 deletions.
84 changes: 42 additions & 42 deletions Client/tool_stdin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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!**

Expand Down
2 changes: 2 additions & 0 deletions manpage/ydotool.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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* _<ms>_] [_<KEYCODE:PRESSED>_ ...]
Expand Down
15 changes: 15 additions & 0 deletions manpage/ydotoold.8.scd
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ ydotoold \- daemon for *ydotool*(1)
*-P*, *--socket-perm arg* _<perms>_
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

Expand Down

0 comments on commit 3487f5e

Please sign in to comment.