Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Idea: Activate by hotkey instead of right-click #56

Open
kstenschke opened this issue Jan 28, 2017 · 6 comments
Open

Feature Idea: Activate by hotkey instead of right-click #56

kstenschke opened this issue Jan 28, 2017 · 6 comments
Assignees

Comments

@kstenschke
Copy link

kstenschke commented Jan 28, 2017

First of all thank you for this great app!
Especially when using a trackball, drawing gestures with a concurrent keypress (instead of having to keep the right mousebutton pressed) would, in my opinion, make usage much more comfortable.

P.s. i am for now using Karabiner to achieve firing a right mousebutton press on a certain key press.

@jiegec
Copy link
Member

jiegec commented Jan 29, 2017

Yes, this feature is useful especially when using Trackpad. I will implement it.

@jiegec
Copy link
Member

jiegec commented Jan 30, 2017

Partially implemented. Wondering how to edit the UI.

diff --git a/MacGesture/AppDelegate.m b/MacGesture/AppDelegate.m
index 984ef3e..e9c0c57 100644
--- a/MacGesture/AppDelegate.m
+++ b/MacGesture/AppDelegate.m
@@ -36,8 +36,16 @@ static BOOL eventTriggered;
     }
     
     windowController = [[CanvasWindowController alloc] init];
+    
+    NSDictionary *options = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES};
+    if(!AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options)) {
+        // bad
+        int i = 0;
+    }
 
-    CGEventMask eventMask = CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventRightMouseDragged) | CGEventMaskBit(kCGEventRightMouseUp) | CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventScrollWheel);
+    CGEventMask eventMask = CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventRightMouseDragged) |
+        CGEventMaskBit(kCGEventRightMouseUp) | CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventScrollWheel) |
+        CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventMouseMoved);
     mouseEventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, eventMask, mouseEventCallback, NULL);
     CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, mouseEventTap, 0);
     CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
@@ -211,6 +219,8 @@ void resetDirection() {
 // See https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/#//apple_ref/c/tdef/CGEventTapCallBack
 static CGEventRef mouseEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
     static BOOL shouldShow;
+    NSInteger keycode;
+    NSInteger filterKeycode = kVK_F1;
     
     if (!isEnabled) {
         return event;
@@ -218,6 +228,11 @@ static CGEventRef mouseEventCallback(CGEventTapProxy proxy, CGEventType type, CG
     
     NSEvent *mouseEvent;
     switch (type) {
+        case kCGEventKeyDown:
+            keycode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
+            if (keycode != filterKeycode || shouldShow) {
+                return event;
+            }
         case kCGEventRightMouseDown:
             // not thread safe, but it's always called in main thread
             // check blocker apps
@@ -261,6 +276,7 @@ static CGEventRef mouseEventCallback(CGEventTapProxy proxy, CGEventType type, CG
             [windowController handleMouseEvent:mouseEvent];
             lastLocation = mouseEvent.locationInWindow;
             break;
+        case kCGEventMouseMoved:
         case kCGEventRightMouseDragged:
             if (!shouldShow){
                 return event;
@@ -304,6 +320,11 @@ static CGEventRef mouseEventCallback(CGEventTapProxy proxy, CGEventType type, CG
                 updateDirections(mouseEvent);
             }
             break;
+        case kCGEventKeyUp:
+            keycode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
+            if (keycode != filterKeycode) {
+                return event;
+            }
         case kCGEventRightMouseUp: {
             if (!shouldShow){
                 return event;
diff --git a/MacGesture/CanvasWindowController.m b/MacGesture/CanvasWindowController.m
index 4b8db5d..27a6bfb 100644
--- a/MacGesture/CanvasWindowController.m
+++ b/MacGesture/CanvasWindowController.m
@@ -50,12 +50,15 @@
 
 - (void)handleMouseEvent:(NSEvent *)event {
     switch (event.type) {
+        case NSKeyDown:
         case NSRightMouseDown:
             [self.window.contentView mouseDown:event];
             break;
+        case NSMouseMoved:
         case NSRightMouseDragged:
             [self.window.contentView mouseDragged:event];
             break;
+        case NSKeyUp:
         case NSRightMouseUp:
             [self.window.contentView mouseUp:event];
             break;

@kstenschke
Copy link
Author

kstenschke commented Jan 30, 2017

activation

I would imagine something like the above, with 1. clicking the "Activate by Keypress" radio option without having a key selected yet starting the same key-listener as clicking the related "Chose", and 2. clicking "Chose" automatically selecting the radio option (and 3. removing the key deselecting the related radio option also).

@jiegec
Copy link
Member

jiegec commented Jan 30, 2017

I am considering the extensibility of this feature. Should it support only one key, or a shortcut? Should it support modifier keys? Also, capturing keyboard events seems intrusive.

@kstenschke
Copy link
Author

kstenschke commented Jan 30, 2017

To my thinking a single modifier key or combination of modifier keys is the most intuitive as it is performed simultaneous, at the same time as doing the gesture movement.
A shortcut, as in pressed once before performing the gesture movement, seems disruptive to me as it adds one "noticable" separate step before doing the gesture movement. But different people might perceive this differently.

@jiegec
Copy link
Member

jiegec commented Jan 30, 2017

@codefalling WDYT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants