当我将它作为脚本运行时,Python-uinput 无法移动光标
python main.py
但是当我使用 Python 交互式逐步运行时,它工作正常
import uinput
import Tkinter as tk
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
root.destroy()
device = uinput.Device([
uinput.BTN_LEFT,
uinput.BTN_RIGHT,
uinput.REL_X,
uinput.REL_Y,
])
def main():
device.emit(uinput.REL_X, -1 * screen_width)
device.emit(uinput.REL_Y, -1 * screen_height)
if __name__ == '__main__':
main()
这是一个不移动光标的命令。
spksoft@spksoft ~/code/python/Sample HI $ python main.py
Traceback (most recent call last):
File "main.py", line 13, in <module>
uinput.REL_Y,
File "/usr/local/lib/python2.7/dist-packages/uinput/__init__.py", line 161, in __init__
self.__uinput_fd = _libsuinput.suinput_open()
File "/usr/local/lib/python2.7/dist-packages/uinput/__init__.py", line 64, in _error_handler
raise OSError(code, os.strerror(code))
OSError: [Errno 13] Permission denied
spksoft@spksoft ~/code/python/Sample HI $ sudo python main.py
spksoft@spksoft ~/code/python/Sample HI $
这是一个与 python 交互的命令,它可以正确移动光标。
spksoft@spksoft ~/code/python/Sample HI $ sudo python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import uinput
>>> import Tkinter as tk
>>> root = tk.Tk()
>>> screen_width = root.winfo_screenwidth()
>>> screen_height = root.winfo_screenheight()
>>> root.destroy()
>>> device = uinput.Device([
... uinput.BTN_LEFT,
... uinput.BTN_RIGHT,
... uinput.REL_X,
... uinput.REL_Y,
... ])
>>> device.emit(uinput.REL_X, -1 * screen_width)
>>> device.emit(uinput.REL_Y, -1 * screen_height)
>>>