驱动程序模拟按键 [英] Driver to Simulate Keypress

查看:518
本文介绍了驱动程序模拟按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个驱动程序来将按键模拟到Linux中的特定进程中,有人可以帮助我吗?

i need to make a driver to emulate keypresses into a particular process in linux, can anyone help me with that?

它不必是驱动程序,但是我相信没有其他方法可以做到,该操作系统没有屏幕管理器,并且正在使用Directfb来处理输入

It doesn't need to be a driver, but i believe there's no other way to do it, the OS is running with no screen manager and is using directfb to handle input

推荐答案

如果拥有适当的权限,则可以使用任何read()/write()命令与Linux中的任意进程进行交互.

If you have the proper permissions, then you can use any of the read()/write() commands to interact with an arbitrary process in Linux.

查看/proc/目录,您将看到每个运行进程的各个组件的文件结构表示.

Look at the /proc/ directory and you will see a file structure representation of the various components of each running process.

root@netbook:~# ll /proc/
total 4
dr-xr-xr-x 153 root       root                0 2011-06-19 23:14 ./
drwxr-xr-x  22 root       root             4096 2011-04-29 03:52 ../
dr-xr-xr-x   7 root       root                0 2011-06-22 15:58 1/
dr-xr-xr-x   7 root       root                0 2011-06-22 15:58 11/
...

在此示例中,我使用了ls,但是您可以使用标准Linux库实用地执行此操作.找到您要发送密钥的进程,然后打开(使用fopen或类似文件)文件/proc/{pid}/fd/0.这是Linux(stdin)中的标准,您写入此字符设备的任何内容都将被解释为输入.

I used ls for this example, but you can do this pragmatically with standard Linux libraries. Find the process you want to send keys to and open (with fopen or similar) the file /proc/{pid}/fd/0. This is the standard in (stdin) in Linux and anything you write to this character device will be interpreted as input.

这篇关于驱动程序模拟按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆