python鼠标控制模块_使用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)

I get:

AttributeError: 'module' object has no attribute 'rawinput'

I then tried pymouse and although I used pip to install it when I import pymouse:

from pymouse import PyMouse

I get:

TypeError: Object value must be tuple, dictionary or DictWrapper: 0

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 "", line 1, in

File "/usr/local/lib/python2.7/dist-packages/pymouse/__init__.py", line 95, in

from unix import PyMouse, PyMouseEvent

File "/usr/local/lib/python2.7/dist-packages/pymouse/unix.py", line 53, in

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 "", 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 "", 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

Note the exception occurs in Xlib. I had version 0.15rc1 installed. Downgrading to 0.14 fixed the problem.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值