English 中文(简体)
在X11/Linux中使用xinput禁用键盘后释放所有按键?
原标题:Releasing all keys after disabling the keyboard in X11/Linux using xinput?
问题回答

“我正在编写一个需要禁用键盘的程序,并希望避免这个问题”

抓住键盘焦点并丢弃所有输入有什么错?

xinput是一个相当钝的工具你遇到了一个超过两年的bug,这意味着它不太可能被修复。事实上,这个bug可能比这要古老得多,可以被使用它的人视为“预期行为”。

您所体验到的是终端模拟器处理键盘事件和shell反应的特殊性。当你按下enter键时,shell将执行给它的命令,你的命令xinput将在按下enter键之前完成。由于键盘被禁用,甚至没有按键释放事件会进入事件处理。

这不是一个bug,这是一个特性。

如何解决这个问题:要么在实际执行分离之前等待所有按键都被按下,要么在xinput命令之前添加睡眠(这两种都是竞争条件,所以它不是100%可靠的)。

即将其放在shell命令行上

sleep 1 ; xinput set-prop $ID "Device Enabled" 0

在实际执行xinput禁用之前,会先睡一秒钟。如果你不按回车键,你应该会以所需的状态出来。

只需模拟xinput set prop$ID“Device Enabled”0后的任何按键点击,在需要命令之前没有睡眠时间

xinput set-prop $ID "Device Enabled" 0 ; xdotool key z




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...