在使用xinput禁用X11/Linux中的键盘后释放所有键? [英] Releasing all keys after disabling the keyboard in X11/Linux using xinput?

查看:304
本文介绍了在使用xinput禁用X11/Linux中的键盘后释放所有键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上使用X11/Xorg时,当您使用xinput禁用键盘(例如xinput set-prop $ID "Device Enabled" 0)时,不会发送'key-up'事件(因为您已禁用键盘).如果您在命令行上输入该命令,这将是值得注意的,它的行为就像您按住"enter"(输入)一样.这是因为在您将手指从Enter键上移开之前,该命令(会禁用键盘)会运行.

On Linux when using X11/Xorg, when you use xinput to disable they keyboard (e.g. xinput set-prop $ID "Device Enabled" 0) the 'key-up' event is not send (because you've disabled the keyboard). This is noticable if you enter that command on the command line, it'll act like you're holding 'enter' down. This is because the command (which disables the keyboard) runs before you lift your finger off the enter key.

此错误中对此进行了讨论( https ://bugs.launchpad.net/ubuntu/+source/xserver-xorg-input-evdev/+bug/724280 )和此博客文章(

This is discussed in this bug ( https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-input-evdev/+bug/724280 ) and this blog post ( http://blog.yjl.im/2010/12/using-xinput-to-disable-keyboard-mouse.html ).

我正在编写一个需要禁用键盘的程序,并希望避免此问题.是否有任何方法/命令可以释放当前按下的所有键"(可以在禁用键盘"命令之后运行)?还是有一个命令/方式获取所有当前按下的键的列表"以及一种手动/以编程方式发送键释放"事件的方法? (通过这种方式,我可以禁用键盘,查看按下了哪些键,然后释放"这些键).

I am writing a programme that needs to disable the keyboard, and want to avoid this problem. Is there any way/command to "release all the keys that are currently pressed" (which could be run just after the "disable the keyboard" command)? Or is there a command/way to "get a list of all the current keys that are pressed" and a way to manually/programmatically send the "key released" event? (This way I could disable the keyboard, see what keys are pressed, and then 'release' those keys).

这可能吗?

推荐答案

您所体验到的是终端仿真器如何处理键盘事件以及shell做出反应的独特之处.当您按下Enter键时,外壳程序将执行赋予它的命令,并且您的命令xinput ...将在按下Enter键之前完成.由于禁用了键盘,因此甚至没有按键释放事件会进入事件处理.

What you experience is a peculiarity of how keyboard events are processed by terminal emulators and the shell reacts. When you press enter the shell will execute the command given to it, and your command xinput ... will finish before enter is even depressed. Since the keyboard gets disabled no key release event will be even entering the event processing.

这不是错误,而是功能.

It's not a bug, it's a feature.

解决方法:要么在实际执行分离之前等待所有键被按下,要么在xinput命令之前添加睡眠(这两个都是竞争条件,因此不是100%可靠的).

How to work around it: Either wait for all keys to be depressed before actually executing the detach, or just add a sleep before the xinput command (those are both race conditions, so it's not 100% reliable).

即将其放在shell命令行上

I.e. putting this on the shell command line

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

在实际禁用xinput之前,将先睡眠一秒钟.如果您不按住Enter键,则应该以所需的状态显示.

Will first sleep for a second before actually doing the xinput disable. If you don't keep the enter key pressed you should come out in the desired state.

这篇关于在使用xinput禁用X11/Linux中的键盘后释放所有键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆