def release(*args): ''' release depressed keys accepts as many arguments as you want. e.g. release('left_arrow', 'a','b'). ''' for i in args: win32api.keybd_event(VK_CODE[i], 0, 0x0002, 0)
def pressAndHold(*args): ''' press and hold. Do NOT release. accepts as many arguments as you want. e.g. pressAndHold('left_arrow', 'a','b'). ''' for i in args: win32api.keybd_event(VK_CODE[i], 0, 0, 0) time.sleep(.05)
def press(*args): ''' one press, one release. accepts as many arguments as you want. e.g. press('left_arrow', 'a','b'). ''' for i in args: win32api.keybd_event(VK_CODE[i], 0, 0, 0) time.sleep(.05) win32api.keybd_event(VK_CODE[i], 0, 0x0002, 0)
def set_foreground(self): """ 将窗口放在前台并激活 """ # _shell = win32com.client.Dispatch("WScript.Shell") # _shell.SendKeys('%') win32api.keybd_event(13, 0, 0, 0) if self.parent is None: # 避免非顶级窗口 result = win32gui.SetForegroundWindow(self.handle) if result == 0: self._raise_last_error()
def call(self, label): #gibrish text is a placeholder if self.mode == 0: if label=="ok_gesture": self.mode += 1 elif label == "point_up": win32api.keybd_event(VolUp, 48) elif label == "rock_and_roll": win32api.keybd_event(VolDown, 49) elif self.mode == 1: if label == "ok_gesture": self.mode += 1 elif label == "point_up": win32api.keybd_event(NextTrack, 25) elif label == "rock_and_roll": win32api.keybd_event(PrevTrack, 16) elif self.mode == 2: if label == "ok_gesture": self.mode += 1 elif label == "point_up": win32api.keybd_event(PlayPauseMedia, 34) elif label == "rock_and_roll": print("") elif self.mode == 3: if label == "ok_gesture": self.mode += 1 elif label == "point_up": if self.numberOfDevices > 0: self.devices[0].toggle() elif label == "rock_and_roll": if self.numberOfDevices > 1: self.devices[1].toggle() elif self.mode == 4: if label == "ok_gesture": self.mode = 0 elif label == "point_up": if self.numberOfDevices > 2: self.devices[2].toggle() elif label == "rock_and_roll": if self.numberOfDevices > 3: self.devices[3].toggle()
def getAllAsset(self): self.topWindow() time.sleep(0.5) # win32api.keybd_event(VK_CODE['F4'], 0, 0, 0) # distance = 54 # left_distance balance = u'资金余额' # 通过距离判断 balance = self.getSset(balance, distance) othe_balance = u'可用金额' othe_balance = self.getSset(othe_balance, distance) market_value = u'股票市值' market_value = self.getSset(market_value, distance) propertys = u'总 资 产' propertys = self.getSset(propertys, distance) AssetList = {'balance': balance['title'], 'othe_balance': othe_balance['title'], 'market_value': market_value['title'], 'propertys': propertys['title']} return AssetList
def getAllStock(self): win32api.keybd_event(VK_CODE['F4'], 0, 0, 0) attr = self.show_window_attr(self.para_hld) x = attr['post'][0] + 300 y = attr['post'][1] + 300 win32api.SetCursorPos([x, y]) # Mover to post(x,y) self.copyKey() copy_txt = self.getCopyText() copy_txt = copy_txt.rstrip().split("\n") c = [] cArray = {} cloun = '' for vv in copy_txt: cloun = vv.split(" ") for v in cloun: c.append(v) cArray[c[1]] = c c = [] return cArray
def send_msg(self, msg): self.lock.acquire() # for this problem: https://bbs.csdn.net/topics/390973288?page=1 win32api.keybd_event(0x11, 0, 0, 0) # ctrl win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32gui.ShowWindow(self.con_hwnd, win32con.SW_MAXIMIZE) win32gui.SetForegroundWindow(self.con_hwnd) win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(msg, win32con.CF_UNICODETEXT) win32clipboard.CloseClipboard() win32api.keybd_event(0x11, 0, 0, 0) # ctrl win32api.keybd_event(0x56, 0, 0, 0) # 'v' win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32api.keybd_event(0x11, 0, 0, 0) # ctrl win32api.keybd_event(0x0d, 0, 0, 0) # enter win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32api.keybd_event(0x0d, 0, win32con.KEYEVENTF_KEYUP, 0) # release key time.sleep(1) win32gui.SetForegroundWindow(self.cur_hwnd) self.lock.release()
## im.save(os.getcwd() + '\\full_snap__ ' + str(int(time.time())) + ##'.png', 'PNG') return im def check(im,k): for i in range(0,60+k): r,g,b =im.getpixel((i,0)) r=r+g+b if r<400: if checkagain(im,i+50): tk.clock() return True return False def checkagain(im,j): for i in range(j,30): r,g,b =im.getpixel((i,0)) r=r+g+b if r<400: return False return True k=0 while True: prev=k k=k+int(tk.clock()/100) if k>150: k=150 if check(screenshot(),int(k)): win32api.keybd_event(0x20, 0,0,0)
def Key_event(self, key): win32api.keybd_event(key, 0, 0, 0) # win32api.keybd_event(key, 0, win32con.KEYEVENTF_KEYUP, 0) #
def copyKey(self): win32api.keybd_event(VK_CODE['ctrl'], 0, 0, 0) # Alt win32api.keybd_event(VK_CODE['c'], 0, 0, 0) # O win32api.keybd_event(VK_CODE['c'], 0, win32con.KEYEVENTF_KEYUP, 0) # win32api.keybd_event(VK_CODE['ctrl'], 0, win32con.KEYEVENTF_KEYUP, 0)
def appStart(self, fileext, ver): win32api.ShellExecute(0, 'open', fileext, ver, '', 1) time.sleep(5) self.k.type_string(self.password) win32api.keybd_event(VK_CODE['tab'], 0, 0, 0) win32api.keybd_event(VK_CODE['enter'], 0, 0, 0)
def receive_msg(self): self.lock.acquire() # for this problem: https://bbs.csdn.net/topics/390973288?page=1 win32api.keybd_event(0x11, 0, 0, 0) # ctrl win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32gui.ShowWindow(self.con_hwnd, win32con.SW_MAXIMIZE) win32gui.SetForegroundWindow(self.con_hwnd) time.sleep(1) x_mid = int(win32api.GetSystemMetrics(win32con.SM_CXSCREEN) / 2) y_mid = int(win32api.GetSystemMetrics(win32con.SM_CYSCREEN) / 2) win32api.SetCursorPos([x_mid, y_mid]) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0) # left mouse button win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0) # release key win32api.keybd_event(0x11, 0, 0, 0) # ctrl win32api.keybd_event(0x41, 0, 0, 0) # 'a' win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32api.keybd_event(0x41, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32api.keybd_event(0x11, 0, 0, 0) # ctrl win32api.keybd_event(0x43, 0, 0, 0) # 'c' win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # release key win32api.keybd_event(0x43, 0, win32con.KEYEVENTF_KEYUP, 0) # release key time.sleep(1) win32clipboard.OpenClipboard() text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) win32clipboard.CloseClipboard() win32gui.SetForegroundWindow(self.cur_hwnd) time.sleep(1) self.lock.release() return text
def ctrlshiftaltv(): win32api.keybd_event(keys['shift'], 0, 0, 0) win32api.keybd_event(keys['ctrl'], 0, 0, 0) win32api.keybd_event(keys['alt'], 0, 0, 0) win32api.keybd_event(keys['v'], 0, 0, 0) win32api.keybd_event(keys['v'], 0, 2, 0) win32api.keybd_event(keys['ctrl'], 0, 2, 0) win32api.keybd_event(keys['alt'], 0, 2, 0) win32api.keybd_event(keys['shift'], 0, 2, 0)
) while True: data = connection.recv(5) if data: key1 = data.decode('utf-8') key = key1.replace("_", "") try: if key[0] == "p": if key[1:] != "0x5b": PressKeyPynput(eval(key[1:])) else: win32api.keybd_event(0x5b, 0, 0, 0) if key[0] == "r": if key[1:] != "0x5b": ReleaseKeyPynput(eval(key[1:])) else: win32api.keybd_event(0x5b, 0, win32con.KEYEVENTF_KEYUP, 0) if key == "ddddd": print("Debugging the keyboard...") for keyHEX, eta in keysPressed.items(): if eta == 1: ReleaseKeyPynput(eval(keyHEX)) print(f"{keyHEX} - Released.") print("Done.") elif key == "aaaaa":
"j": 0x4A, "k": 0x4B, "l": 0x4C, "m": 0x4D, "n": 0x4E, "o": 0x4F, "p": 0x50, "q": 0x51, "r": 0x52, "s": 0x53, "t": 0x54, "u": 0x55, "v": 0x56, "w": 0x57, "x": 0x58, "y": 0x59, "z": 0x5A } while True: letter = ser.read() #read the serial input from the configured port try: #try to convert var letter to ASCII letter.decode("ASCII") except UnicodeError: #if there is a error pass pass else: letter = letter.decode("ASCII") #if converting the input letter does work convert it letter.replace("\r", "") if letter != " " and letter != '\x08' and letter != '\x00': win32api.keybd_event(winKeyCodes[letter.lower()], 0,0,0)
def press(key): if key.isalpha(): key = key.lower() if key == '@': win32api.keybd_event(keys['shift'], 0, 0, 0) win32api.keybd_event(keys['2'], 0, 0, 0) win32api.keybd_event(keys['2'], 0, 2, 0) win32api.keybd_event(keys['shift'], 0, 2, 0) else: win32api.keybd_event(keys[key], 0, 0, 0) win32api.keybd_event(keys[key], 0, 2, 0)