arm下的按键测试代码

来源:互联网 发布:nodejs access数据库 编辑:程序博客网 时间:2024/05/22 04:48


首先查看内核代码:linux/arch/arm/mach-s5pv210/mach-tq210.c,得到devicename为“gpio-keys”

确认输入子系统:

 cat /proc/bus/input/devices,得知gpio-keys的event信息为event0



#include <stdio.h>#inlcude <linux/input.h>#include <fcntl.h>int main (){  int keys_fd;  char ret[2];  struct input_event t;  keys_fd = open ("/dev/input/event0", O_RDONLY);  if (keys_fd <= 0)    {      printf ("open /dev/input/event0 device!\n");      return 0;    }  while (1)    {      if (read (keys_fd, &t, sizeof (t)) == sizeof (t))        {          if (t.type == EV_KEY)            if (t.value == 0 || t.value == 1)        {              printf ("key %d %s\n", t.code,                      (t.value) ? "Pressed" : "Released");          if(t.code==KEY_ESC)              break;        }        }    }  close (keys_fd);  return 0;}


0 0