系统:嵌入式 linux 系统
平台:高通平台
代码:
#include <fcntl.h>
#include <linux/uinput.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
int main() {
struct uinput_setup usetup;
struct input_event ev;
// 1. 打开 /dev/uinput 设备
int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
if (fd < 0) {
perror("Failed to open /dev/uinput");
return 1;
}
// 2. 告诉 uinput 我们需要发送按键事件 (EV_KEY)
ioctl(fd, UI_SET_EVBIT, EV_KEY);
ioctl(fd, UI_SET_KEYBIT, KEY_POWER)