24 Commits

Author SHA1 Message Date
6ad0031138 Mention Void Linux install
Closes #22
2021-08-22 09:28:44 -03:00
56ea92caa2 Update README 2021-05-10 23:01:58 -03:00
4f1abaf937 Add install step for Ubuntu 2021-04-02 13:03:17 -03:00
1d92f46e4e Update README 2021-01-13 10:57:03 -03:00
dd7cb3e467 Remove Ubuntu notice to let it open to contributions 2021-01-13 10:54:51 -03:00
aae8117eeb "usage" uniformity 2021-01-07 16:07:59 -03:00
b99ee5b6be Update README 2021-01-07 02:30:53 -03:00
3c0b816499 Update README 2021-01-07 02:29:20 -03:00
be414120a2 Update README 2021-01-07 02:24:06 -03:00
5cffbf6bb5 Formatting 2021-01-02 21:42:05 -03:00
9aa9985b0e Update README 2021-01-01 11:58:39 -03:00
466062ef00 Update README 2021-01-01 07:44:58 -03:00
975bb74284 Passthrough mouse events
To not block mice that have keys, which end up grabbed due to generic
configurations that simply filter anything that responds to CAPSLOCK/ESC.

Fixes #15
2021-01-01 00:18:03 -03:00
8bfd57eda2 Formatting 2020-12-30 23:40:02 -03:00
186b887e7d Make multi device example more robust
The previous one won't work when devices reattach.
2020-12-30 23:16:17 -03:00
c738e8783a Formatting 2020-12-30 21:32:58 -03:00
a062311ffb Formatting 2020-12-30 21:19:31 -03:00
ac6bbe61c2 Update README 2020-12-29 09:26:35 -03:00
12dc2f75c7 Update README 2020-12-29 03:47:41 -03:00
3eaf2bddfe Update README 2020-12-29 03:46:32 -03:00
0c8326646a Expand mouse support
Until now mouse support existed just as side effect of muxing and that
mouse clicks are registered as key events. This expands the support for
mouse wheel and movement.
2020-12-29 02:43:04 -03:00
5c7e6b5a5d Formatting 2020-12-28 23:35:47 -03:00
7428d959e0 Formatting 2020-12-28 23:31:58 -03:00
e5dc581ddf Formatting 2020-12-28 23:24:11 -03:00
2 changed files with 80 additions and 64 deletions

View File

@ -25,8 +25,8 @@ ESC when pressed alone is quite handy, specially in vi.
## Building
```
$ git clone git@gitlab.com:interception/linux/plugins/caps2esc.git
```text
$ git clone https://gitlab.com/interception/linux/plugins/caps2esc.git
$ cd caps2esc
$ cmake -B build -DCMAKE_BUILD_TYPE=Release
$ cmake --build build
@ -34,10 +34,10 @@ $ cmake --build build
## Execution
```
```text
caps2esc - transforming the most useless key ever in the most useful one
usage: caps2esc [-h] [-m mode] [-t delay]
usage: caps2esc [-h | [-m mode] [-t delay]]
options:
-h show this message and exit
@ -54,56 +54,67 @@ options:
```
`caps2esc` is an [_Interception Tools_][interception-tools] plugin. A suggested
`udevmon` job configuration is:
`udevmon` job configuration (check the [_Interception Tools_
README][interception-tools] for alternatives) is:
```yaml
- JOB: intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
DEVICE:
EVENTS:
EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
```
For more information about the [_Interception Tools_][interception-tools], check
the project's website.
## Mouse button support
## Mouse/Touchpad Support
After _Interception Tools_ 0.3, `caps2esc` can work with mouse clicks. An
example configuration taken from my laptop:
After _Interception Tools_ 0.3.2, `caps2esc` can observe (or replace) mouse
events. An example configuration taken from my laptop:
```yaml
SHELL: [zsh, -c]
---
- JOB: mux -c caps2esc
- JOB:
- intercept -g $DEVNODE | mux -o caps2esc
- mux -i caps2esc | caps2esc | uinput -d $DEVNODE
- CMD: mux -c caps2esc
- JOB: mux -i caps2esc | caps2esc | uinput -c /etc/interception/keyboard.yaml
- JOB: intercept -g $DEVNODE | mux -o caps2esc
DEVICE:
LINK: /dev/input/by-path/platform-i8042-serio-0-event-kbd
- JOB:
- intercept $DEVNODE | mux -o caps2esc
- JOB: intercept $DEVNODE | mux -o caps2esc
DEVICE:
LINK: /dev/input/by-path/platform-i8042-serio-4-event-mouse
```
For more information on the topic, check the [_Interception Tools_
README][interception-tools] about usage of the `mux` tool and device specific
setups.
README][interception-tools] about usage of the `mux` tool and hybrid virtual
device configurations.
## Installation
### Archlinux
It's available from [community](https://archlinux.org/packages/community/x86_64/interception-caps2esc/):
```
```text
$ pacman -S interception-caps2esc
```
I don't use Ubuntu and recommend Archlinux instead, as it provides the AUR, so I
don't maintain PPAs. For more information on Ubuntu/Debian installation check
this:
### Void Linux
- <https://askubuntu.com/questions/979359/how-do-i-install-caps2esc>
```text
$ xbps-install -S caps2esc
```
### Ubuntu ([independent package][ubuntu])
```text
sudo add-apt-repository ppa:deafmute/interception
sudo apt install interception-caps2esc
```
<sub>For debian and other derivatives you can download directly at https://launchpad.net/~deafmute/+archive/ubuntu/interception/+packages.</sub>
[ubuntu]: https://gitlab.com/interception/linux/tools/-/issues/38
## Caveats

View File

@ -6,11 +6,11 @@
// clang-format off
const struct input_event
syn = {.type = EV_SYN, .code = SYN_REPORT, .value = 0},
esc_up = {.type = EV_KEY, .code = KEY_ESC, .value = 0},
ctrl_up = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 0},
esc_down = {.type = EV_KEY, .code = KEY_ESC, .value = 1},
ctrl_down = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 1};
syn = {.type = EV_SYN , .code = SYN_REPORT , .value = 0},
esc_up = {.type = EV_KEY , .code = KEY_ESC , .value = 0},
ctrl_up = {.type = EV_KEY , .code = KEY_LEFTCTRL , .value = 0},
esc_down = {.type = EV_KEY , .code = KEY_ESC , .value = 1},
ctrl_down = {.type = EV_KEY , .code = KEY_LEFTCTRL , .value = 1};
// clang-format on
void print_usage(FILE *stream, const char *program) {
@ -18,20 +18,20 @@ void print_usage(FILE *stream, const char *program) {
fprintf(stream,
"caps2esc - transforming the most useless key ever in the most useful one\n"
"\n"
"usage: %s [-h] [-m mode] [-t delay]\n"
"usage: %s [-h | [-m mode] [-t delay]]\n"
"\n"
"options:\n"
" -h show this message and exit\n"
" -t delay used for key sequences (default: 20000 microseconds)\n"
" -m mode 0: default\n"
" - caps as esc/ctrl\n"
" - esc as caps\n"
" 1: minimal\n"
" - caps as esc/ctrl\n"
" 2: useful on 60%% layouts\n"
" - caps as esc/ctrl\n"
" - esc as grave accent\n"
" - grave accent as caps\n",
" -h show this message and exit\n"
" -t delay used for key sequences (default: 20000 microseconds)\n"
" -m mode 0: default\n"
" - caps as esc/ctrl\n"
" - esc as caps\n"
" 1: minimal\n"
" - caps as esc/ctrl\n"
" 2: useful on 60%% layouts\n"
" - caps as esc/ctrl\n"
" - esc as grave accent\n"
" - grave accent as caps\n",
program);
// clang-format on
}
@ -46,37 +46,39 @@ void write_event(const struct input_event *event) {
}
void write_event_with_mode(struct input_event *event, int mode) {
switch (mode) {
case 0:
if (event->code == KEY_ESC)
event->code = KEY_CAPSLOCK;
break;
case 2:
switch (event->code) {
case KEY_ESC:
event->code = KEY_GRAVE;
break;
case KEY_GRAVE:
if (event->type == EV_KEY)
switch (mode) {
case 0:
if (event->code == KEY_ESC)
event->code = KEY_CAPSLOCK;
break;
}
break;
}
break;
case 2:
switch (event->code) {
case KEY_ESC:
event->code = KEY_GRAVE;
break;
case KEY_GRAVE:
event->code = KEY_CAPSLOCK;
break;
}
break;
}
write_event(event);
}
int main(int argc, char *argv[]) {
int opt, mode = 0, delay = 20000;
while ((opt = getopt(argc, argv, "ht:m:")) != -1) {
int mode = 0, delay = 20000;
for (int opt; (opt = getopt(argc, argv, "ht:m:")) != -1;) {
switch (opt) {
case 'h':
return print_usage(stdout, argv[0]), EXIT_SUCCESS;
case 't':
delay = atoi(optarg);
continue;
case 'm':
mode = atoi(optarg);
continue;
case 't':
delay = atoi(optarg);
continue;
}
return print_usage(stderr, argv[0]), EXIT_FAILURE;
@ -91,20 +93,22 @@ int main(int argc, char *argv[]) {
if (input.type == EV_MSC && input.code == MSC_SCAN)
continue;
if (input.type != EV_KEY) {
if (input.type != EV_KEY && input.type != EV_REL &&
input.type != EV_ABS) {
write_event(&input);
continue;
}
switch (state) {
case START:
if (input.code == KEY_CAPSLOCK && input.value)
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK &&
input.value)
state = CAPSLOCK_HELD;
else
write_event_with_mode(&input, mode);
break;
case CAPSLOCK_HELD:
if (input.code == KEY_CAPSLOCK) {
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK) {
if (input.value == 0) {
write_event(&esc_down);
write_event(&syn);
@ -112,7 +116,8 @@ int main(int argc, char *argv[]) {
write_event(&esc_up);
state = START;
}
} else if (input.value == 1) {
} else if ((input.type == EV_KEY && input.value == 1) ||
input.type == EV_REL || input.type == EV_ABS) {
write_event(&ctrl_down);
write_event(&syn);
usleep(delay);
@ -122,7 +127,7 @@ int main(int argc, char *argv[]) {
write_event_with_mode(&input, mode);
break;
case CAPSLOCK_IS_CTRL:
if (input.code == KEY_CAPSLOCK) {
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK) {
input.code = KEY_LEFTCTRL;
write_event(&input);
if (input.value == 0)