Cool Tricks with Xinput Device

J

Jarret W. Buse

Guest
Cool Tricks with Xinput Device

The display manager of Linux systems is X Windows. X Windows is also referred to as X11, X-Windows and X. X Windows is made up of many components which are managed to support the GUI. The Xinput extension, libXi, controls input from the mouse and keyboard as well as other input devices which may not be common.

The core devices for Xinput are the mouse and keyboard. It is possible to have multiple mice and keyboards on a system. For example, on a laptop there is a keyboard and usually a touchpad or some such device to control the mouse. Another keyboard and/or mouse can be added using the Universal Serial Bus (USB).

NOTE: For systems with multiple input devices, be sure that if one of the devices is to be disabled that it is the correct one. For example, if you have a laptop with a keyboard and you add another in the USB port, you want to be sure you disabled the proper keyboard. Personally, I have a laptop with a touchpad that I do not like at all. I can add a USB mouse and disable the touchpad so I do not accidentally touch it and cause the cursor to do things I do not want it to do. Sometimes, there is an option to 'disable touchpad as you type' which works. Sometimes the option exists, but does not work properly. It may be necessary to be able to disable and enable a touchpad or other input device.

To get a list of the various input devices, mice and keyboards, we use the following command in a Terminal:

xinput -list

NOTE: You can also just type xinput with no options since -list is the default option.

The output from the command should display a list of input devices. The output from my system is as shown:

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech Optical USB Mouse id=9 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]
↳ HP WMI hotkeys id=12 [slave keyboard (3)]

The first section shows the Virtual core pointer which are the mice. The master devices are what appear in X Windows. For the master pointer device, it is the arrow cursor which corresponds to the pointing device, mouse or touchpad. The master keyboard device is the cursor depicting where letters will appear, such as in a word processor.

The slave devices are the physical hardware devices which controls the master devices. For example, you can see the Logitech Optical USB Mouse listed as a slave pointer in the above list of my devices. The mouse is one of two input pointer devices which is considered a slave to the Virtual core pointer.

After the Virtual core pointer, you see Virtual core keyboard followed by six slave devices. The first is the Virtual core XTEST keyboard which is similar to the Virtual core XTEST pointer. Each master device will have a XTEST keyboard and XTEST pointer associated with it.

The listing of AT Translated Set 2 keyboard is the laptop keyboard. I can disable the keyboard with the command 'xinput set-prop 10 "Device Enabled" 0'. The keyboard has the device ID of 10. The same can be done for the touchpad, so I do not have to worry about it when typing. The command for my system would be 'xinput set-prop 11 "Device Enabled" 0'. As you can see from the above output from the xinput command, the touchpad ID is 11.

If I need to enable the device, I perform the same command, but change the last '0' at the end to a '1'. To turn off a device, I use '0' and to turn on a device I use '1'.

NOTE: Do not turn off your keyboard unless you have a second keyboard to attach to the system. Keep in mind that all changes are not permanent. When the system is restarted, all devices are enabled as they were. To make changes permanent, add the commands in a BASH script to execute at startup.

Now for an interesting trick. Suppose you had a game which used the mouse for input. You wanted to play two players, but each person wants to use the mouse. Why not use two mice? Well, they both control the same cursor, but what if there were two cursors? That is the trick. Each slave device under the master device controls that master device. To accomplish this trick, you need another master device.

To create a new master device you enter the following command: 'xinput create-master name'. The name is up to you, but try to keep it simple. For example, I could create one with the command 'xinput create-master mouse'. My output from the xinput would be as follows:

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech Optical USB Mouse id=9 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ HP WMI hotkeys id=12 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]
⎡ mouse pointer id=13 [master pointer (14)]
⎜ ↳ mouse XTEST pointer id=15 [slave pointer (13)]
⎣ mouse keyboard id=14 [master keyboard (13)]
↳ mouse XTEST keyboard id=16 [slave keyboard (14)]

You can see that I now have a new master pointer and keyboard.

NOTE: The pointer and keyboard master devices are always created as a pair.

You should notice that there are no physical slave devices which are physical hardware. So, we need to move one of my mice to the new master pointer device. The command is 'xinput reattach #a #b' which moves device with ID #a to the master with device ID #b. For example, to move my Logitech mouse with ID 9 to the Master pointer device with ID 13, I would use the following command:

'xinput reattach 9 13'

After the device has been moved, my xinput command shows the following output:

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ HP WMI hotkeys id=12 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]
⎡ mouse pointer id=13 [master pointer (14)]
⎜ ↳ Logitech Optical USB Mouse id=9 [slave pointer (13)]
⎜ ↳ mouse XTEST pointer id=15[slave pointer (13)]
⎣ mouse keyboard id=14 [master keyboard (13)]
↳ mouse XTEST keyboard id=16 [slave keyboard (14)]

You can now see that the Logitech mouse is now on the mouse pointer master device we created. To prove this point, I will show a screenshot with the two cursors.

Figure 1.jpg

FIGURE 1

The same can be done with a second keyboard as well. After adding a second keyboard, I moved it to the mouse keyboard (ID14) as shown:

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)]
⎜ ↳ USBPS2 id=18 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ HP WMI hotkeys id=12 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]
⎡ mouse pointer id=13 [master pointer (14)]
⎜ ↳ Logitech Optical USB Mouse id=9 [slave pointer (13)]
⎜ ↳ mouse XTEST pointer id=15 [slave pointer (13)]
⎣ mouse keyboard id=14 [master keyboard (13)]
↳ mouse XTEST keyboard id=16 [slave keyboard (14)]
↳ USBPS2 id=17 [slave keyboard (14)]

Now, I can have two people playing a game, each with their own keyboard and mouse.

NOTE: Do note that the main master devices have precedence over the secondary master devices.

For two people to use the same system, you can have a secondary mouse and keyboard on a secondary master device. With two monitors, each with a different window, can allow two people to execute two applications at once. Each user can then perform separate tasks on the same system at once. As a test, I created two master devices and then used one mouse to open a text editor. With the other mouse, I also opened a text editor. Each keyboard could enter text into its own editor without affecting the other editor. In this way, a system can support two users.
 

Attachments

  • slide.jpg
    slide.jpg
    77.9 KB · Views: 142,786


Thank you, Jarrett. Was able to disable touch screen digitizer that was not working well and interrupting the touchpad in Xubuntu 14.04 on an ASUS sonicmaster.
 
Hi Jarett, lately i found this post and i need of small assistance on this .
As per the above information shared i was able to create new cursor in additonal to the exisitng or default ones.

But my problem statement described below and needs a quick solution for the same:

I am running an Air Traffic Controller application on my Centos 7 machine. This machine is connected to two monitors one a normal dell monitor and the other one is the touch monitor.

the reason for creating an additional cursor is to have a independant cursor for independant monitors. I am able to attach this new cursor created using xinput to the touch screen as well.

The problem here is when i start the application new cursor gets created and stays on monitor 1 until i touch the touch monitor 2 only then it goes to touch monitor.

I want a way to move this new cursor to touch screen soon after i execute the script.
 
Had to pop open the man pages to figure out how to get rid of the experimental duplicate cursor :)
 

Members online


Top