mirror of
https://gitlab.com/interception/linux/plugins/caps2esc.git
synced 2025-07-06 19:13:21 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
230f5c70d3 | |||
15636b64e7 | |||
6ab17c7d1a | |||
220ca0bc71 | |||
bb09cd8d9a | |||
0d88388a9e | |||
9f353f96c6 |
62
README.md
62
README.md
@ -28,19 +28,35 @@ ESC when pressed alone is quite handy, specially in vi.
|
|||||||
```
|
```
|
||||||
$ git clone git@gitlab.com:interception/linux/plugins/caps2esc.git
|
$ git clone git@gitlab.com:interception/linux/plugins/caps2esc.git
|
||||||
$ cd caps2esc
|
$ cd caps2esc
|
||||||
$ mkdir build
|
$ cmake -B build -DCMAKE_BUILD_TYPE=Release
|
||||||
$ cd build
|
$ cmake --build build
|
||||||
$ cmake ..
|
|
||||||
$ make
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Execution
|
## Execution
|
||||||
|
|
||||||
|
```
|
||||||
|
caps2esc - transforming the most useless key ever in the most useful one
|
||||||
|
|
||||||
|
usage: caps2esc [-h] [-m mode]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h show this message and exit
|
||||||
|
-m mode 0: default
|
||||||
|
- caps as esc/ctrl
|
||||||
|
- esc as caps
|
||||||
|
1: minimal
|
||||||
|
- caps as esc/ctrl
|
||||||
|
2: useful on 60% layouts
|
||||||
|
- caps as esc/ctrl
|
||||||
|
- esc as grave accent
|
||||||
|
- grave accent as caps
|
||||||
|
```
|
||||||
|
|
||||||
`caps2esc` is an [_Interception Tools_][interception-tools] plugin. A suggested
|
`caps2esc` is an [_Interception Tools_][interception-tools] plugin. A suggested
|
||||||
`udevmon` job configuration is:
|
`udevmon` job configuration is:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE"
|
- JOB: intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
|
||||||
DEVICE:
|
DEVICE:
|
||||||
EVENTS:
|
EVENTS:
|
||||||
EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
|
EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
|
||||||
@ -50,11 +66,43 @@ $ make
|
|||||||
For more information about the [_Interception Tools_][interception-tools], check
|
For more information about the [_Interception Tools_][interception-tools], check
|
||||||
the project's website.
|
the project's website.
|
||||||
|
|
||||||
|
## Mouse button support
|
||||||
|
|
||||||
|
After _Interception Tools_ 0.3, `caps2esc` can work with mouse clicks. 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
|
||||||
|
DEVICE:
|
||||||
|
LINK: /dev/input/by-path/platform-i8042-serio-0-event-kbd
|
||||||
|
- 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.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
I'm maintaining an Archlinux package on AUR:
|
It's available from [community](https://archlinux.org/packages/community/x86_64/interception-caps2esc/):
|
||||||
|
|
||||||
- <https://aur.archlinux.org/packages/interception-caps2esc>
|
```
|
||||||
|
$ 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:
|
||||||
|
|
||||||
|
- <https://askubuntu.com/questions/979359/how-do-i-install-caps2esc>
|
||||||
|
|
||||||
## Caveats
|
## Caveats
|
||||||
|
|
||||||
|
61
caps2esc.c
61
caps2esc.c
@ -18,6 +18,28 @@ capslock_repeat = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 2},
|
|||||||
syn = {.type = EV_SYN, .code = SYN_REPORT, .value = 0};
|
syn = {.type = EV_SYN, .code = SYN_REPORT, .value = 0};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
void print_usage(FILE *stream, const char *program) {
|
||||||
|
// clang-format off
|
||||||
|
fprintf(stream,
|
||||||
|
"caps2esc - transforming the most useless key ever in the most useful one\n"
|
||||||
|
"\n"
|
||||||
|
"usage: %s [-h] [-m mode]\n"
|
||||||
|
"\n"
|
||||||
|
"options:\n"
|
||||||
|
" -h show this message and exit\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
|
||||||
|
}
|
||||||
|
|
||||||
int equal(const struct input_event *first, const struct input_event *second) {
|
int equal(const struct input_event *first, const struct input_event *second) {
|
||||||
return first->type == second->type && first->code == second->code &&
|
return first->type == second->type && first->code == second->code &&
|
||||||
first->value == second->value;
|
first->value == second->value;
|
||||||
@ -32,13 +54,29 @@ void write_event(const struct input_event *event) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char *argv[]) {
|
||||||
|
int opt, mode = 0;
|
||||||
|
while ((opt = getopt(argc, argv, "hm:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'h':
|
||||||
|
return print_usage(stdout, argv[0]), EXIT_SUCCESS;
|
||||||
|
case 'm':
|
||||||
|
mode = optarg[0] - '0';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return print_usage(stderr, argv[0]), EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
int capslock_is_down = 0, esc_give_up = 0;
|
int capslock_is_down = 0, esc_give_up = 0;
|
||||||
struct input_event input;
|
struct input_event input;
|
||||||
|
|
||||||
setbuf(stdin, NULL), setbuf(stdout, NULL);
|
setbuf(stdin, NULL), setbuf(stdout, NULL);
|
||||||
|
|
||||||
while (read_event(&input)) {
|
while (read_event(&input)) {
|
||||||
|
if (input.type == EV_MSC && input.code == MSC_SCAN)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (input.type != EV_KEY) {
|
if (input.type != EV_KEY) {
|
||||||
write_event(&input);
|
write_event(&input);
|
||||||
continue;
|
continue;
|
||||||
@ -66,14 +104,31 @@ int main(void) {
|
|||||||
if (!esc_give_up && input.value) {
|
if (!esc_give_up && input.value) {
|
||||||
esc_give_up = 1;
|
esc_give_up = 1;
|
||||||
write_event(&ctrl_down);
|
write_event(&ctrl_down);
|
||||||
|
write_event(&syn);
|
||||||
|
usleep(20000);
|
||||||
}
|
}
|
||||||
} else if (equal(&input, &capslock_down)) {
|
} else if (equal(&input, &capslock_down)) {
|
||||||
capslock_is_down = 1;
|
capslock_is_down = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.code == KEY_ESC)
|
switch (mode) {
|
||||||
input.code = KEY_CAPSLOCK;
|
case 0:
|
||||||
|
if (input.code == KEY_ESC)
|
||||||
|
input.code = KEY_CAPSLOCK;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
switch (input.code) {
|
||||||
|
case KEY_ESC:
|
||||||
|
input.code = KEY_GRAVE;
|
||||||
|
break;
|
||||||
|
case KEY_GRAVE:
|
||||||
|
input.code = KEY_CAPSLOCK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
write_event(&input);
|
write_event(&input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user