Python-uinput it can't move cursor when I run it as a script
python main.py
But when I run step by step with Python interactive It works fine
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()
This is a command that it does not move a cursor.
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 $
This is a command with python interactive and It can move a cursor correctly.
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)
>>>
test video : Python-uinput cursor does move test