Skip to content

Instantly share code, notes, and snippets.

@masui masui/raspi_mouse.c
Created Jan 22, 2015

Embed
What would you like to do?
Raspberry Piでマウスホイール信号を取得する
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h> // struct input_event とか
main()
{
int mouse_fd = open("/dev/input/event0", O_RDONLY);
if (mouse_fd < 0) {
fprintf(stderr,"can't open mouse device\n");
exit(0);
}
struct input_event mouse;
for(;;){
int bytes = read(mouse_fd, &mouse, sizeof(struct input_event));
if(bytes >= 0){
if(mouse.type == EV_REL){
if(mouse.code == REL_WHEEL){
printf("%d\n",mouse.value);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.