Question: I need help with my c mouse position code so that it works properly. The mouse position is supposed to update when you move it

I need help with my c mouse position code so that it works properly. The mouse position is supposed to update when you move it and should keep updating the position as you move. The mouse left and right button clicked works but whenever I move the mouse it just keeps outputing the same position. How can I fix this.
I already compiled the code with -lxdo -lX11 at the end, and I run the code with sudo
#include
#include
#include
#include
#include
#include
int main(){
char info[10];
int dev_mouse =-1;
dev_mouse = open("/dev/input/mice", O_RDWR);
while (1){
read(dev_mouse, info, 3);
if (0x01 & info[0]) printf("%s", "left button down
");
if (0x02 & info[0]) printf("%s", "right button down
");
// Read in positions of your mouse and print them;
int x, y, scrn;
xdo_t *handle = xdo_new(NULL);
xdo_get_mouse_location(handle, &x, &y, &scrn);
xdo_free(handle);
printf("Mouse Position: x =%4d, y =%4d
", x, y);
}
close(dev_mouse);
return 0;
}
I need help with my c mouse position code so that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!