Skip to content

Commit

Permalink
Fix tap location on monitor with non-normalized frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Reeywhaar committed Sep 9, 2023
1 parent 43b89a8 commit 71313a6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions MiddleMe/GlobalEventMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ class GlobalEventMonitor {
let isSwipe = distance >= 0.005

if !isSwipe {
#if DEBUG
print("TAP!")
#else
generateMiddleClick()
#endif
generateMiddleClick()
}
}

Expand All @@ -95,14 +91,18 @@ class GlobalEventMonitor {
private func generateMiddleClick() {
guard let screen = getCurrentScreen() else { return }

#if DEBUG
print("TAP!", screen.localizedName, NSEvent.mouseLocation, screen.frame.minY)
#else
var position = NSEvent.mouseLocation
position.y = screen.frame.height - position.y
position.y = screen.frame.height - (position.y - screen.frame.minY)
let source = CGEventSource.init(stateID: .hidSystemState)
let eventDown = CGEvent(mouseEventSource: source, mouseType: .otherMouseDown, mouseCursorPosition: position , mouseButton: .center)
let eventUp = CGEvent(mouseEventSource: source, mouseType: .otherMouseUp, mouseCursorPosition: position , mouseButton: .center)
eventDown?.post(tap: .cghidEventTap)
usleep(100)
eventUp?.post(tap: .cghidEventTap)
#endif
}

private func getCurrentScreen() -> NSScreen? {
Expand Down

0 comments on commit 71313a6

Please sign in to comment.