diff options
author | koekeishiya <aasvi93@hotmail.com> | 2019-04-13 19:09:39 +0200 |
---|---|---|
committer | koekeishiya <aasvi93@hotmail.com> | 2019-04-13 19:09:39 +0200 |
commit | 5b06e5102032ce799ca0ad5d1620ca56ec0883a0 (patch) | |
tree | 8be80baaa91136773e64ec209f78d6be020bc791 /src/skhd.c | |
parent | 52cde83ab83b115f0c136a48b5825d57753c94b8 (diff) | |
download | skhd-5b06e5102032ce799ca0ad5d1620ca56ec0883a0.tar.gz skhd-5b06e5102032ce799ca0ad5d1620ca56ec0883a0.zip |
#75 flag to launch in observer mode
Diffstat (limited to 'src/skhd.c')
-rw-r--r-- | src/skhd.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -114,6 +114,36 @@ internal CF_NOTIFICATION_CALLBACK(keymap_handler) END_TIMED_BLOCK(); } +internal EVENT_TAP_CALLBACK(key_observer_handler) +{ + switch (type) { + case kCGEventTapDisabledByTimeout: + case kCGEventTapDisabledByUserInput: { + debug("skhd: restarting event-tap\n"); + struct event_tap *event_tap = (struct event_tap *) reference; + CGEventTapEnable(event_tap->handle, 1); + } break; + case kCGEventKeyDown: + case kCGEventFlagsChanged: { + uint32_t flags = CGEventGetFlags(event); + uint32_t keycode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); + + if (keycode == kVK_ANSI_C && flags & 0x40000) { + exit(0); + } + + printf("\rkeycode: 0x%.2X\tflags: ", keycode); + for (int i = 31; i >= 0; --i) { + printf("%c", (flags & (1 << i)) ? '1' : '0'); + } + fflush(stdout); + + return NULL; + } break; + } + return event; +} + internal EVENT_TAP_CALLBACK(key_handler) { switch (type) { @@ -205,7 +235,7 @@ internal bool parse_arguments(int argc, char **argv) { int option; - const char *short_option = "VPvc:k:t:rh"; + const char *short_option = "VPvc:k:t:rho"; struct option long_option[] = { { "verbose", no_argument, NULL, 'V' }, { "profile", no_argument, NULL, 'P' }, @@ -215,6 +245,7 @@ parse_arguments(int argc, char **argv) { "key", required_argument, NULL, 'k' }, { "text", required_argument, NULL, 't' }, { "reload", no_argument, NULL, 'r' }, + { "observe", no_argument, NULL, 'o' }, { NULL, 0, NULL, 0 } }; @@ -249,6 +280,12 @@ parse_arguments(int argc, char **argv) if (pid) kill(pid, SIGUSR1); return true; } break; + case 'o': { + event_tap.mask = (1 << kCGEventKeyDown) | + (1 << kCGEventFlagsChanged); + event_tap_begin(&event_tap, key_observer_handler); + CFRunLoopRun(); + } break; } } |