mirror of
https://github.com/neon443/DockPhobia.git
synced 2026-03-11 06:49:12 +00:00
mouse tracking
This commit is contained in:
@@ -292,6 +292,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -320,6 +321,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.DockPhobia;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import AppKit
|
||||
|
||||
@main
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
@IBOutlet var window: NSWindow!
|
||||
|
||||
var mouseTracker = MouseTracker()
|
||||
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
// Insert code here to initialize your application
|
||||
while true {
|
||||
printMouse()
|
||||
sleep(1)
|
||||
}
|
||||
mouseTracker.addMonitor()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
@@ -29,4 +29,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,58 @@
|
||||
import Foundation
|
||||
import AppKit
|
||||
import Cocoa
|
||||
import CoreGraphics
|
||||
|
||||
func printMouse() {
|
||||
let mouseLoc: NSPoint
|
||||
mouseLoc = NSEvent.mouseLocation
|
||||
print(mouseLoc)
|
||||
struct Screen {
|
||||
var width: CGFloat
|
||||
var height: CGFloat
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user