Skip to content

Instantly share code, notes, and snippets.

@arya2004
Created July 14, 2024 06:48
Show Gist options
  • Select an option

  • Save arya2004/e49db7b9411c8ff0e33b1cd1100cf473 to your computer and use it in GitHub Desktop.

Select an option

Save arya2004/e49db7b9411c8ff0e33b1cd1100cf473 to your computer and use it in GitHub Desktop.
A guide and script to temporarily disable and enable the laptop keyboard while using an external keyboard in Linux Mint.

Step-by-Step Guide

  1. Identify Your Laptop Keyboard Device ID: Open a terminal and run:

    xinput list

    This command will display a list of all input devices connected to your system. Look for an entry that corresponds to your laptop keyboard, such as "AT Translated Set 2 keyboard" or something similar. Note down the device ID (e.g., 11).

  2. Disable the Keyboard: Use the following command to disable your laptop keyboard (replace 11 with your actual device ID):

    xinput disable 11
  3. Enable the Keyboard: Use the following command to re-enable your laptop keyboard (replace 11 with your actual device ID):

    xinput enable 11
  4. Create a Toggle Script: Create a script to easily toggle the keyboard state between enabled and disabled.

    Script: toggle_keyboard.sh

    #!/bin/bash
    
    DEVICE_ID=11  # Replace with your actual device ID
    
    if xinput list-props $DEVICE_ID | grep "Device Enabled (.*):.*1" > /dev/null
    then
        xinput disable $DEVICE_ID
        echo "Keyboard disabled"
    else
        xinput enable $DEVICE_ID
        echo "Keyboard enabled"
    fi
  5. Make the Script Executable:

    chmod +x toggle_keyboard.sh
  6. Run the Script:

    ./toggle_keyboard.sh

Automating at Startup

To disable the keyboard automatically at startup, follow these steps:

  1. Open Startup Applications from the Mint menu.
  2. Click on Add.
  3. Set the Name to something like "Disable Laptop Keyboard".
  4. Set the Command to:
    xinput disable 11  # Replace 11 with your actual device ID
  5. Click Add and then Close.

Now, your laptop keyboard will be disabled every time you start your computer. You can enable it using the toggle_keyboard.sh script whenever needed.

#!/bin/bash
DEVICE_ID=11 # Replace with your actual device ID
if xinput list-props $DEVICE_ID | grep "Device Enabled (.*):.*1" > /dev/null
then
xinput disable $DEVICE_ID
echo "Keyboard disabled"
else
xinput enable $DEVICE_ID
echo "Keyboard enabled"
fi
@Joaquim3
Copy link

Thanks a lot @arya2004 , This is very handy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment