Я хотел бы отображать уведомление каждый раз, когда мышь перемещается в течение 15 секунд.
Пока я, кажется, понимаю, мне нужно добавить
window.acceptsMouseMovedEvents = true
и мне нужно переопределить MouseMoved
override func mouseMoved(with event: NSEvent) {
//print ("MOVED!")
timer.invalidate()
displayNotification()
}
func displayNotification(){
var timeLeft = 15
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
let notification = NSUserNotification()
notification.title = "Title of notification"
notification.subtitle = "Subtitle of notification"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default.deliver(notification)
timeLeft -= 1
if(timeLeft==0){
timer.invalidate()
}
}
}
Я не могу заставить работать мышь MouseMoved.