
Tengo una computadora portátil pero también un teclado USB externo conectado. ¿Es posible de alguna manera bloquear el teclado incorporado de la computadora portátil (es decir, las teclas presionadas no deberían tener ningún efecto) pero mantener el externo respondiendo?
Estoy ejecutando Ubuntu Gnome 16.04. Mi computadora portátil es Lenovo ThinkPad T420.
Respuesta1
Sí, esto debería ser posible con el uso de xinput
.
Para comenzar, ejecute xinput list
en una terminal. Deberías ver algo similar a lo siguiente:
zachary@MCServer:~$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [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)]
↳ Power Button id=7 [slave keyboard (3)]
Ahora, probablemente verás dos teclados, en lugar de solo uno, ya que tienes dos teclados conectados. Recomiendo desconectar el teclado USB y ejecutar el comando.
Tome nota del ID de Virtual core XTEST keyboard
. En mi caso es 5
.
Conecta el teclado USB, ya que estás a punto de desactivar el interno.
Ejecute este comando:
xinput set-prop 5 "Device Enabled" 0
y reemplace 5 con la ID de su dispositivo.
Para volver a habilitar el teclado:
xinput set-prop 5 "Device Enabled" 1`
reemplace 5 con la ID de su dispositivo.
También puede ponerlos en scripts separados si lo desea y ejecutarlos desde la terminal (o crear .desktop
archivos para los scripts que cree).
Editar:
Si lo desea, he creado un script que comprobará el estado del dispositivo especificado xinput
y lo alternará (activado si está desactivado, desactivado si está activado). Deberá cambiar la device
variable al ID correspondiente.
#!/bin/bash
device=5 #Change this to reflect your device's ID
output=$(xinput list-props $device | awk '/Device Enabled/{print $4}')
if [ $output == 1 ]
then
xinput set-prop $device "Device Enabled" 0
elif [ $output == 0 ]
then
xinput set-prop $device "Device Enabled" 1
else
echo "Something's up."
fi
Edición 2:
Script mejorado: detección automática de ID del dispositivo (siempre que su nombre sea fijo) y notificaciones de escritorio.
#!/usr/bin/env bash
# name of the device - we hope this will not change
DEVNAME="AT Translated Set 2 keyboard"
# here we find the device ID corresponding to the name
device=$(xinput list | grep "${DEVNAME}" | sed "s/.*${DEVNAME}.*id=\([0-9]*\).*/\1/g")
# here we get the enabled state
state=$(xinput list-props $device | awk '/Device Enabled/{print $4}')
if [ ${state} == 1 ]; then
# if it is enabled, disable it and show a notification
xinput set-prop ${device} 'Device Enabled' 0
notify-send -u normal "Keyboard lock" "Keyboard \"${DEVNAME}\" (id=${device}) was disabled."
elif [ ${state} == 0 ]; then
# if it is disabled, enable it and show a notification
xinput set-prop ${device} 'Device Enabled' 1
notify-send -u normal "Keyboard lock" "Keyboard \"${DEVNAME}\" (id=${device}) was enabled."
else
# some weird state - do nothing and show critical notification
notify-send -u critical "Keyboard lock" "Keyboard \"${DEVNAME}\" (id=${device}) is neither enabled nor disabled. State is \"${state}\""
fi