Skip to content

evemu-event: introduce a FIFO to inject commands

Inaky Perez-Gonzalez requested to merge inakypg/evemu:fifo into master

This patch adds the --fifo option which puts evemu-event into a mode where it reads lines from that FIFO and send input events to devices based on it.

This allows putting it in the background to get commands sent to devices with ease and performance (when simulating fast mouse movement); for example, you could make a python script that generates mice coordinates to draw a circle (as round as your monitor's aspect is):

  #! /usr/bin/python3
  import math
  import sys
  import time
  t = 0
  td = 0.1
  while True:
      x = 5000 + 3000 * math.cos(2 * 3.1416 * 0.1 * t)
      y = 5000 + 3000 * math.sin(2 * 3.1416 * 0.1 * t)
      print("""\
  event18 EV_ABS ABS_X %s
  event18 EV_ABS ABS_Y %s SYNC
  WAIT %0.3f
  """ % (int(x), int(y), td))
      sys.stdout.flush()
      time.sleep(td / 2)
      t += 0.2

and feeding this into the FIFO of a created device which has a 0-65536 range (this was obtained by querying VMWare's mouse with event-describe):

  $ cat > mouse.descriptor <<EOF
  # EVEMU 1.3
  # Kernel: 5.1.15-200.fc29.x86_64
  # DMI: dmi:bvnPhoenixTechnologiesLTD:bvr6.00:bd04/13/2018:svnVMware,Inc.:pnVMwareVirtualPlatform:pvrNone:rvnIntelCorporation:rn440BXDesktopReferencePlatform:rvrNone:cvnNoEnclosure:ct1:cvrN/A:
  # Input device name: "VirtualPS/2 VMware VMMouse"
  # Input device ID: bus 0x11 vendor 0x02 product 0x13 version 0x06
  # Supported events:
  #   Event type 0 (EV_SYN)
  #     Event code 0 (SYN_REPORT)
  #     Event code 1 (SYN_CONFIG)
  #     Event code 2 (SYN_MT_REPORT)
  #     Event code 3 (SYN_DROPPED)
  #...
  #     Event code 15 (SYN_MAX)
  #   Event type 1 (EV_KEY)
  #     Event code 272 (BTN_LEFT)
  #     Event code 273 (BTN_RIGHT)
  #     Event code 274 (BTN_MIDDLE)
  #   Event type 3 (EV_ABS)
  #     Event code 0 (ABS_X)
  #       Value        0
  #       Min          0
  #       Max      65535
  #       Fuzz         0
  #       Flat         0
  #       Resolution   0
  #     Event code 1 (ABS_Y)
  #       Value        0
  #       Min          0
  #       Max      65535
  #       Fuzz         0
  #       Flat         0
  #       Resolution   0
  # Properties:
  N: VMWare Mouse
  I: 0011 0002 0013 0006
  P: 00 00 00 00 00 00 00 00
  B: 00 0b 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 07 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 01 00 00 00 00 00 00 00 00
  B: 02 00 00 00 00 00 00 00 00
  B: 03 03 00 00 00 00 00 00 00
  B: 04 00 00 00 00 00 00 00 00
  B: 05 00 00 00 00 00 00 00 00
  B: 11 00 00 00 00 00 00 00 00
  B: 12 00 00 00 00 00 00 00 00
  B: 14 00 00 00 00 00 00 00 00
  B: 15 00 00 00 00 00 00 00 00
  B: 15 00 00 00 00 00 00 00 00
  A: 00 0 65535 0 0 0
  A: 01 0 65535 0 0 0
  EOF
  $ evemu-event --fifo=mouse.fifo
  VMWare Mouse: /dev/input/event18
  $ python circle.py > mouse.fifo

will make our mouse spin around mouse absolute 5000,5000 with a 3000 ratio.

The format of the lines is described in the source in the read_fifo() function, but it boils down to:

  • <DEVICE> <TYPE> <CODE> <VALUE> [SYNC]
  • WAIT <MILLISECS>
  • empty (ignored)

DEVICE: an absolute name for an input device; if relative, /dev/input will be prefixed

TYPE: type of event (EV_xyz)

CODE: code of the event type (eg: SYN_xyz, KEY_xyz, BTN_xyz, REL_xyz, ABS_xyz, MSC_xyz, SND_xyz, SW_xyz, LED_xyz, REP_xyz, FF_xyz...

VALUE: numeric value to set (0 to release, 1 to press, etc)

SYNC: the event shall carry the sync flag

In general, the changes are:

  • introduce ev_from_args(), which executes the actions given in the command line or in a FIFO line; moves the code in main to use that.

  • on --fifo given, calls read_fifo() to start a loop to execute commands given on the FIFO.

Co-developed-by: Dic Key Li dic.key.li@intel.com

Signed-off-by: Inaky Perez-Gonzalez inaky.perez-gonzalez@intel.com

Merge request reports