ActivityWatch / aw-watcher-afk

Watches keyboard and mouse activity to determine if you are AFK or not (for use with ActivityWatch)
Mozilla Public License 2.0
47 stars 34 forks source link

Use macOS API directly to detect input (instead of PyUserInput) #29

Closed ErikBjare closed 7 years ago

ErikBjare commented 7 years ago

This API should do it: https://developer.apple.com/documentation/coregraphics/cgeventsource/1408790-secondssincelasteventtype

ErikBjare commented 7 years ago

Since I'm now in possession of a Mac, I can actually do this.

We'd simply create a new file macos.py containing the necessary and remove the support for it in unix.py.

Especially important due to this problem.

ErikBjare commented 7 years ago

Turns out it was as easy as:

from Quartz.CoreGraphics import (CGEventSourceSecondsSinceLastEventType,
                                 kCGEventSourceStateHIDSystemState,
                                 kCGAnyInputEventType)
seconds_since_input = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType)