diff options
author | Christian Segundo | 2025-03-19 14:18:58 +0100 |
---|---|---|
committer | Christian Segundo | 2025-03-19 14:23:11 +0100 |
commit | 97e8f90bdd1802d4a08a5deb549fb1aa8e8d6768 (patch) | |
tree | d6eee8777fe733e8fce3afda14a46d3c3362c740 /main.c | |
download | osx-jiggler-97e8f90bdd1802d4a08a5deb549fb1aa8e8d6768.tar.gz |
First commit
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -0,0 +1,45 @@ +#include <ApplicationServices/ApplicationServices.h> + +int main(int argc, char *argv[]) { + double inactivity_threshold = 60.0; + int right = 0; + + if (argc > 1) { + if (strcmp(argv[1], "--help") == 0) { + printf("Usage: osx-jiggler [inactivity_threshold]\n"); + printf(" inactivity_threshold: Time in seconds before the mouse moves " + "(default: 60.0)\n"); + printf(" --help: Show this help message\n"); + return 0; + } + + inactivity_threshold = atof(argv[1]); + if (inactivity_threshold <= 0) { + fprintf(stderr, + "Invalid inactivity time. Please provide a positive number.\n"); + return 1; + } + } + + while (1) { + double idle_time = CGEventSourceSecondsSinceLastEventType( + kCGEventSourceStateHIDSystemState, kCGAnyInputEventType); + + if (idle_time >= inactivity_threshold) { + CGEventRef event = CGEventCreate(NULL); + CGPoint cursor = CGEventGetLocation(event); + CFRelease(event); + + (right) ? (cursor.x += 1) : (cursor.x -= 1); + right = !right; + + event = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, cursor, + kCGMouseButtonLeft); + CGEventPost(kCGHIDEventTap, event); + CFRelease(event); + } + sleep(1); + } + + return 0; +} |