
노트북이 있지만 외부 USB 키보드도 연결되어 있습니다. 내장 노트북 키보드를 잠그는 것(즉, 누른 키가 아무 효과도 없어야 함)이 가능하지만 외부 키보드는 계속 반응하도록 할 수 있습니까?
저는 Ubuntu Gnome 16.04를 실행하고 있습니다. 내 노트북은 Lenovo ThinkPad T420입니다.
답변1
예, 를 사용하면 가능합니다 xinput
.
시작하려면 xinput list
터미널에서 실행하세요. 다음과 비슷한 내용이 표시됩니다.
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)]
이제 두 개의 키보드가 연결되어 있으므로 키보드 하나만이 아닌 두 개가 표시될 것입니다. USB 키보드를 분리하고 명령을 실행하는 것이 좋습니다.
의 ID를 기록해 두십시오 Virtual core XTEST keyboard
. 제 경우에는 입니다 5
.
내부 키보드를 비활성화하려고 하므로 USB 키보드를 연결합니다.
다음 명령을 실행하세요:
xinput set-prop 5 "Device Enabled" 0
5를 장치 ID로 바꿉니다.
키보드를 다시 활성화하려면:
xinput set-prop 5 "Device Enabled" 1`
5를 장치 ID로 바꾸십시오.
원하는 경우 이를 별도의 스크립트에 넣고 터미널에서 실행할 수도 있습니다(또는 .desktop
작성한 스크립트에 대한 파일을 생성할 수도 있습니다).
편집하다:
원하는 경우 지정된 장치의 상태를 확인하고 전환하는 스크립트를 만들었습니다 xinput
(해제된 경우 켜짐, 켜진 경우 꺼짐). device
변수를 해당 ID로 변경해야 합니다 .
#!/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
편집 2:
향상된 스크립트 - 자동 장치 ID 감지(이름이 고정된 경우) 및 데스크톱 알림.
#!/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