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

Capture Magic Mouse tap gestures #28

Closed
aff opened this issue Aug 19, 2021 · 4 comments
Closed

Capture Magic Mouse tap gestures #28

aff opened this issue Aug 19, 2021 · 4 comments

Comments

@aff
Copy link

aff commented Aug 19, 2021

Hi and thanks for open sourcing this awesome tool!

Question: Is it possible to capture Magic Mouse tap gestures (e.g. to simulate tap-to-click)? I´ve tried adding a "print(action)" on line 39 on EventManager.swift, and it seems only keyboard actions trigger anything to the output terminal. Please advise.

Thanks again and best regards.

@creasty
Copy link
Owner

creasty commented Aug 20, 2021

Currently, it only intercepts keyboard events:

let eventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue)

If you want to handle click events, include leftMouseDown & leftMouseUp to the mask.
c.f., https://developer.apple.com/documentation/coregraphics/cgeventtype

@aff
Copy link
Author

aff commented Aug 23, 2021

Hi and many thanks for the suggestion. I´ve tried adding your suggested code, and even let eventMask = NSEvent.EventTypeMask.any.rawValue, but I can still not make it catch mouse events (clicks, taps, anything). Do keyboard and mouse events work differently?

@creasty
Copy link
Owner

creasty commented Aug 27, 2021

Please read the code more carefully.
It worked on my end.

index 961a81b..9a94825 100644
--- a/keyboard/AppComponent.swift
+++ b/keyboard/AppComponent.swift
@@ -20,6 +20,8 @@ final class AppComponent {
             if let manager = _eventManager {
                 return manager.handle(proxy: proxy, cgEvent: event)
             }
+        case .leftMouseDown:
+            print("leftMouseDown!")
         default:
             break
         }
diff --git a/keyboard/AppDelegate.swift b/keyboard/AppDelegate.swift
index bc39af6..84303b7 100644
--- a/keyboard/AppDelegate.swift
+++ b/keyboard/AppDelegate.swift
@@ -70,7 +70,7 @@ private extension AppDelegate {
     }

     func setupEventTap() {
-        let eventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue)
+        let eventMask = (1 << CGEventType.keyDown.rawValue) | (1 << CGEventType.keyUp.rawValue) | (1 << CGEventType.leftMouseDown.rawValue)

         guard let eventTap = CGEvent.tapCreate(
             tap: .cghidEventTap,

@aff
Copy link
Author

aff commented Aug 27, 2021

Fantastic, thank you! (I missed the AppComponent.swift part, I am sorry and I apologize)

@aff aff closed this as completed Aug 27, 2021
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

2 participants