我正在尝试使用" / dev / input / mice"来轮询鼠标并使用Java更新其在Java中的位置。但是现在我无法找到确定是否有新数据的方法。如何以非阻塞方式读取输入文件?
public class Mouse {
String MOUSE_STREAM = "/dev/input/mice";
BufferedInputStream bis;
private Mouse(){
bis = new BufferedInputStream(new FileInputStream(new File (MOUSE_STREAM)));
}
public Vect getDelta() {
int sumX = 0;
int sumY = 0;
// This is what I want, but available always returns 0;
// while (bis.available() > 3) {
// Otherwise, If I don't check then .read() will block until the next event
int buttons = bis.read();
int x = bis.read();
int y = bis.read();
sumX += x;
sumY += y;
}
return new Vect(sumX, sumY);
}
}
PS我需要使用非常低级别的界面,因为我在Linux的实时版本中运行而不需要更高级别的库。