2009-09-15

Python 模拟鼠标动作的函数

最近在写游戏机器人,用 Python 写的,需要模拟鼠标的动作。 Google 了好久,很快发现了模拟键盘的 virtkey,鼠标的很难找,但是最终还是找到了。

相关链接是

http://mail.python.org/pipermail/python-list/2007-December/641865.html
http://www.tranzoa.net/tzpython/tz_windows_stuff.py
以及 Xlib 文档

示例代码:


import Xlib.display
import Xlib.X
import Xlib.ext.xtest

# 点击
display = Xlib.display.Display()
def mouse_click(button): #button= 1 left, 2 middle, 3 right
Xlib.ext.xtest.fake_input(display,Xlib.X.ButtonPress, button)
display.sync()
Xlib.ext.xtest.fake_input(display,Xlib.X.ButtonRelease,
button)
display.sync()

# 移动
ds = display.Display()

def goto_xy(x, y) :
xtest.fake_input(ds, X.MotionNotify, x = x, y = y) #注意x,y参数的写法
ds.flush()

2009-09-09

Windows 键盘问题一例

今天打开电脑,进入Windows,登陆时竟然发现键盘不能用!冷静了一下后用软键盘登了,登陆后发现还是不行!

于是用鼠标和软键盘操作,看Device Manager,键盘设备有个黄叹号,设备状态里显示

Windows cannot start this hardware device because its configuration information (in the registry) is incomplete or damaged (code 19)

Google之,在http://www.edmartechguide.com/2009/02/windows-cannot-start-this-hardware.html里得到线索

于是进入Regedit,在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class项下逐个检查,直到找到{4D36E96B-E325-11CE-BFC1-08002BE10318},发现Class值是Keyboard,那么应该就是这项了

由于权限问题,改名和删除都不行,于是仔细观察各项,发现"UpperFilters"里有个可疑的alidevice,于是删掉,把"kbdclass alidevice"改成"kbdclass"

然后去Device Manager里Uninstall键盘设备,然后刷进,于是可以用了。

这样看来,应该是淘宝的驱动挂了,或者是让我搞挂了。

另外是Device Manager里的PS/2鼠标也不能用,这里是我笔记本上的触摸板。我用的鼠标是USB的,不过注册表里没有发现可疑项,重启以后自然能用了。

另外庆幸我的USB鼠标还能工作,否则输入设备一个都没了。。。好险

2009-09-07

gdm 配置文件的一个问题

今天想整一下xdmcp, gdm 配了半天也不出个所以然。
在我机器上 /etc/gdm 目录里 除了 gdm.conf gdm.conf-custom 还有个 gdm-cdd.conf
而且看 gdm 启动的命令行里竟然也是用 gdm-cdd.conf

根据 https://bugs.launchpad.net/ubuntu/+source/ubuntustudio-look/+bug/153837 里面的说法,这个是 ubuntustudio 的一些包搞的鬼。

于是就把 ubuntustudio 相关的所有包(主要是主题)删去, 问题解决。