6818 开发板 C 语言程序:点击屏幕随机改变颜色
#include "stdio.h"\n#include "stdlib.h"\n#include "time.h"\n#include "unistd.h"\n#include "linux/input.h"\n#include "fcntl.h"\n#include "sys/types.h"\n#include "sys/stat.h"\n\n#define DEVICE_PATH "/dev/input/event0" // 输入设备路径\n#define SCREEN_WIDTH 800 // 屏幕宽度\n#define SCREEN_HEIGHT 480 // 屏幕高度\n\n// 函数声明\nvoid changeColor(int r, int g, int b);\nvoid clickScreen();\n\nint main() {\n while (1) {\n clickScreen();\n changeColor(rand() % 256, rand() % 256, rand() % 256);\n sleep(1);\n }\n\n return 0;\n}\n\nvoid changeColor(int r, int g, int b) {\n // 使用屏幕显示库来绘制颜色\n // 这里省略具体实现\n printf("Change color to R:%d G:%d B:%d\n", r, g, b);\n}\n\nvoid clickScreen() {\n int fd;\n struct input_event ev;\n\n // 打开输入设备\n fd = open(DEVICE_PATH, O_RDONLY);\n if (fd < 0) {\n perror("Failed to open input device");\n exit(1);\n }\n\n while (1) {\n // 读取输入事件\n read(fd, &ev, sizeof(struct input_event));\n\n // 判断是否为点击事件\n if (ev.type == EV_KEY && ev.code == BTN_TOUCH && ev.value == 1) {\n break;\n }\n }\n\n // 关闭输入设备\n close(fd);\n}
原文地址: https://www.cveoy.top/t/topic/qgYR 著作权归作者所有。请勿转载和采集!