I am novice Swift coder trying to catch mouse events as well as keyboard events. It seems I am only doing the latter. The main goal is to allow for «tap-to-click» with Magic Mouse 2 and avoid its loud clicking sound.
Fully working sample at https://github.com/creasty/Keyboard/blob/master/keyboard/AppDelegate.swift
let eventMask =
(1 << CGEventType.keyDown.rawValue) |
(1 << CGEventType.keyUp.rawValue) |
(1 << CGEventType.leftMouseDown.rawValue) |
(1 << CGEventType.leftMouseUp.rawValue)
guard let eventTap = CGEvent.tapCreate(
tap: .cghidEventTap,
place: .headInsertEventTap,
options: .defaultTap,
eventsOfInterest: CGEventMask(eventMask),
callback: appComponent.eventTapCallback,
userInfo: nil
) else {
fatalError("Failed to create event tap")
}
Keyboard presses are caught alright, but no reaction to mouse clicks. Please advise. Thanks.
Xcode Version 12.5.1 (12E507) on MacOS 11.5.2