Driver to Simulate Keypress

两盒软妹~` 提交于 2019-12-11 06:04:13

问题


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

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


回答1:


try xdotool-- it's for writing mouse/keyboard macros.

$ xdotool type "hello world"

$ xdotool keydown x

etc




回答2:


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

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/
...

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.



来源:https://stackoverflow.com/questions/5979544/driver-to-simulate-keypress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!