我正在编写一个需要在特定时间轮询键盘键的程序,而不是通过编写我自己的事件驱动键盘轮询类的努力,我以为我会使用JInput的内置键盘类。
当我以root身份运行我的程序时(我在Ubuntu 10.10上运行)它完美地工作但是它甚至没有检测到当作为普通用户运行时键盘存在的事实。我得到以下错误输出:
Nov 29, 2010 2:08:50 PM net.java.games.input.DefaultControllerEnvironment getControllers
INFO: Loading: net.java.games.input.LinuxEnvironmentPlugin
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event11): Failed to open device /dev/input/event11 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event10): Failed to open device /dev/input/event10 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event9): Failed to open device /dev/input/event9 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event8): Failed to open device /dev/input/event8 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event7): Failed to open device /dev/input/event7 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event6): Failed to open device /dev/input/event6 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event5): Failed to open device /dev/input/event5 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event4): Failed to open device /dev/input/event4 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event3): Failed to open device /dev/input/event3 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event2): Failed to open device /dev/input/event2 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event1): Failed to open device /dev/input/event1 (13)
Nov 29, 2010 2:08:50 PM net.java.games.input.ControllerEnvironment log
INFO: Failed to open device (/dev/input/event0): Failed to open device /dev/input/event0 (13)
有没有人有使用JInput中的键盘的任何经验或任何有关如何解决此问题的想法,所以我不必以root身份运行?谢谢!
答案 0 :(得分:1)
您可以执行
,而不是以root身份运行程序sudo chmod a+r /dev/input/event5
(或者指向键盘的任何设备)由您决定哪种设备对您的目的更安全。我想,但不确定,重启后权限会恢复。
我没有能够让JInput的键盘适配器在Ubuntu中工作,而无需以root身份运行应用程序或执行上述操作。可能不是你想要的答案,但它至少会告诉你并不孤单。
为什么设备不能被任何人读取的明显原因是,无特权的程序(即键盘记录器)不能在任何给定时间只听取来自键盘的所有输入。我认为各种窗口系统以特权模式运行,然后控制对用户程序的键盘数据的访问。如果JInput通过该层,您可能不需要特殊权限。
修改强>
由于它似乎适用于OP,我将在此处包含barti_ddu的注释。如上所述,作为手动更改键盘设备权限的替代方法,您还可以设置udev规则,以便自动设置这些权限。值得注意的是,您可以使用它来设置设备组(例如“输入”),然后相应地运行程序。
这将涉及向/etc/udev/rules.d/99-evdev.rules
添加类似的内容:
KERNEL=="event*", NAME="input/%k", MODE="640", GROUP="input"
警告:未经测试。