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 |
22
caps2esc.c
22
caps2esc.c
@ -46,6 +46,9 @@ void write_event(const struct input_event *event) {
|
||||
}
|
||||
|
||||
void write_event_with_mode(struct input_event *event, int mode) {
|
||||
if (event->type == EV_REL || event->type == EV_ABS)
|
||||
return;
|
||||
|
||||
switch (mode) {
|
||||
case 0:
|
||||
if (event->code == KEY_ESC)
|
||||
@ -71,12 +74,12 @@ int main(int argc, char *argv[]) {
|
||||
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 +94,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 +117,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 +128,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)
|
||||
|
Reference in New Issue
Block a user