mouse tracking

This commit is contained in:
neon443
2025-05-23 11:57:03 +01:00
parent 8d9f8294a4
commit 1a8963f464
3 changed files with 59 additions and 9 deletions

View File

@@ -292,6 +292,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@@ -320,6 +321,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia; PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -6,19 +6,19 @@
// //
import Cocoa import Cocoa
import AppKit
@main @main
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var window: NSWindow! @IBOutlet var window: NSWindow!
var mouseTracker = MouseTracker()
func applicationDidFinishLaunching(_ aNotification: Notification) { func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application // Insert code here to initialize your application
while true { mouseTracker.addMonitor()
printMouse()
sleep(1)
}
} }
func applicationWillTerminate(_ aNotification: Notification) { func applicationWillTerminate(_ aNotification: Notification) {
@@ -29,4 +29,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return true return true
} }
} }

View File

@@ -8,9 +8,58 @@
import Foundation import Foundation
import AppKit import AppKit
import Cocoa import Cocoa
import CoreGraphics
func printMouse() { struct Screen {
let mouseLoc: NSPoint var width: CGFloat
mouseLoc = NSEvent.mouseLocation var height: CGFloat
print(mouseLoc)
} }
class MouseTracker {
var screen: Screen
var monitor: NSEvent?
init() {
if let screen = NSScreen.main {
let rect = screen.frame
self.screen = Screen(
width: rect.width,
height: rect.height
)
print(self.screen)
} else {
fatalError("no screen wtf???")
}
addMonitor()
}
func checkMouse(_ event: NSEvent) {
var location = event.locationInWindow
print(location)
}
func addMonitor() {
self.monitor = NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved, handler: checkMouse) as? NSEvent
}
func removeMonitor() {
NSEvent.removeMonitor(monitor as Any)
}
}
/*- (void) startEventTap {
//eventTap is an ivar on this class of type CFMachPortRef
eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
CGEventTapEnable(eventTap, true);
}
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
if (type == kCGEventMouseMoved) {
NSLog(@"%@", NSStringFromPoint([NSEvent mouseLocation]));
}
return event;
}
*/