Skip to content

Commit

Permalink
Hold the eventTap reference, #39
Browse files Browse the repository at this point in the history
  • Loading branch information
aahung committed Apr 1, 2019
1 parent 0f17590 commit ddd536d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Unshaky/ShakyPressPreventer.m
Expand Up @@ -21,6 +21,8 @@ @implementation ShakyPressPreventer {
int keyDelays[N_VIRTUAL_KEY];
BOOL ignoreExternalKeyboard;
Handler shakyPressDismissedHandler;

CFMachPortRef eventTap;
}

static NSDictionary<NSNumber *, NSString *> *_keyCodeToString;
Expand All @@ -37,6 +39,7 @@ + (ShakyPressPreventer *)sharedInstance {

- (instancetype)init {
if (self = [super init]) {
eventTap = NULL;
[self loadKeyDelays];
[self loadIgnoreExternalKeyboard];
[self loadWorkaroundForCmdSpace];
Expand Down Expand Up @@ -189,8 +192,8 @@ - (CGEventRef)filterShakyPressEvent:(CGEventRef)event {
- (BOOL)setupInputDeviceListener {

CGEventMask eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp) | (1 << kCGEventFlagsChanged));
CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0,
eventMask, myCGEventCallback, (__bridge void *)(self));
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0,
eventMask, eventTapCallback, (__bridge void *)(self));
if (!eventTap) {
NSLog(@"Permission issue");
return NO;
Expand Down

0 comments on commit ddd536d

Please sign in to comment.