使用python进行鼠标控制 [英] Mouse control with python
问题描述
我正在运行Ubuntu 12.04并使用python2.我希望能够控制鼠标,并且我发现有几种不同的python模块打算这样做,但无法使它们正常工作.
I'm running Ubuntu 12.04 and working with python 2. I would like to be able to control my mouse, and I have found several different python modules intended to do this, but cannot get them to work.
我安装了辫子,但是当我尝试时:
I installed dogtail, but when I try:
dogtail.rawinput.click(x,y)
我得到:
AttributeError: 'module' object has no attribute 'rawinput'
然后我尝试了pymouse,尽管我在导入pymouse时使用pip进行安装:
I then tried pymouse and although I used pip to install it when I import pymouse:
from pymouse import PyMouse
我得到:
TypeError: Object value must be tuple, dictionary or DictWrapper: 0
我也尝试了uinput模块,但是鼠标命令似乎只有放在循环中时才起作用,这令人沮丧/荒谬.
I tried the uinput module as well but the mouse commands only seemed to work when placed in a loop, which is frustrating/ridiculous.
如果有人知道如何解决这些问题/我做错了/更好或更易于使用的模块,我将非常感谢您的帮助.
If anyone knows how to fix either of those problems/what I'm doing wrong/better or easier to use modules I would much appreciate the help.
推荐答案
鉴于错误信息有限,我假设我的问题与您的相同.我得到的完整异常和回溯是:
I'll assume that my problem is the same as yours, given the limited error information. The full exception and traceback I got was:
>>> import pymouse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymouse/__init__.py", line 95, in <module>
from unix import PyMouse, PyMouseEvent
File "/usr/local/lib/python2.7/dist-packages/pymouse/unix.py", line 53, in <module>
class PyMouseEvent(PyMouseEventMeta):
File "/usr/local/lib/python2.7/dist-packages/pymouse/unix.py", line 66, in PyMouseEvent
'client_died': False,
File "/usr/local/lib/python2.7/dist-packages/Xlib/ext/record.py", line 121, in create_context
ranges = ranges)
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1403, in __init__
self._binary = apply(self._request.to_binary, args, keys)
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1088, in to_binary
return apply(self.to_binary, varargs, keys)
File "<string>", line 3, in to_binary
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 523, in pack_value
data.append(self.type.pack_value(v))
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1102, in pack_value
return apply(self.to_binary, (), value)
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1088, in to_binary
return apply(self.to_binary, varargs, keys)
File "<string>", line 4, in to_binary
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 573, in check_value
vals.append(f.check_value(val[i]))
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 582, in check_value
raise TypeError('Object value must be tuple, dictionary or DictWrapper: %s' % val)
TypeError: Object value must be tuple, dictionary or DictWrapper: 0
请注意,异常发生在Xlib中.我安装了版本0.15rc1. 降级到0.14可以解决此问题.
Note the exception occurs in Xlib. I had version 0.15rc1 installed. Downgrading to 0.14 fixed the problem.
这篇关于使用python进行鼠标控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!