Welcome to the Linux Foundation Forum!

problems with read(...); and mice-device (/dev/input/mice)

edited October 2016 in Software Development

Hello,

i have this code:


  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. char mice_data[3];
  5. int mice_position(){
  6. int fd = open("/dev/input/mice", O_RDWR);
  7. if(fd == -1){
  8. printf("ERROR Opening %s\n", "/dev/input/mice");
  9. return -1;
  10. }
  11. printf("\n");
  12. read(fd, mice_data, sizeof(mice_data));
  13. close(fd);
  14. return 0;
  15. }
  16. int mouse_x = 0;
  17. int mouse_y = 0;
  18. int update_mouse(){
  19. mice_position();
  20. mouse_x += mice_data[1];
  21. mouse_y += mice_data[2];
  22. return 0;
  23. }
  24. int main(){
  25. while(1){
  26. update_mouse();
  27. printf("%i\t%i", mouse_x, mouse_y);
  28. }
  29. return 0;
  30. }

and if im running it it works, but only if the printf(\n"), statement in line 16 is there. if it isnt the program doesnt show anything.

another problem i have is that the read-functions waits until the mice-file changes/until the mouse moves. how can i solve both problems?

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training