linux input subsystem虚拟键盘和鼠标_绿色软件之家

绿色软件之家:您身边最放心的安全下载站! 最新更新|软件分类|软件专题|手机版|系统之家|纯净系统

您当前所在位置:首页操作系统LINUX → linux input subsystem虚拟键盘和鼠标

linux input subsystem虚拟键盘和鼠标

时间:2015/6/28来源:绿色软件之家作者:网管联盟我要评论(0)

  1  event device

  in /dev/input/event?

  cat data from /dev/input/event? the data format is :

  struct input_event {

  struct timeval time;

  __u16 type;

  __u16 code;

  __s32 value;

  };

  e.g :

  xx xx xx xx yy yy yy yy tt tt cc cc vv vv vv vv

  xx is usec

  yy is sec

  tt is type

  cc is key code

  vv is value, might be it means keyup or keydown

  for mouse event, you can get the same message format

  xx, yy is the same as keyboard

  tt is EV_REL, it means the value feild is relative distance;

  cc is REL_X or REL_Y

  vv is the value of relative distance

  2 register input_dev

  /**************************

  for virtual mouse

  **/

  static int  vkm_vmouse_register(void)

  {

  struct input_dev *vmouse_dev;

  vmouse_dev = input_allocate_device();

  if (!vmouse_dev)

  return -ENOMEM;

  vmouse_dev->name = "VMouse ";

  vmouse_dev->phys = "xxmouse/input1";

  vmouse_dev->id.bustype = BUS_HOST;

  vmouse_dev->id.vendor = 0x0001;

  vmouse_dev->id.product = 0x0002;

  vmouse_dev->id.version = 0x0100;

  vmouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);

  vmouse_dev->keybit[BIT_word(BTN_MOUSE)] =

  BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);

  vmouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);

  /* error check */

  error = input_register_device(vmouse_dev);

  if (error) {

  input_free_device(vmouse_dev);

  return error;

  }

  }

  /**************************

  for virtual keyboard

  **/

  static int  vkm_vkbd_register(void)

  {

  int i, error;

  struct input_dev *vkbd_dev;

  vkbd_dev = input_allocate_device();

  if (!vkbd_dev)

  return -ENOMEM;

  vkbd_dev->name = "VKBD Keyboard";

  vkbd_dev->phys = "atakbd/input0";

  vkbd_dev->id.bustype = BUS_HOST;

  vkbd_dev->id.vendor = 0x0001;

  vkbd_dev->id.product = 0x0001;

  vkbd_dev->id.version = 0x0100;

  vkbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);

  vkbd_dev->keycode = atakbd_keycode;

  vkbd_dev->keycodesize = sizeof(unsigned char);

  vkbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);

  for (i = 1; i < 0x72; i++) {

  set_bit(atakbd_keycode[i], vkbd_dev->keybit);

  }

  /* error check */

  error = input_register_device(vkbd_dev);

  if (error) {

  input_free_device(vkbd_dev);

  return error;

  }

  return 0;

  }

  send keyboard event to input handler like this:

  input_report_key(vkbd_dev,KEY_A,0);

  input_sync(vkbd_dev);

  and send mouse event to input handler like this:

  input_report_rel(vmouse_dev, REL_X, 10);

  input_report_rel(vmouse_dev, REL_Y, 10);

  input_sync(vmouse_dev);

关键词标签:linux,input,subsyste

相关阅读

文章评论
发表评论

热门文章 安装红帽子RedHat Linux9.0操作系统教程安装红帽子RedHat Linux9.0操作系统教程使用screen管理你的远程会话使用screen管理你的远程会话GNU/Linux安装vmwareGNU/Linux安装vmware如何登录linux vps图形界面 Linux远程桌面连如何登录linux vps图形界面 Linux远程桌面连

相关下载

人气排行 Linux下获取CPUID、硬盘序列号与MAC地址linux tc实现ip流量限制dmidecode命令查看内存型号linux下解压rar文件安装红帽子RedHat Linux9.0操作系统教程Ubuntu linux 关机、重启、注销 命令lcx.exe、nc.exe、sc.exe入侵中的使用方法查看linux服务器硬盘IO读写负载