linuxinputsimulatewacom

Simulate Stylus Input


I am looking for a way to inject wacom input into a running X server. I kind of get stuck at the beginning finding any resources about this topic.

There is a lot of information about how to inject keystrokes and mouse input, but thats not what i am looking for and it does not seem to simlutate wacom stuff.

Does anyone have any informations about this topic?


Solution

  • On Linux, the various input devices generate a variety of events.

    For example,

    Keyboards - EV_KEY
    Mice      - EV_REL
    Tablets   - EV_ABS
    

    The events supported/generated by any particular input device can be identified by running xinput on the system with the input device connected to it as follows:

    xinput --list <name of the connected input device>
    

    A sample list of input devices created by connecting a Wacom tablet:

    $ > xinput --list
    ⎡ Virtual core pointer                          id=2    [master pointer  (3)]
    ⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
    ⎜   ↳ SynPS/2 Synaptics TouchPad                id=14   [slave  pointer  (2)]
    ⎜   ↳ Wacom Intuos4 6x9 eraser                  id=17   [slave  pointer  (2)]
    ⎜   ↳ Wacom Intuos4 6x9 cursor                  id=18   [slave  pointer  (2)]
    ⎜   ↳ Wacom Intuos4 6x9 pad                     id=19   [slave  pointer  (2)]
    ⎜   ↳ Wacom Intuos4 6x9 stylus                  id=20   [slave  pointer  (2)]
    ⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
        ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
        ↳ AT Translated Set 2 keyboard              id=13   [slave  keyboard (3)]
    

    ..and the list of input events supported/generated by one of the 4 Wacom devices that are registered to input events from the Wacom tablet:

    $ > xinput --list "Wacom Intuos4 6x9 eraser"
    Wacom Intuos4 6x9 eraser                    id=17   [slave  pointer  (2)]
        Reporting 8 classes:
            Class originated from: 17
            Buttons supported: 9
            Button labels: None None None None None None None None None
            Button state:
            Class originated from: 17
            Keycodes supported: 248
            Class originated from: 17
            Detail for Valuator 0:
              Label: Abs X
              Range: 0.000000 - 44704.000000
              Resolution: 200000 units/m
              Mode: absolute
              Current value: 0.000000
            Class originated from: 17
            Detail for Valuator 1:
              Label: Abs Y
              Range: 0.000000 - 27940.000000
              Resolution: 200000 units/m
              Mode: absolute
              Current value: 0.000000
            Class originated from: 17
            Detail for Valuator 2:
              Label: Abs Pressure
              Range: 0.000000 - 2048.000000
              Resolution: 1 units/m
              Mode: absolute
              Current value: 0.000000
            Class originated from: 17
            Detail for Valuator 3:
              Label: Abs Tilt X
              Range: -64.000000 - 63.000000
              Resolution: 1 units/m
              Mode: absolute
              Current value: 0.000000
            Class originated from: 17
            Detail for Valuator 4:
              Label: Abs Tilt Y
              Range: -64.000000 - 63.000000
              Resolution: 1 units/m
              Mode: absolute
              Current value: 0.000000
            Class originated from: 17
            Detail for Valuator 5:
              Label: Abs Tilt Y
              Range: -64.000000 - 63.000000
              Resolution: 1 units/m
              Mode: absolute
              Current value: 0.000000
    

    The above shows 9 buttons, and several axes with their corresponding min/max values for each type of input event(referred to by their lables).

    For example, the absolute x axis has a min/max of 0 - 44704 units, with 20000 units/m. Presumably input events of type EV_ABS are generated only within this range for the X-axis.

    Once the types of events being generated by the input device have been identified, it is easy to inject fake events into the Xinput queue using uinput framework. A simple example is available here

    As you intend to simulate a Wacom tablet, you would probably need to inject all the input events that a typical Wacom tablet generates when used.

    xinput can be used to monitor the sequence and timing of input events generated by an actual device as shown in this answer.