mirror of
https://gitlab.com/interception/linux/plugins/caps2esc.git
synced 2025-07-07 11:28:50 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
0c8326646a | |||
5c7e6b5a5d | |||
7428d959e0 | |||
e5dc581ddf |
32
caps2esc.c
32
caps2esc.c
@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
const struct input_event
|
const struct input_event
|
||||||
syn = {.type = EV_SYN, .code = SYN_REPORT, .value = 0},
|
syn = {.type = EV_SYN , .code = SYN_REPORT , .value = 0},
|
||||||
esc_up = {.type = EV_KEY, .code = KEY_ESC, .value = 0},
|
esc_up = {.type = EV_KEY , .code = KEY_ESC , .value = 0},
|
||||||
ctrl_up = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 0},
|
ctrl_up = {.type = EV_KEY , .code = KEY_LEFTCTRL , .value = 0},
|
||||||
esc_down = {.type = EV_KEY, .code = KEY_ESC, .value = 1},
|
esc_down = {.type = EV_KEY , .code = KEY_ESC , .value = 1},
|
||||||
ctrl_down = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 1};
|
ctrl_down = {.type = EV_KEY , .code = KEY_LEFTCTRL , .value = 1};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
void print_usage(FILE *stream, const char *program) {
|
void print_usage(FILE *stream, const char *program) {
|
||||||
@ -46,6 +46,9 @@ void write_event(const struct input_event *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void write_event_with_mode(struct input_event *event, int mode) {
|
void write_event_with_mode(struct input_event *event, int mode) {
|
||||||
|
if (event->type == EV_REL || event->type == EV_ABS)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
if (event->code == KEY_ESC)
|
if (event->code == KEY_ESC)
|
||||||
@ -71,12 +74,12 @@ int main(int argc, char *argv[]) {
|
|||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return print_usage(stdout, argv[0]), EXIT_SUCCESS;
|
return print_usage(stdout, argv[0]), EXIT_SUCCESS;
|
||||||
case 't':
|
|
||||||
delay = atoi(optarg);
|
|
||||||
continue;
|
|
||||||
case 'm':
|
case 'm':
|
||||||
mode = atoi(optarg);
|
mode = atoi(optarg);
|
||||||
continue;
|
continue;
|
||||||
|
case 't':
|
||||||
|
delay = atoi(optarg);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return print_usage(stderr, argv[0]), EXIT_FAILURE;
|
return print_usage(stderr, argv[0]), EXIT_FAILURE;
|
||||||
@ -91,20 +94,22 @@ int main(int argc, char *argv[]) {
|
|||||||
if (input.type == EV_MSC && input.code == MSC_SCAN)
|
if (input.type == EV_MSC && input.code == MSC_SCAN)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (input.type != EV_KEY) {
|
if (input.type != EV_KEY && input.type != EV_REL &&
|
||||||
|
input.type != EV_ABS) {
|
||||||
write_event(&input);
|
write_event(&input);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case START:
|
case START:
|
||||||
if (input.code == KEY_CAPSLOCK && input.value)
|
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK &&
|
||||||
|
input.value)
|
||||||
state = CAPSLOCK_HELD;
|
state = CAPSLOCK_HELD;
|
||||||
else
|
else
|
||||||
write_event_with_mode(&input, mode);
|
write_event_with_mode(&input, mode);
|
||||||
break;
|
break;
|
||||||
case CAPSLOCK_HELD:
|
case CAPSLOCK_HELD:
|
||||||
if (input.code == KEY_CAPSLOCK) {
|
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK) {
|
||||||
if (input.value == 0) {
|
if (input.value == 0) {
|
||||||
write_event(&esc_down);
|
write_event(&esc_down);
|
||||||
write_event(&syn);
|
write_event(&syn);
|
||||||
@ -112,7 +117,8 @@ int main(int argc, char *argv[]) {
|
|||||||
write_event(&esc_up);
|
write_event(&esc_up);
|
||||||
state = START;
|
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(&ctrl_down);
|
||||||
write_event(&syn);
|
write_event(&syn);
|
||||||
usleep(delay);
|
usleep(delay);
|
||||||
@ -122,7 +128,7 @@ int main(int argc, char *argv[]) {
|
|||||||
write_event_with_mode(&input, mode);
|
write_event_with_mode(&input, mode);
|
||||||
break;
|
break;
|
||||||
case CAPSLOCK_IS_CTRL:
|
case CAPSLOCK_IS_CTRL:
|
||||||
if (input.code == KEY_CAPSLOCK) {
|
if (input.type == EV_KEY && input.code == KEY_CAPSLOCK) {
|
||||||
input.code = KEY_LEFTCTRL;
|
input.code = KEY_LEFTCTRL;
|
||||||
write_event(&input);
|
write_event(&input);
|
||||||
if (input.value == 0)
|
if (input.value == 0)
|
||||||
|
Reference in New Issue
Block a user