本文整理汇总了Python中win32api.mouse_event函数的典型用法代码示例。如果您正苦于以下问题:Python mouse_event函数的具体用法?Python mouse_event怎么用?Python mouse_event使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mouse_event函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close_alter_window
def close_alter_window(self, elapsed_seconds=1):
'''点击安全警告窗口中的“运行”按钮, 尝试3次失败后关闭该窗口
'''
try_num = 0
start = time.time()
while True:
hwnd = winGuiAuto.findTopWindows(u"安全警告".encode('gbk'))
if hwnd:
try:
(left, top, right, bottom) = win32gui.GetWindowRect(hwnd[0])
x = left + 460
y = top + 255
win32api.SetCursorPos((x, y))
win32api.ClipCursor((x, y, x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
win32api.ClipCursor((0, 0, 0, 0))
except Exception, e:
print e
win32api.ClipCursor((0, 0, 0, 0))
try_num += 1
if try_num > 3:
win32api.SendMessage(hwnd[0], win32con.WM_CLOSE, 0, 0)
break
time.sleep(3)
continue
if elapsed_seconds == 0:
break
if self.elapsed(start) > 10:
break
time.sleep(1)
示例2: MoveToLocation
def MoveToLocation(pos, duration=0, tick=0.01):
"""Move the mouse cursor to a specified location, taking the specified time.
Args:
pos: position (in screen coordinates) to move to
duration: amount of time the move should take
tick: amount of time between successive moves of the mouse
Returns:
None
"""
# calculate the number of moves to reach the destination
num_steps = (duration/tick)+1
# get the current and final mouse position in mouse coords
current_location = ScreenToMouse(win32gui.GetCursorPos())
end_location = ScreenToMouse(pos)
# Calculate the step size
step_size = ((end_location[0]-current_location[0])/num_steps,
(end_location[1]-current_location[1])/num_steps)
step = 0
while step < num_steps:
# Move the mouse one step
current_location = (current_location[0]+step_size[0],
current_location[1]+step_size[1])
# Coerce the coords to int to avoid a warning from pywin32
win32api.mouse_event(
win32con.MOUSEEVENTF_MOVE|win32con.MOUSEEVENTF_ABSOLUTE,
int(current_location[0]), int(current_location[1]))
step += 1
time.sleep(tick)
示例3: MouseDownMove
def MouseDownMove(self,x,y):
# 按下后拖住移动
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y)
time.sleep(0.05)
windll.user32.SetCursorPos(x,y)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y)
time.sleep(0.5)
示例4: click
def click(cls, x, y):
win32api.SetCursorPos((x, y))
time.sleep(cls.IN_BETWEEN_DELAY)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
time.sleep(cls.IN_BETWEEN_DELAY)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
time.sleep(cls.AFTER_DELAY)
示例5: mouseClick
def mouseClick(x,y):
if not x is None and not y is None:
mouseMove(x,y)
time.sleep(0.03)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
time.sleep(0.01)
示例6: FX_MouseLClick
def FX_MouseLClick(x, y):
if platform.system() == 'Windows':
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, int(x), int(y), 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, int(x), int(y), 0, 0)
else:
global g_m
g_m.click(x, y, 1)
示例7: disablescanner
def disablescanner(self):
autopy.mouse.move(933,39)
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
time.sleep(0.1)
示例8: click
def click(x, y):
""" click(x, y): click at (x,y) """
xx, yy = win32api.GetCursorPos()
win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
l.info("(%4d, %4d) --> (%4d, %4d) clicked" % (xx, yy, x, y))
示例9: left_click
def left_click(item_coordinates):
win32api.SetCursorPos((x_pad + item_coordinates[0], y_pad + item_coordinates[1]))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
time.sleep(.02)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
# Gave the game a second to catch up
time.sleep(.2)
示例10: mouse_fun
def mouse_fun(self):
mouse_click_delay = 1
anchor_pos = np.array((0, 0))
start_time = time.clock()
while 1:
ret, view = self.vid.read()
if not self.q_key.empty():
keypress = self.q_key.get_nowait()
if keypress == ord('q'):
self.q_frame.put(np.zeros([self.board_h, self.board_w], dtype=np.uint8))
return
elif keypress == ord('r'):
self.canvas = np.zeros([self.board_h, self.board_w], dtype=np.uint8)
print('canvas cleared')
board = cv2.warpPerspective(view, self.H, (self.board_w, self.board_h))
dt_view = self.find_dots(board)
key_points = self.detector(dt_view)
if len(key_points) > 0:
pos = np.array((int(key_points[0][0]) + win32api.GetSystemMetrics(0), int(key_points[0][1]) + 30))
win32api.SetCursorPos(pos)
if np.linalg.norm(pos - anchor_pos) > 30:
anchor_pos = pos
start_time = time.clock()
else:
if time.clock() - start_time > mouse_click_delay:
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, pos[0], pos[1], 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, pos[0], pos[1], 0, 0)
start_time = time.clock()
else:
start_time = time.clock()
示例11: _run
def _run(self):
# move mouse
insertState = self._appAttr["AppInfo"].keyMouseInputState["INSERT"].state
if insertState:
self.isEnabled = not self.isEnabled
if not self.isEnabled:
return
self.isFiring = self._appAttr["AppInfo"].keyMouseInputState["LMB"].state
if self.isFiring:
px, py = self.screenCenterX, self.screenCenterY
fScreenWidth = windll.user32.GetSystemMetrics(0) - 1.0 # SM_CXSCREEN
fScreenHeight = windll.user32.GetSystemMetrics(1) - 1.0 # SM_CYSCREEN
rx = 65535.0 / fScreenWidth
ry = 65535.0 / fScreenHeight
py += 130
#self.input.mi.dx = int( ceil(px * rx) )
#self.input.mi.dy = int( ceil(py * ry) )
#windll.User32.SendInput(1, byref(self.input), sizeof(self.input))
c_px = int(ceil(px))
c_py = int(ceil(py))
win32api.mouse_event(self.mouseMoveFlag, c_px, c_py)
self.frame += 1
else:
self.frame = 0
示例12: click
def click(x, y):
x = x_off + x * tile_dim
y = y_off + y * tile_dim
win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x, y, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
time.sleep(speed)
示例13: ClickPosition
def ClickPosition(ie, x, y):
win32api.SetCursorPos((x,y))
#sleep(2)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
#sleep(2)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
sleep(1)
示例14: printing_handler
def printing_handler(addr, tags, data, source):
left_hand_id = 7
right_hand_id = 11
#print "---"
print "received new osc msg from %s" % getUrlStr(source)
# print "with addr : %s" % addr
# print "typetags : %s" % tags
# print "---"
#print data
left_hand = data[1+left_hand_id].split(',')
right_hand = data[1+right_hand_id].split(',')
x = float(right_hand[0])
y = float(right_hand[1])
# x = (x-0.5)*1.2+0.5;
# y = (y-0.5)*1.2+0.5;
cx = int(x*65536)#win32api.GetSystemMetrics(0))
cy = int(y*65536)#win32api.GetSystemMetrics(1))
#print cx,cy
if start == True:
#win32api.SetCursorPos((cx,cy))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN|win32con.MOUSEEVENTF_MOVE|win32con.MOUSEEVENTF_ABSOLUTE,cx,cy)
示例15: clicker
def clicker():
"""Checks for keyboard combinations and handles clicking."""
global cps
global speed
while True:
if win32api.GetAsyncKeyState(81) != 0 and win32api.GetAsyncKeyState(16) != 0: #Check if Shift + Q is pressed
while True:
(x,y) = win32api.GetCursorPos() #Get the current position of the cursor
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
cps += 1
time.sleep(speed)
if win32api.GetAsyncKeyState(38) != 0 and win32api.GetAsyncKeyState(16) != 0 and speed > 0.005: #Check if Shift + Up is pressed
speed -= 0.005
cps = 0
time.sleep(0.1)
if win32api.GetAsyncKeyState(40) != 0 and win32api.GetAsyncKeyState(16) != 0 and speed < 1: #Check if Shift + Down is pressed
speed += 0.005
cps = 0
time.sleep(0.1)
if win32api.GetAsyncKeyState(87) != 0 and win32api.GetAsyncKeyState(16) != 0: #Check if Shift + W is pressed
break
cps = 0