How to Use the Command 'xinput' (with examples)

How to Use the Command 'xinput' (with examples)

The xinput command is a versatile utility in Unix-like systems that allows users to interact with the input subsystem. It’s part of the X.Org Server distribution and is commonly used to list, query, and change input device settings. This tool is extremely useful for configurations involving mice, keyboards, touchpads, or other peripherals. Users can harness the power of xinput to fine-tune device behavior, troubleshoot device connectivity, or adjust settings for user comfort and accessibility.

List all input devices

Code:

xinput list

Motivation:

A user might want to list all input devices to get an overview of the peripherals connected to their system. This is particularly useful when configuring or diagnosing issues with hardware such as mice, keyboards, and touchpads, as it provides device IDs that are necessary for further manipulation.

Explanation:

  • xinput: This command is being used to interact with the input devices.
  • list: This argument specifies that the user wants to see a list of all currently connected input devices.

Example output:

⎡ Virtual core pointer                       id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer             id=4    [slave  pointer  (2)]
⎜   ↳ Logitech USB Optical Mouse             id=8    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad             id=10   [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=11   [slave  keyboard (3)]

Disable an input

Code:

xinput disable id

Motivation:

Disabling an input device can be crucial for troubleshooting, energy saving, or preventing unwanted input. For example, you may want to disable your laptop’s touchpad when typing to avoid accidental cursor movement.

Explanation:

  • xinput: The base command for interacting with input devices.
  • disable: Indicates the action to be performed is disabling.
  • id: The unique identifier of the input device to be disabled, obtained from the xinput list output.

Example output:

The command itself does not return output, but subsequent checks will show the device as disabled in the xinput list.

Enable an input

Code:

xinput enable id

Motivation:

Enabling an input device is often necessary after troubleshooting or using a device that was previously disabled, such as reactivating a touchpad after a keyboard session.

Explanation:

  • xinput: The command used to manage input devices.
  • enable: This argument specifies that the action being performed is enabling the device.
  • id: The identifier of the device obtained from the xinput list that needs to be enabled.

Example output:

Like the disable command, the enable command does not return output directly, but the device will appear active in system device listings.

Disconnect an input from its master

Code:

xinput float id

Motivation:

Floating an input device removes it from its master control group. This can be useful for testing input behavior in isolation or when temporarily disconnecting a device while leaving it physically attached.

Explanation:

  • xinput: The command interacting with the device.
  • float: A command to remove the device from a master device context.
  • id: The device ID to be floated, as specified by the xinput list.

Example output:

No direct output is produced, but the xinput list will show the device as no longer associated with any master device.

Reattach an input as slave to a master

Code:

xinput reattach id master_id

Motivation:

When a device is floated, it might need to be reattached to regain full functionality. For instance, reconnecting a mouse to its previous master pointer after specific testing scenarios.

Explanation:

  • xinput: The utility for managing input devices.
  • reattach: The function to reconnect a floated device back to a master device.
  • id: The ID of the device to be reattached.
  • master_id: The ID of the master device to which the slave device should be reattached, both obtainable from the xinput list.

Example output:

Output will show the device under the specified master again on executing xinput list.

List settings of an input device

Code:

xinput list-props id

Motivation:

Viewing the properties of an input device is essential to understand current settings, adjust configurations, or troubleshoot issues. This command reveals all configurable settings of a specified device.

Explanation:

  • xinput: Command to interact with input devices.
  • list-props: Accessible options for a specific device.
  • id: Identifier for the device whose properties are to be listed.

Example output:

Device 'SynPS/2 Synaptics TouchPad':
    Device Enabled (151):    1
    Coordinate Transformation Matrix (153): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    ...

Change a setting of an input device

Code:

xinput set-prop id setting_id value

Motivation:

Changing the settings of an input device allows users to customize the behavior of their peripherals, such as adjusting sensitivity, modifying button mappings, or changing the scrolling direction.

Explanation:

  • xinput: The main command for input interaction.
  • set-prop: Modifies a property of a device.
  • id: The identifier for the device.
  • setting_id: The ID of the property to be changed, obtainable from xinput list-props.
  • value: The new value to be assigned to the specified property.

Example output:

There is no direct output from this command, but executing xinput list-props id after modification will show the updated settings.

Conclusion:

The xinput command provides extensive capabilities for managing and configuring input devices in Unix-like systems. By understanding how to list, enable, disable, float, reattach, and adjust properties of devices, users can ensure that their hardware is optimized for their specific needs and environment. Each use case illustrates a different aspect of this powerful tool, making xinput an indispensable command for anyone needing to manipulate input devices directly.

Related Posts

How to Use the Command 'zramctl' (with Examples)

How to Use the Command 'zramctl' (with Examples)

zramctl is a command-line utility for setting up and controlling zram devices on Linux systems.

Read More
How to Use the Command 'rename' (with Examples)

How to Use the Command 'rename' (with Examples)

The rename command, part of the Debian package, is a powerful tool for batch renaming files using Perl regular expressions.

Read More
How to Use the Command 'lldb' (with Examples)

How to Use the Command 'lldb' (with Examples)

The LLVM Low-Level Debugger (LLDB) is a robust tool utilized predominantly by developers to debug compiled executable programs.

Read More