Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating mouse and keyboard input on Wayland and X11

Tags:

linux

wayland

I am working on a small acceptance test for my OpenGL application written in C. So far, I'm only able to take screenshots and haven't found a way of simulating mouse and keyboard input on both Wayland and X11.

Any suggestions on how to manipulate the event stream of a specific window in Wayland/X11?

like image 594
vinnylinux Avatar asked Jul 18 '18 15:07

vinnylinux


2 Answers

For simulating X11 mouse events you have several options:

  1. If your X server supports XTEST extension (usually it does), then use XTEST Extension Library with functions XTestFakeKeyEvent,XTestFakeMotionEvent, etc. An example
  2. You can use XLib functions like XSendEvent, XWarpPointer, etc. An example
  3. If you are under Linux and your tests have access to command shell then you can use command line tool xdotool (which internally uses XTEST extension. An example

For Wayland you can use uinput kernel module. Documentation and examples are here

like image 126
SergeyLebedev Avatar answered Oct 27 '22 00:10

SergeyLebedev


keyboard is a Python library designed to emulate keyboard and mouse on both Linux (X11 only) and Windows. There may be a similar project that uses C, but I don't know of it yet.

like image 27
Kyle Avatar answered Oct 27 '22 01:10

Kyle