Injecting input events

Moderators: Gully, peteru

Post Reply
User avatar
peteru
Uber Wizard
Posts: 9735
Joined: Tue Jun 12, 2007 23:06
Location: Sydney, Australia
Contact:

Injecting input events

Post by peteru » Sun May 21, 2017 15:42

I'm having some issue replying to the original topic, so I thought I'd start a new one. It's probably worth splitting this info.
naigy wrote:
Sat May 20, 2017 20:49
perhaps a boot up script (likely linked to the end of the GUI I would guess) which emulates these buttons being pressed. Any advice on API / commands to do this.
Python code or install curl. You can use the OpenWebif AJAX API over HTTP. I don't think there are any API calls to control PIP directly, so you may have to resort to sending key press commands to simulate remote control.

Alternatively, you could try to inject the correct key codes into the Linux input event system. For a really dirty hack, you could just craft a binary file with the right input events and then use dd to inject them. For a more high level approach, something like python-evdev might be useful.

As a proof of concept, I started capturing the events from /dev/input/event1 into a file, pressed the required keys to simulate a macro and stopped the capture. Then I injected these events back into /dev/input/event1 and sure enough, got the expected results.

Code: Select all

# cat /dev/input/event1 >key_capture

# cat key_capture >/dev/input/event1

"Beauty lies in the hands of the beer holder."
Blog.

Post Reply

Return to “FAQs, Tips & How to Guides”