From 692772f8094deb88614f5f5f3a3b323dffd3bb97 Mon Sep 17 00:00:00 2001
From: Eli Ribble <eli@theribbles.org>
Date: Thu, 26 Aug 2021 10:49:08 -0600
Subject: [PATCH] Add working C program to get tiny mouse movements.

Turns out that the Python mouse library is losing the fine-grained mouse
position data, which we really need.
---
 show-mouse.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 show-mouse.c

diff --git a/show-mouse.c b/show-mouse.c
new file mode 100644
index 0000000..87a944c
--- /dev/null
+++ b/show-mouse.c
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#define MOUSEFILE "/dev/input/mouse1"
+//
+int main()
+{
+    int fd;
+    struct input_event ie;
+    //
+    unsigned char button,bLeft,bMiddle,bRight;
+    char x,y;
+    int absolute_x,absolute_y;
+
+    if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
+        printf("Device open ERROR\n");
+        exit(EXIT_FAILURE);
+    }
+    else
+    {
+        printf("Device open OK\n");
+    }
+    //
+    printf("right-click to set absolute x,y coordinates origin (0,0)\n");
+    while(read(fd, &ie, sizeof(struct input_event)))
+    {
+        unsigned char *ptr = (unsigned char*)&ie;
+        int i;       
+        //
+        button=ptr[0];
+        bLeft = button & 0x1;
+        bMiddle = ( button & 0x4 ) > 0;
+        bRight = ( button & 0x2 ) > 0;
+        x=(char) ptr[1];y=(char) ptr[2];
+        // printf("bLEFT:%d, bMIDDLE: %d, bRIGHT: %d, rx: %d  ry=%d\n",bLeft,bMiddle,bRight, x,y);
+        //
+        absolute_x+=x;
+        absolute_y-=y;
+        if (bRight==1)
+        {
+            absolute_x=0;
+            absolute_y=0;
+            printf("Absolute x,y coords origin recorded\n");
+        }
+        //
+        printf("Absolute coords from TOP_LEFT= %i %i\n",absolute_x,absolute_y);
+        //
+        // comment to disable the display of raw event structure datas
+        //
+        for(i=0; i<sizeof(ie); i++)
+        {
+            printf("%02X ", *ptr++);
+        }
+        printf("\n");
+    }
+
+return 0;
+}