Skip to content

Commit 94fe670

Browse files
authored
Merge pull request #239 from Paiusco/update-readme-and-manual
Manual and README update
2 parents d1fe910 + bc1079d commit 94fe670

File tree

4 files changed

+87
-49
lines changed

4 files changed

+87
-49
lines changed

Client/tool_stdin.c

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "ydotool.h"
55

66
#define FLAG_UPPERCASE 0x80000000
7-
#define FLAG_CTRL 0x40000000
7+
#define FLAG_CTRL 0x40000000
88

99
static const int32_t ascii2keycode_map[128] = {
1010
// 00 - 0f
@@ -83,47 +83,47 @@ int tool_stdin(int argc, char **argv) {
8383
printf("Type anything (CTRL-C to exit):\n");
8484

8585
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
127127
}
128128

129129
return 0;

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ydotool will then be rewritten in JavaScript afterwards, to enable more people t
1515
The man page is not always up to date. Please use `--help` to ensure correctness.
1616

1717
## ChangeLog
18-
This project is now refactored. (v1.0.0)
18+
This project is now refactored. (from v1.0.0)
1919

2020
Changes:
2121
- Rewritten in pure C99
@@ -35,10 +35,13 @@ Good News:
3535

3636
## Usage
3737
Currently implemented command(s):
38+
- `click` - Click on mouse buttons
39+
- `mousemove` - Move mouse pointer to absolute position
3840
- `type` - Type a string
3941
- `key` - Press keys
40-
- `mousemove` - Move mouse pointer to absolute position
41-
- `click` - Click on mouse buttons
42+
- `debug` - Print the socket, number of parameters and parameter values
43+
- `bakers` - Show the honorable bakers
44+
- `stdin` - Sends the key presses as it was a keyboard (i.e from ssh) See [PR #229](https://github.com/ReimuNotMoe/ydotool/pull/229)
4245

4346
## Examples
4447
Switch to tty1 (Ctrl+Alt+F1), wait 2 seconds, and type some words:
@@ -65,9 +68,13 @@ Mouse repeating left click:
6568

6669
ydotool click --repeat 5 --next-delay 25 0xC0
6770

71+
Repeat the keyboard presses from stdin:
72+
73+
ydotool stdin
74+
6875
## Notes
6976
#### Runtime
70-
This program requires access to `/dev/uinput`. **This usually requires root permissions.**
77+
`ydotoold` (daemon) program requires access to `/dev/uinput`. **This usually requires root permissions.**
7178

7279
#### Available key names
7380
See `/usr/include/linux/input-event-codes.h`
@@ -84,18 +91,33 @@ In order to solve this problem, a persistent background service, ydotoold, is ma
8491
Since v1.0.0, the use of ydotoold is mandatory.
8592

8693
## Build
87-
**CMake 3.4+ is required.**
94+
**CMake 3.22+ is required.**
95+
96+
### Build options
97+
There are a few extra options that can be configured when running CMake
98+
99+
- BUILD_DOCS=ON|OFF - whether to build the documentation, depends on ``scdoc``. Default: ON
100+
- SYSTEMD_USER_SERVICE=ON|OFF - whether to use systemd user service file, depends on ``systemd``. Default: ON
101+
- SYSTEMD_SYSTEM_SERVICE=ON|OFF - whether to use systemd system service file, depends on ``systemd``. Default: OFF
102+
- OPENRC=ON|OFF - whether to use openrc service file. Default: OFF (TBD)
88103

89104

90105
### Compile
91-
At least on Fedora 39, might require ``sudo dnf install -y scdoc`` to have acccess to the ``scdoc`` manpage generator.
92106

93107
mkdir build
94108
cd build
95109
cmake ..
96110
make -j `nproc`
97111

112+
If issues appears, check the build options, but try to install the dependecies:
113+
114+
Debian-based:
115+
116+
sudo apt install scdoc
117+
118+
RHEL-based:
98119

120+
sudo dnf install scdoc
99121
## Troubleshooting
100122
### Custom keyboard layouts
101123
Currently, ydotool does not recognize if the user is using a custom keyboard layout. In order to comfortably use ydotool alongside a custom keyboard layout, the user could use one of the following fixes/workarounds:
@@ -126,7 +148,6 @@ device:ydotoold-virtual-device {
126148
#### Use a hardware-configurable keyboard
127149
[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.
128150

129-
## Older Notes
130151
### Current situation
131152
This project is now being maintained **thanks to all the people that are supporting this project!**
132153

manpage/ydotool.1.scd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Currently implemented command(s):
2525
Move mouse pointer to absolute position
2626
*click*
2727
Click on mouse buttons
28+
*stdin*
29+
Resend all keypresses as a keyboard (i.e. from ssh)
2830

2931
# KEYBOARD COMMANDS
3032
*key* [*-d*,*--key-delay* _<ms>_] [_<KEYCODE:PRESSED>_ ...]

manpage/ydotoold.8.scd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,23 @@ ydotoold \- daemon for *ydotool*(1)
2020
*-P*, *--socket-perm arg* _<perms>_
2121
Set socket permission.
2222

23+
*-o*, *--socket-own=UID:GID*
24+
Socket ownership.
25+
26+
*-m*, *--mouse-off*
27+
Disable mouse (EV_REL)
28+
29+
*-k*, *--keyboard-off*
30+
Disable keyboard (EV_KEY)
31+
32+
*-T*, *--touch-on*
33+
Enable touchscreen (EV_ABS)
34+
2335
*-h*, *--help*
2436
Display help and exit.
37+
38+
*-V*, *--version*
39+
Show version information.
2540

2641
# AUTHOR
2742

0 commit comments

Comments
 (0)