nocaps.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <linux/input.h>
  4. #include "event.h"
  5. const struct input_event
  6. ctrl_up = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 0},
  7. capslock_up = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 0},
  8. ctrl_down = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 1},
  9. capslock_down = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 1},
  10. ctrl_repeat = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 2},
  11. capslock_repeat = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 2};
  12. int main(void) {
  13. int capslock_is_down = 0;
  14. struct input_event input;
  15. setbuf(stdin, NULL), setbuf(stdout, NULL);
  16. while (read_event(&input)) {
  17. if (input.type != EV_KEY) {
  18. write_event(&input);
  19. continue;
  20. }
  21. if (capslock_is_down) {
  22. if (equal(&input, &capslock_down) ||
  23. equal(&input, &capslock_repeat)) {
  24. continue;
  25. }
  26. if (equal(&input, &capslock_up)) {
  27. capslock_is_down = 0;
  28. write_event(&ctrl_up);
  29. continue;
  30. }
  31. if (input.value) {
  32. write_event(&ctrl_down);
  33. }
  34. } else {
  35. if (equal(&input, &capslock_down)) {
  36. capslock_is_down = 1;
  37. continue;
  38. }
  39. }
  40. write_event(&input);
  41. }
  42. }