搞定了几个东西
来源:互联网 发布:java wait 区别 编辑:程序博客网 时间:2024/04/30 00:59
搞定了几个东西
1,取得鼠标位置,get_mpos()
2,移动鼠标,set_mpos()
3,鼠标左键点击,move_click()
4,键盘输入(部分搞定,那个scancode还不明白是啥意思,为什么0x99输出的是字符'p'???)
代码如下
1,取得鼠标位置,get_mpos()
2,移动鼠标,set_mpos()
3,鼠标左键点击,move_click()
4,键盘输入(部分搞定,那个scancode还不明白是啥意思,为什么0x99输出的是字符'p'???)
代码如下
- from ctypes import *
- import time
- #<some pos>
- win_start = (9, 753)
- close_window = (1017, 4)
- #</some pos>
- PUL = POINTER(c_ulong)
- class KeyBdInput(Structure):
- _fields_ = [("wVk", c_ushort),("wScan", c_ushort),("dwFlags", c_ulong),("time", c_ulong),("dwExtraInfo", PUL)]
- class HardwareInput(Structure):
- _fields_ = [("uMsg", c_ulong),("wParamL", c_short),("wParamH", c_ushort)]
- class MouseInput(Structure):
- _fields_ = [("dx", c_long),("dy", c_long),("mouseData", c_ulong),("dwFlags", c_ulong),("time",c_ulong),("dwExtraInfo", PUL)]
- class Input_I(Union):
- _fields_ = [("ki", KeyBdInput),("mi", MouseInput),("hi", HardwareInput)]
- class Input(Structure):
- _fields_ = [("type", c_ulong),("ii", Input_I)]
- class POINT(Structure):
- _fields_ = [("x", c_ulong),("y", c_ulong)]
- #<Get Pos>
- def get_mpos():
- orig = POINT()
- windll.user32.GetCursorPos(byref(orig))
- return int(orig.x), int(orig.y)
- #</Get Pos>
- #<Set Pos>
- def set_mpos(pos):
- x,y = pos
- windll.user32.SetCursorPos(x, y)
- #</Set Pos>
- #<move and click>
- def move_click(pos, move_back = False):
- origx, origy = get_mpos()
- set_mpos(pos)
- FInputs = Input * 2
- extra = c_ulong(0)
- ii_ = Input_I()
- ii_.mi = MouseInput( 0, 0, 0, 2, 0, pointer(extra) )
- ii2_ = Input_I()
- ii2_.mi = MouseInput( 0, 0, 0, 4, 0, pointer(extra) )
- x = FInputs( ( 0, ii_ ), ( 0, ii2_ ) )
- windll.user32.SendInput(2, pointer(x), sizeof(x[0]))
- if move_back:
- set_mpos((origx, origy))
- return origx, origy
- #</move and click>
- def sendkey(scancode, pressed):
- FInputs = Input * 1
- extra = c_ulong(0)
- ii_ = Input_I()
- flag = 0x8 # KEY_SCANCODE
- ii_.ki = KeyBdInput( 0, 0, flag, 0, pointer(extra) )
- InputBox = FInputs( ( 1, ii_ ) )
-
- if scancode == None:
- return
- InputBox[0].ii.ki.wScan = scancode
- InputBox[0].ii.ki.dwFlags = 0x8 # KEY_SCANCODE
- if not(pressed):
- InputBox[0].ii.ki.dwFlags |= 0x2 # released
- windll.user32.SendInput(1, pointer(InputBox), sizeof(InputBox[0]))
- if pressed:
- print "%x pressed" % scancode
- else:
- print "%x released" % scancode
- if __name__ == '__main__':
- origx, origy = get_mpos()
- print 'Orig Pos:', origx, origy
- #set_mpos(9, 753)
- #move_click(win_start)
- move_click((800,600))
- time.sleep(1)
- sendkey(0x99,1)
- #keyboard_input()
-
- #set_mpos(origx, origy)
- 搞定了几个东西
- jquery 老牛叉了,几个调用搞定一切啊
- 搞定了
- 搞定了!
- 花了一天时间,搞定了JIVE3.14a.开源的东西真是麻烦.不过还好.
- 哈哈哈,好爽,经过几个礼拜的努力,终于把布料运算搞定了。
- 终于搞定UIScrollView上的几个tableview和collection view之间切换的问题了
- 十分钟搞定pandas(增加了几个实用技巧,持续更新)
- 用了几个月Mac OS X,发现很多东西…
- 马上就要搞定了!
- 终于搞定了mysql!
- 终于搞定了vmware
- CDS自己搞定了
- 工作搞定了
- 跳棋被搞定了
- 终于搞定了X~
- 终于搞定了conky
- 终于搞定Paypal了
- Python之Windows控件操作系列一:模拟鼠标点击
- linux-0.11调试教程,安装minix-1.5.10到硬盘(3)安装shoelace后修改/etc/rc文件和更改root密码
- 用Python监听鼠标和键盘事件
- 模拟鼠标键盘
- python键盘、鼠标控制
- 搞定了几个东西
- python 获取本机计算机名和IP地址
- Python 定时器 timer
- SQL查询语句大全集锦
- 使用bjam编译boost
- Django模板系统(非常详细)
- boost::regex学习
- search keyword
- 386. Take things as they come. 既来之,则安之。