def ctrl_click(self, x, y): """Clicks at pixel x, y while simulating the CTRL button to be down.""" x += window.x y += window.y lParam = win32api.MAKELONG(x, y) while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) win32gui.PostMessage(window.id, wcon.WM_KEYDOWN, wcon.VK_CONTROL, 0) win32gui.PostMessage(window.id, wcon.WM_LBUTTONDOWN, wcon.MK_LBUTTON, lParam) win32gui.PostMessage(window.id, wcon.WM_LBUTTONUP, wcon.MK_LBUTTON, lParam) win32gui.PostMessage(window.id, wcon.WM_KEYUP, wcon.VK_CONTROL, 0) time.sleep(userset.MEDIUM_SLEEP)
def voice(): file = "static//js//Category//findout.csv" state_left = win32api.GetKeyState( 0x01) # Left button down = 0 or 1. Button up = -127 or -128 state_right = win32api.GetKeyState( 0x02) # Right button down = 0 or 1. Button up = -127 or -128 df = pd.read_csv(file) speak = wincl.Dispatch("SAPI.SpVoice") speak.Speak(str(len(df)) + "search results") a = win32api.GetKeyState(0x01) b = win32api.GetKeyState(0x02) for x in range(len(df)): strvoice = df['Description'][x] speak.Speak(f"The link {x+1} {strvoice}") if state_left: # Button state changed driver = webdriver.Chrome(executable_path=r'chromedriver.exe') driver.get(df['Link'][x])
def send_mouse_info(server): # send mouse info to server global last_pos WAIT_TIME = int(sys.argv[-2]) / 1000 while True: cur_pos = get_mouse_pos() if last_pos != cur_pos: mapped_pos = map_mouse_pos(cur_pos) server.tasks.append(b'<MOUSE-POS %i-%i>' % (mapped_pos[0], mapped_pos[1])) last_pos = cur_pos[:] ara.time.sleep(WAIT_TIME) left_state = win32api.GetKeyState(0x01) right_state = win32api.GetKeyState(0x02) if left_state not in [0, 1]: server.tasks.append(b'<MOUSE-PRESS 1>') if right_state not in [0, 1]: server.tasks.append(b'<MOUSE-PRESS 2>')
def select_area(): global box_size count = 0 mouse = Mouse_Controller() # Mouse obj state_left = win32api.GetKeyState(0x01) while True: buttons_clicked = win32api.GetKeyState(0x01) if buttons_clicked != state_left: # Button state changed state_left = buttons_clicked if buttons_clicked < 0: x1, y1 = mouse.position else: x2, y2 = mouse.position box_size = (x1, y1, x2, y2) print(box_size) break
def detect_key_state_thread(self, key, active, vk, key_state): # 키보드 입력 감지 스레드 global exit_var while True: sem.acquire() # 임계영역 생성 if exit_var: # 스레드 종료 변수 값이 설정됐을 경우 sem.release() # 임계영역 해제 return # 스레드 종료 cur_key_state = win32api.GetKeyState(vk[1]) # 현재 키보드 입력 상태 if cur_key_state != key_state: # 키보드 입력 상태가 변경됐을 경우 key_state = cur_key_state # 키보드 입력 상태 갱신 if key_state == -127 or key_state == -128: # 두번 실행 방지 act = active.split(' ') # 설정 파일 내용 저장 if key == self.pause: # 입력한 키가 설정한 중지 키일 경우 exit_var = True # 스레드 종료 변수 값 설정 self.start = False # 시작 버튼 눌림 여부 값 변경 self.statusBar.showMessage('Pause') # 상태 표시줄 내용 갱신 sem.release() # 임계영역 해제 return # 스레드 종료 for i in range(0, len(act)): # 설정 파일 if act[i] == key + ':' and i == 0: # 핫키 구분자일 경우 continue elif i%2 == 0 and i != 1: # 딜레이 시간일 경우 time.sleep(float(act[i])) # 딜레이 시간만큼 정지 elif i%2 == 1 or i == 1: # 동작일 경우 if 'move' in act[i]: # 마우스 이동일 경우 move_x = act[i].split('^')[1].split(',')[0] # 이동할 x값 저장 move_y = act[i].split('^')[1].split(',')[1] # 이동할 y값 저장 myMacro.move_mouse_game(int(move_x), int(move_y)) # 설정한 좌표로 마우스 이동 else: # 마우스 이동이 아닐 경우 if '^' in act[i]: # 지속 입력 및 클릭일 경우 continue_time = act[i].split('^')[1] # 지속 시간 저장 if 'leftclick' in act[i]: # 마우스 지속 좌클릭일 경우 myMacro.click_mouse_down_left() # 마우스 좌클릭 상태 유지 time.sleep(float(continue_time)) # 지속 시간만큼 대기 myMacro.click_mouse_up_left() # 마우스 좌클릭 상태 해제 elif 'rightclick' in act[i]: # 마우스 지속 우클릭일 경우 myMacro.click_mouse_down_right() # 마우스 우클릭 상태 유지 time.sleep(float(continue_time)) # 지속 시간만큼 대기 myMacro.click_mouse_up_right() # 마우스 우클릭 상태 해제 elif 'wheelclick' in act[i]: # 마우스 지속 휠클릭일 경우 myMacro.click_mouse_down_wheel() # 마우스 휠클릭 상태 유지 time.sleep(float(continue_time)) # 지속 시간만큼 대기 myMacro.click_mouse_up_wheel() # 마우스 휠클릭 상태 해제 else: # 키보드 지속 입력일 경우 input_key = act[i].split('^')[0] # 입력 키 저장 myMacro.input_down_keyboard(input_key) # 입력 키 눌림 상태 유지 time.sleep(float(continue_time)) # 지속 시간만큼 대기 myMacro.input_up_keyboard(input_key)# 입력 키 눌림 상태 해제 else: # 지속 입력 및 클릭이 아닐 경우 if 'leftclick' in act[i]: # 마우스 좌클릭일 경우 myMacro.click_mouse_left(0,0) # 마우스 좌클릭 elif 'rightclick' in act[i]: # 마우스 우클릭일 경우 myMacro.click_mouse_right(0,0) # 마우스 우클릭 elif 'wheelclick' in act[i]: # 마우스 휠클릭일 경우 myMacro.click_mouse_wheel() # 마우스 휠클릭 else: # 키보드 입력일 경우 myMacro.input_keyboard(act[i]) # 키보드 입력 sem.release() # 임계영역 해제
def send_string(self, string): """Send one or multiple characters to the window.""" if type(string) == float: # Remove decimal string = str(int(string)) for c in str(string): while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) if c.isdigit(): # Digits only require KEY_UP event. win32gui.PostMessage(window.id, wcon.WM_KEYUP, ord(c.upper()), 0) # time.sleep(0.03) # This can probably be removed continue win32gui.PostMessage(window.id, wcon.WM_KEYDOWN, ord(c.upper()), 0) time.sleep(userset.SHORT_SLEEP) # This can probably be removed win32gui.PostMessage(window.id, wcon.WM_KEYUP, ord(c.upper()), 0) time.sleep(userset.SHORT_SLEEP)
def send_delayed_key(self): #timeout: this must be a real one, send it now dk = self.delayed_event log("send_delayed_key() delayed_event=%s", dk) if dk: self.delayed_event = None altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1) if altgr: KeyboardBase.process_key_event(self, *dk)
def keydown(self): if (win32api.GetKeyState((self.key)) & (1 << 7)) != 0: if self.state == 0: self.draw() self.press() else: if self.state == 1: self.draw() self.unpress()
def GetKeydown(code): """ Check if the key with keycode is held down. :param code: Keycode of the key. :type code: Integer """ return (win32api.GetKeyState(code) & (1 << 15)) != 0
def __init__(self, diag=30, path='C:/Users/kir/Desktop/actions/', state_left=0): self.diag = diag self.path = path self.num = 0 self.state_left = win32api.GetKeyState(0x01) self.img = 0
def detect_mouse_click(arg): state_left = win32api.GetKeyState( 0x01) # Left button down = 0 or 1. Button up = -127 or -128 state_right = win32api.GetKeyState( 0x02) # Right button down = 0 or 1. Button up = -127 or -128 while True: a = win32api.GetKeyState(0x01) if a != state_left: # Button state changed state_left = a if a < 0: #print('Left Button Pressed') coords = pyautogui.position() return coords time.sleep(0.001)
def initial(): import json import sys from colorama import init, AnsiToWin32, Fore, Back, Style import math # import datetime init(wrap=False) stream = AnsiToWin32(sys.stderr).stream try: regex = "Session A - [24 x 80]" state_left = win32api.GetKeyState( 0x01) # Left button down = 0 or 1. Button up = -127 or -128 state_right = win32api.GetKeyState( 0x02) # Right button down = 0 or 1. Button up = -127 or -128 import os.path secs_between_keys = 0.01 win = WindowMgr() win_ins = win.find_window(regex) filename = "images/vgm.png" print(Style.RESET_ALL + '===Starting Process==', file=stream) if win_ins == None: print(Fore.RED + ('-Not found session : %s' % regex), file=stream) print(Fore.RED + '-Please open CTCS program before execute..', file=stream) sys.exit() win.Maximize(win_ins) # (x,y,w,h) =win.set_onTop(win_ins) (x, y, w, h) = win.set_onTop(win_ins) vHeighScreen = h * 0.11 except Exception as e: # except: if hasattr(e, 'message'): print(e.message) else: print(e) print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e)
def playGame(): up = 740206 left = 643346 right = 611908 down = 599127 b = 553387 a = 1044869 start = 125360 select = 47308 y = 1 time.sleep(2) #click(300,300) while (win32api.GetKeyState(0x1B) > -100): #3000 runs per minute x = random.randint(0, up + left + right + down + b + a + start + select) if 0 < x < up: upArrow() upArrow() upArrow() upArrow() upArrow() print 'UP' elif up <= x < up + left: leftArrow() leftArrow() leftArrow() leftArrow() leftArrow() print 'LEFT' elif up + left <= x < up + left + right: rightArrow() rightArrow() rightArrow() rightArrow() rightArrow() print 'RIGHT' elif up + left + right <= x < up + left + right + down: downArrow() downArrow() downArrow() downArrow() downArrow() print 'DOWN' elif up + left + right + down <= x < up + left + right + down + b: buttonB() print "B" elif up + left + right + down + b <= x < up + left + right + down + b + a: buttonA() print 'A' elif up + left + right + down + b + a <= x < up + left + right + down + b + a + start: Start() print 'START' elif up + left + right + down + b + a + start <= x < up + left + right + down + b + a + start + select: Select() print 'SELECT' sys.exit("Error message")
def __init__(self, root = root): self.root = root self.root.title("PingPong Yo") self.canvas = Canvas(self.root, bg="black", height=400, width=400) self.canvas.pack() self.r_x, self.r_y = 50,50 self.x,self.y = randint(50,350),randint(50,350) self.vx, self.vy = 1, -1 self.bola = self.canvas.create_oval(self.x,self.y,self.x+self.r_x,self.y+self.r_y, fill="white") # untuk posisi mouse self.state_awal = api.GetKeyState(0x01) #untuk paddle self.paddle_x1 = 380 self.paddle_y1 = 30 self.paddle_x2 = 399 self.paddle_y2 = 120 self.paddle1 = self.canvas.create_rectangle(380, 30, 399, 120, fill="green") self.paddle2 = self.canvas.create_rectangle(1,30,18,120, fill="green") #untuk posisi mouse # self.tx = self.canvas.winfo_pointerx() - self.canvas.winfo_rootx() # self.ty = self.canvas.winfo_pointery() - self.canvas.winfo_rooty() while True: self.tyb = self.canvas.winfo_pointery() - self.canvas.winfo_rooty() self.canvas.move(self.bola, self.vx, self.vy) self.canvas.after(1) self.canvas.update() self.tx = self.canvas.winfo_pointerx() - self.canvas.winfo_rootx() self.ty = self.canvas.winfo_pointery() - self.canvas.winfo_rooty() # if api.GetKeyState(0x01) != self.state_awal and self.tx > 0 and self.tx < 400 and self.ty > 400 and self.ty < 400 : self.canvas.move(self.paddle1, 0, self.ty - self.tyb) self.canvas.move(self.paddle2,0,self.ty - self.tyb) if self.canvas.coords(self.bola)[1] == 0: self.vy = 1 if self.canvas.coords(self.bola)[0]+self.r_x == 400: self.vx = -1 if self.canvas.coords(self.bola)[1]+self.r_y == 400: self.vy = -1 if self.canvas.coords(self.bola)[0] == 0: self.vx = 1 print((str(self.tx) if self.tx <= 400 else "400") + " ," + (str(self.ty) if self.ty <= 400 else "400"))
def Start_Count_Down_Then_Capture(monitorNum, killCamOnly=False): ring = RingBuffer(100) print("User Aiming") start_time = time.time() state_left = win32api.GetKeyState(0x01) state_left_time = time.time() state_right = win32api.GetKeyState(0x02) while time.time() - start_time < 2: if state_right == 0: return False else: state_right = win32api.GetKeyState(0x02) capture_count = 0 while state_right < 0: ring.append(Capture_Sights(monitorNum)) state_right = win32api.GetKeyState(0x02) state_left = win32api.GetKeyState(0x01) capture_count += 1 if state_left < 0: print("Shot taken, rendering gif") state_left_time = time.time() while time.time() - state_left_time < .25: ring.append(Capture_Sights(monitorNum)) fireSeconds = round(time.time() - start_time, 2) final_result = Capture_Result(monitorNum) if killCamOnly == False: ring.CreateTargetGif(fireSeconds, final_result) else: ring.CreateKillCamGif(fireSeconds) print("Gif rendered, ready to capture next shot") return True break return False
def send_delayed_key(self): #timeout: this must be a real one, send it now dk = self.delayed_event if dk: self.delayed_event = None altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1) if altgr: send_key_action_cb, wid, key_event = dk KeyboardBase.process_key_event(self, send_key_action_cb, wid, key_event)
def turn_off_caps_lock(): """ Turn off the caps lock key. """ if win32api.GetKeyState(win32con.VK_CAPITAL): win32api.keybd_event(win32con.VK_CAPITAL, 0x3a, win32con.KEYEVENTF_EXTENDEDKEY, 0) win32api.keybd_event( win32con.VK_CAPITAL, 0x3a, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) pass
def identify_click(): while (win32api.GetKeyState(0x20) == 0): timer_100ms = threading.Timer(0.10, identify_click) #print("Waiting for Spacebar") time.sleep(.15) application() #print("Spacebar Status=%d" %(win32api.GetKeyState(0x20))) #print("Not Entered While Case") #while(timer_100ms.is_alive()): print("Waiting for Timer")
def click(self, x: int = None, y: int = None): """Click at pixel xy.""" x = int(x / self.zoom_count) #1.5是缩放比例 y = int(y / self.zoom_count) lParam = win32api.MAKELONG(x, y) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_MOUSEMOVE, wcon.MK_LBUTTON, lParam) win32gui.SendMessage( self.ScreenBoardhwnd, wcon.WM_SETCURSOR, self.ScreenBoardhwnd, win32api.MAKELONG(wcon.HTCLIENT, wcon.WM_LBUTTONDOWN)) # win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_SETCURSOR, 0, 0) while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_LBUTTONDOWN, wcon.MK_LBUTTON, lParam) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_LBUTTONUP, 0, lParam)
def draw(self, curve, tmin, tmax, steps=2, wait_time=1 / 500.): """ draws the curve given by moving the mouse down at each curve(t) for tmin<=t<=tmax with `steps` steps. The pause between each step is `wait_time` the mouse state is NOT restored up in the end Pauses before starting if MB3 is pressed, resumes when MB3 (usually mouse wheel click) is pressed again """ if win32api.GetKeyState( 0x04) < 0: # mb3 down, usually mouse wheel click m_up() while win32api.GetKeyState( 0x04) < 0: # mb3 down, usually mouse wheel click sleep(wait_time) while win32api.GetKeyState( 0x04) >= 0: # mb3 up, usually mouse wheel click sleep(wait_time) while win32api.GetKeyState( 0x04) < 0: # mb3 down, usually mouse wheel click sleep(wait_time) if self.prev_curs_pos.shape[0] != 0: # if there's a prev position m_move(self.prev_curs_pos[0], self.prev_curs_pos[1]) m_down() stay_on = False # don't get the mouse up if there no change of position between two curves x, y = curve(tmin) x, y = int(self.xmin + max(0, min(x, self.sX))), int(self.ymin + max(0, min(y, self.sY))) if self.prev_curs_pos.shape[0] != 0: # if there's a prev position stay_on = array_equal(array([x, y]), self.prev_curs_pos) m_up() sleep(wait_time) m_move(x, y) m_down() for t in linspace(tmin, tmax, steps): pos = curve(t) x, y = pos[0], pos[1] x, y = int(self.xmin + max(0, min(x, self.sX))), int(self.ymin + max(0, min(y, self.sY))) m_move(x, y) sleep(wait_time) self.prev_curs_pos = array([x, y])
def run(self) -> None: while True: a = win32api.GetKeyState(0x01) ox, oy = win32api.GetCursorPos() if a != self.state_left: # Button state changed self.state_left = a if a < 0 and self.painter_widget.mode == "chaos_recipe": self.painter_widget.process_mouse_click(ox, oy) sleep(0.001)
def get_mouseposition(self): state_left = win32api.GetKeyState(0x01) if state_left == -127 or state_left == -128: xclick, yclick = win32api.GetCursorPos() dummy_pos = xclick, yclick d = Dummy(EXERCISE_WEAPON_HOTKEY, CHAR_NAME, dummy_pos) self.quit() d.main() else: self.after(10, self.get_mouseposition)
def OnKeyboardEvent(event): CAPS = win32api.GetKeyState(win32con.VK_CAPITAL) logging.basicConfig(filename=output, level=logging.DEBUG, format='%(message)s') #print(event.__dict__) #print(type(event.flags)) if event.ScanCode in no_output: #key pressed is a non output key, so we have to identify it by its scancode scan_code = event.ScanCode flag = event.flags if scan_code == 56 or scan_code == 29: x = no_output[scan_code][flag] else: x = no_output[scan_code] else: #key pressed is an ascii character keylogs = chr(event.Ascii) x = keylogs #capslock and shift logic if CAPS == 1: if keyboard.is_pressed('shift'): if keylogs.isalpha(): x = keylogs.lower() else: #only alphabet is capitalised! everything else is inverted if not keylogs.isalpha() and keylogs in invert: x = invert[keylogs] else: #caps is off if keyboard.is_pressed('shift'): x = keylogs else: if keylogs.isalpha(): x = keylogs.lower() else: if keylogs in invert: x = keylogs = invert[keylogs] s = str(x) + " time: " + str(datetime.now()) + " window: " + str(event.WindowName) + "\n" logging.log(10, s) print(s) return True
def get_positions(clicks): left_click=win32api.GetKeyState(0x01) positions_list=[] i=0 while True: l_click=win32api.GetKeyState(0x01) if l_click != left_click: left_click=l_click if l_click<0 : # GetKeyState returns a negative value if the key is pressed x_, y_ = pygui.position() positions_list.append({"x":x_,"y":y_}) i=i+1 if i==clicks: break time.sleep(0.01) return positions_list
def get_viewport_position(): first_click, second_click = (), () state_left = win32api.GetKeyState(0x01) while not (first_click and second_click): a = win32api.GetKeyState(0x01) if a != state_left: state_left = a if a < 0 and not first_click: first_click = win32api.GetCursorPos() elif a < 0 and not second_click: second_click = win32api.GetCursorPos() time.sleep(0.001) return [ min([first_click[0], second_click[0]]), min([first_click[1], second_click[1]]), max([first_click[0], second_click[0]]), max([first_click[1], second_click[1]]) ]
def mask_to_names(self, mask): """ Patch NUMLOCK and AltGr """ names = KeyboardBase.mask_to_names(self, mask) altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1) if altgr: self.AltGr_modifiers(names) if self.num_lock_modifier: try: numlock = win32api.GetKeyState(win32con.VK_NUMLOCK) if numlock and self.num_lock_modifier not in names: names.append(self.num_lock_modifier) elif not numlock and self.num_lock_modifier in names: names.remove(self.num_lock_modifier) log("mask_to_names(%s) GetKeyState(VK_NUMLOCK)=%s, names=%s", mask, numlock, names) except: pass else: log("mask_to_names(%s)=%s", mask, names) return names
def finding_pixeValue_start(): print( 'move the mouse to the start of the black rope (in right hand) and then click (open inventory to do so)' ) print( 'u need to hit a black pixel in order for it to work (the rbg will be 0, 0, 0 later, else it will restart!' ) while True: if win32api.GetKeyState(0x01) == -128 or win32api.GetKeyState( 0x01) == -127: global position position = pyautogui.position() #Tuple Point(X|Y) print(position[0]) #int print(position[1]) #int print('close inventory for checking color(in 2 seconds)!') time.sleep(2) if ImageGrab.grab().getpixel(position) == (0, 0, 0): break else: print('rgb value of rope (must be 0,0,0!!!):')
def move_click(self,x:int=None,y:int=None,x1:int=None,y1:int=None,Stride_x:int=1,Stride_y:int=1): x = int(x/self.zoom_count)#1.5是缩放比例 y = int(y/self.zoom_count) x1 = int(x1/self.zoom_count) y1 = int(y1/self.zoom_count) x_down = False y_down = False lenth_x = None lenth_y = None lParam1 = win32api.MAKELONG(x, y) lParam2 = win32api.MAKELONG(x1, y1) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_MOUSEMOVE,wcon.MK_LBUTTON, lParam1) # win32gui.SendMessage(self.ScreenBoardhwnd, wcon.WM_SETCURSOR, self.ScreenBoardhwnd, win32api.MAKELONG(wcon.HTCLIENT, wcon.WM_LBUTTONDOWN)) while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or win32api.GetKeyState(wcon.VK_SHIFT) < 0 or win32api.GetKeyState(wcon.VK_MENU) < 0): time.sleep(0.005) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_LBUTTONDOWN, wcon.MK_LBUTTON, lParam1) time.sleep(0.1) #如果小于,降序 if x >= x1: x_down = True lenth_x = abs(x-x1)+1 if y >= y1: y_down = True lenth_y = abs(y-y1)+1 for lx in range(0,lenth_x,Stride_x): for ly in range(0,lenth_y,Stride_y): if x_down: x2 =x - lx else: x2 =x + lx if y_down: y2 = y - ly else: y2 = y + ly #print("x2:{0}y2:{1}".format(x2,y2)) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_MOUSEMOVE,wcon.MK_LBUTTON, win32api.MAKELONG(x2,y2)) win32gui.PostMessage(self.ScreenBoardhwnd, wcon.WM_LBUTTONUP, wcon.MK_LBUTTON, lParam2)
def KeyBoard_Output(key_out, flag_out, finger_in): """ 子线程按键按下触发事件 :param key_out: 主线程队列的键值 输出 :param flag_out: 主线程队列的标志位 输出 :param finger_in: 主线程队列手指个数 输入 :return: None """ while True: exist_flag = flag_out.get() finger_in.put(0) key = key_out.get() keys = [] if isinstance(key, int) and exist_flag == 1 and key != 0: if key == 13 or key == 25 or key == 38 or key == 52 or key == 53 or key == 54 or key == 55: win32api.keybd_event(KeyValue[key], 0, 0, 0) while (key == 13 or key == 25 or key == 38 or key == 52 or key == 53 or key == 54 or key == 55)\ and keys != 0: # 多指标志位,1为切换多指,0为单指 finger_in.put(1) keys = key_out.get() print(win32api.GetKeyState(KeyValue[key])) if isinstance(keys, int): pass # 三指快捷键太少了,这个函数库也不支持使用 # elif len(keys) == 3: # Third_Key(keys) else: for hot_key in keys: win32api.keybd_event(KeyValue[hot_key], 0, 0, 0) # if hot_key == print(hot_key) else: win32api.keybd_event(KeyValue[key], 0, 0, 0) print(win32api.GetKeyState(KeyValue[key])) win32api.keybd_event(KeyValue[key], 0, win32con.KEYEVENTF_KEYUP, 0) else: pass # 注意这里暂停时间是要和主线程一致 time.sleep(0.15)
def run(self): self.load_count() self.load_json('source/image_label.json') #make sure active window is correct, mouse_left_click changed, mouse within image while True: if win32gui.GetWindowText( win32gui.GetForegroundWindow()) == 'GetSource': x, y = win32api.GetCursorPos() pixel = [y - 200, x - 200] if (0 + self.half_hstep ) < pixel[0] < (self.h - self.half_hstep) and ( 0 + self.half_wstep) < pixel[1] < (self.w - self.half_wstep): pt = (pixel[1] - self.half_wstep, pixel[0] - self.half_hstep) self.updt_im_rec(pt) current_left_click = win32api.GetKeyState(0x01) if self.recent_left_click != current_left_click and current_left_click >= 0: self.recent_left_click = current_left_click self.get_im(pixel) print("■", end='') self.image_cnt['im_count'] += 1 win32api.Sleep(300) else: if self.outside_state != True: self.not_active.emit() else: self.recent_left_click = win32api.GetKeyState(0x01) self.finished.emit()