如何使用 c 中最少的库跟踪鼠标输入

Tim*_*imE 5 c mouse input

我不知道在哪里可以找到这些信息,但我想知道如何使用 c 中最少的非标准库来获取鼠标输入(或任何隐藏输入)。基本上,c 中是否有相当于鼠标(和其他输入)输入的 stdio?或者是否有一个最小且在多个平台上交叉兼容的库。只需能够将鼠标坐标打印到终端窗口就足够了。

Yan*_*min 2

这里是一个0非标准库的做法。在 /dev/input/event# 存在的地方运行。

#include <linux/input.h>
#include <fcntl.h>    

int main(int argc, char **argv)
{
int fd;
if ((fd = open("/dev/input/mice", O_RDONLY)) < 0) {
    perror("evdev open");
    exit(1);
}

struct input_event ev;

while(1) {
    read(fd, &ev, sizeof(struct input_event));
    printf("value %d, type %d, code %d\n",ev.value,ev.type,ev.code);
}

return 0;
}
Run Code Online (Sandbox Code Playgroud)

在 Windows 上,您需要使用 Win32 API 做一些可怕的事情并挂钩消息系统。

简而言之,不,C 中没有这方面的标准。