linux中为用户添加权限_如何在Linux中为X.org服务器禁用和启用笔记本电脑键盘

linux中为用户添加权限

Attaching a USB keyboard to a laptop is common when using a laptop because a normal keyboard may provide a more convenient typing experience. The laptop keyboard is not used in these situations. However, the laptop keyboard may still be touched by accident. In this post, we will discuss how to disable and enable the laptop keyboard in Linux. I will also provide scripts ready for you to directly use them for disabling/enabling the laptop keyboard.

使用便携式计算机时,通常将USB键盘连接到便携式计算机,因为普通键盘可能会提供更方便的键入体验。 在这些情况下不使用笔记本电脑键盘。 但是,笔记本电脑的键盘可能仍然会被意外触摸。 在本文中,我们将讨论如何在Linux中禁用和启用笔记本电脑键盘。 我还将提供脚本,供您直接使用它们来禁用/启用笔记本电脑键盘。

禁用/启用笔记本电脑键盘的脚本 (Scripts for disabling/enabling laptop keyboard )

For those in hurry to have try, you can download the scripts from the code repository.

对于那些急于尝试的人,您可以从代码库中下载脚本。

These scripts use the xinput tool for controlling the keyboard. You will need to install it on your Linux if your Linux hasn’t it installed by default.

这些脚本使用xinput工具控制键盘。 如果默认情况下未安装Linux,则需要在Linux上安装它。

The scripts are in a git repository, you may clone the whole repository and copy these scripts out only by

这些脚本位于git存储库中,您可以克隆整个存储库并仅通过以下方式复制这些脚本:

$ git clone https://github.com/zma/usefulscripts
$ cp -rv usefulscripts/script/laptopkb ./

The laptopkb-disable.sh will disable the keyboard and the laptopkb-enable.sh will enable the keyboard.

laptopkb-disable.sh将禁用键盘,而laptopkb-enable.sh将启用键盘。

laptop-keyboard.jpg

Before disabling your keyboard on your laptop, make sure you have an external USB keyboard connected to your laptop. Otherwise, you will have no way to input commands to enable your keyboard back unless you restart Linux using the power button or run the commands through a SSH session to your laptop (if you enabled the SSH service).

在笔记本电脑上禁用键盘之前,请确保已将外部USB键盘连接到笔记本电脑。 否则,除非您使用电源按钮重启Linux或通过与笔记本电脑的SSH会话运行命令,否则您将无法输入命令来启用键盘,除非您启用了SSH服务。

脚本背后的机制 (The mechanisms behind the scripts )

xinput is a utility to configure and test X input devices including the keyboard and we use it to control the laptop keyboard.

xinput是一个实用程序,用于配置和测试X输入设备(包括键盘),我们使用它来控制笔记本电脑键盘。

The float slave command of xinput removes slave from its current master device, and the --reattach slave master command reattachs slave to master. So these two commands can be used to disable/enable a keyboard (and other devices).

xinputfloat slave命令将从其当前主设备中删除从设备,-- --reattach slave master命令将从设备重新连接到主设备。 因此,这两个命令可用于禁用/启用键盘(和其他设备)。

The remaining problem is to find out the “slave” and “master”. xinput list shows a list of devices as follows.

剩下的问题是找出“奴隶”和“主人”。 xinput list显示设备列表,如下所示。

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech Optical USB Mouse id=9 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [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)]
  ↳ Video Bus id=7 [slave keyboard (3)]
  ↳ Power Button id=8 [slave keyboard (3)]
  ↳ HP WMI hotkeys id=12 [slave keyboard (3)]
  ↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]
⎡ mouse pointer id=13 [master pointer (14)]
⎜ ↳ mouse XTEST pointer id=15 [slave pointer (13)]
⎣ mouse keyboard id=14 [master keyboard (13)]
  ↳ mouse XTEST keyboard id=16 [slave keyboard (14)]

Usually the “AT Translated Set 2 keyboard” is the laptop keyboard. “Virtual core keyboard” is the keyboard master (which is 3 from my observations and 3 is used directly in the script. Yes, it’s a dirty trick. Let me know if you find it is not 3 for you by leaving a comment). From the output of xinput list, we can find out the ids. To find out the laptop keyboard id, we can use grep + cut:

通常,“ AT Translated Set 2键盘”是笔记本电脑键盘。 “虚拟核心键盘”是键盘母版(根据我的观察,这是3个,直接在脚本中使用3个。是的,这是一个肮脏的把戏。请通过评论让我知道您是否不是3个)。 从xinput list的输出中,我们可以找到id。 要找出笔记本电脑的键盘ID,我们可以使用grep + cut

$ xinput list | grep 'AT Translated Set' | cut -f2 | cut -d'=' -f2

So, adter combining them together, we have the scripts I put in the repository.

因此,将它们组合在一起,我们就将脚本放到了存储库中。

翻译自: https://www.systutorials.com/how-to-disable-and-enable-laptop-keyboard-in-linux/

linux中为用户添加权限

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值