Bloqueie o teclado interno do laptop, mas mantenha um teclado USB externo funcionando

Bloqueie o teclado interno do laptop, mas mantenha um teclado USB externo funcionando

Eu tenho um laptop, mas também um teclado USB externo conectado a ele. É de alguma forma possível bloquear o teclado interno do laptop (ou seja, as teclas pressionadas não devem ter efeito), mas manter o teclado externo responsivo?

Estou executando o Ubuntu Gnome 16.04. Meu laptop é o Lenovo ThinkPad T420.

Responder1

Sim, isso deveria ser possível, com o uso de xinput.

Para começar, execute xinput listem um terminal. Você deverá ver algo semelhante ao seguinte:

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)]

Agora, você provavelmente verá dois teclados, em vez de apenas um, já que há dois teclados conectados. Recomendo desconectar o teclado USB e executar o comando.

Anote o ID de Virtual core XTEST keyboard. No meu caso, é 5.

Conecte o teclado USB, pois você está prestes a desabilitar o interno.

Execute este comando:

xinput set-prop 5 "Device Enabled" 0

e substitua 5 pelo ID do seu dispositivo.

Para reativar o teclado:

xinput set-prop 5 "Device Enabled" 1`

substitua 5 pelo ID do seu dispositivo.

Você também pode colocá-los em scripts separados, se desejar, e executá-los no terminal (ou criar .desktoparquivos para os scripts que você cria).

Editar:
Se você quiser, criei um script que irá verificar o estado do dispositivo especificado xinpute alterná-lo (para ligado se estiver desligado, para desligado se estiver ligado). Você precisará alterar a devicevariável para o ID correspondente.

#!/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

Editar 2:
Script aprimorado - detecção automática de ID do dispositivo (desde que seu nome seja corrigido) e notificações na área de trabalho.

#!/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

informação relacionada