Use the Human Interface Device (HID) module

The Python hid module provides a programmatic access to a USB Human Interface Device (HID) from within a Python script.

For example, to determine information about a USB-connected keyboard:

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the LR54 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the hid module:
  4. >>> import hid
    >>>
  5. Use the enumerate() function to return information about the keyboard:
    >>> hid.enumerate()

    This returns the following:

    [{'path': b'/dev/hidraw0', 'vendor_id': 1008, 'product_id': 36, 'serial_number': '', 'release_number': 768, 
    'manufacturer_string': 'CHICONY', 'product_string': 'Basic USB Keyboard', 'usage_page': 18432, 'usage': 17481, 
    'interface_number': 0}]
  6. Use the vender_id and product_id to return specific information about the keyboard, or to read input from the keyboard:
  7. >>> 
    hid.Device(1008,36).product

    This returns information about the keyboard:

    'Basic USB Keyboard' 
  8. To read input from the keyboard:

  9. >>> 
    hid.Device(1008,36).read(64)

    Which returns:

    b'\x00\x00,\x00\x00\x00\x00\x00'
  10. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().

Help for the hid module

Get help for the hid module:

  1. Select a device in Remote Manager that is configured to allow shell access to the admin user, and click Actions > Open Console. Alternatively, log into the LR54 local command line as a user with shell access.

    Depending on your device configuration, you may be presented with an Access selection menu. Type shell to access the device shell.

  2. At the shell prompt, use the python command with no parameters to enter an interactive Python session:

    # python
    Python 3.10.1 (main, Mar 30 2023, 23:47:13) [GCC 11.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    

  3. Import the hid module:
    >>> import hid
    >>>
  4. Use the help command with hid:
    >>> help(hid)
    Help on package hid:
    
    NAME
        hid
    
    PACKAGE CONTENTS
    
    CLASSES
        _ctypes.Structure(_ctypes._CData)
            DeviceInfo
        builtins.Exception(builtins.BaseException)
            HIDException
        builtins.object
            Device 
    ...
    >>>
  5. Use Ctrl-D to exit the Python session. You can also exit the session using exit() or quit().