mirror of
https://gitlab.com/interception/linux/plugins/caps2esc.git
synced 2025-07-07 11:28:50 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb09cd8d9a | |||
0d88388a9e | |||
9f353f96c6 | |||
27efcbbf96 | |||
6fa3ad14b3 | |||
40137670a4 |
14
README.md
14
README.md
@ -4,9 +4,7 @@ _Transforming the most useless key **ever** in the most useful one._
|
|||||||
<sub>_For vi/Vim/NeoVim addicts at least_.</sub>
|
<sub>_For vi/Vim/NeoVim addicts at least_.</sub>
|
||||||
|
|
||||||
<a href="http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/">
|
<a href="http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/">
|
||||||
|
<img src="http://www.catonmat.net/images/why-vim-uses-hjkl/lsi-adm3a-full-keyboard.jpg" alt="ADM-3A terminal">
|
||||||

|
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## What is it?
|
## What is it?
|
||||||
@ -28,8 +26,8 @@ ESC when pressed alone is quite handy, specially in vi.
|
|||||||
## Building
|
## Building
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone git@gitlab.com:interception/linux/tools.git
|
$ git clone git@gitlab.com:interception/linux/plugins/caps2esc.git
|
||||||
$ cd tools
|
$ cd caps2esc
|
||||||
$ mkdir build
|
$ mkdir build
|
||||||
$ cd build
|
$ cd build
|
||||||
$ cmake ..
|
$ cmake ..
|
||||||
@ -58,6 +56,12 @@ I'm maintaining an Archlinux package on AUR:
|
|||||||
|
|
||||||
- <https://aur.archlinux.org/packages/interception-caps2esc>
|
- <https://aur.archlinux.org/packages/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
|
||||||
|
|
||||||
As always, there's always a caveat:
|
As always, there's always a caveat:
|
||||||
|
11
caps2esc.c
11
caps2esc.c
@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@ -13,7 +14,8 @@ ctrl_down = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 1},
|
|||||||
capslock_down = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 1},
|
capslock_down = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 1},
|
||||||
esc_repeat = {.type = EV_KEY, .code = KEY_ESC, .value = 2},
|
esc_repeat = {.type = EV_KEY, .code = KEY_ESC, .value = 2},
|
||||||
ctrl_repeat = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 2},
|
ctrl_repeat = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 2},
|
||||||
capslock_repeat = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 2};
|
capslock_repeat = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 2},
|
||||||
|
syn = {.type = EV_SYN, .code = SYN_REPORT, .value = 0};
|
||||||
// clang-format on
|
// 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) {
|
||||||
@ -37,6 +39,9 @@ int main(void) {
|
|||||||
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;
|
||||||
@ -55,6 +60,8 @@ int main(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
write_event(&esc_down);
|
write_event(&esc_down);
|
||||||
|
write_event(&syn);
|
||||||
|
usleep(20000);
|
||||||
write_event(&esc_up);
|
write_event(&esc_up);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -62,6 +69,8 @@ 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;
|
||||||
|
Reference in New Issue
Block a user