概述
搞定了几个东西
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)
最后
以上就是负责皮带为你收集整理的搞定了几个东西的全部内容,希望文章能够帮你解决搞定了几个东西所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复