def run(self): while self.__running.isSet(): self.__flag.wait() # checks if the '+' button and 'numpad 8' were pressed if GetAsyncKeyState(VK_NUMPAD8) and GetAsyncKeyState(VK_ADD): while GetKeyState(VK_NUMPAD8): pass # wait until Numpad 8 is released press_key(NP_8) press_key(W_KEY) # checks if the 'right shift' button and '+' were pressed elif GetAsyncKeyState(VK_RSHIFT) and GetAsyncKeyState(VK_ADD): while GetKeyState(VK_RSHIFT): pass # wait until Right Shift is released press_key(W_KEY) press_key(SHIFT_KEY) # checks if the '+' button was pressed elif GetAsyncKeyState(VK_ADD): press_key(W_KEY) # checks if the 'right ctrl' button is pressed and releases 'shift', 'w' and 'numpad 8' if GetAsyncKeyState(VK_RCONTROL): release_key(SHIFT_KEY) release_key(W_KEY) release_key(NP_8) sleep(0.2)
def stop_0(self, ch='p', continue_key='p', pre_alt=True): # ch = 'a' break0 = 0 ch = ch.upper() from win32api import GetKeyState from win32gui import MessageBox VK_Alt = 18 # alt键的虚拟键盘码 nVirtKey = GetKeyState(ord(ch)) # 默认按键的状态 if (nVirtKey == -127 or nVirtKey == -128): if (pre_alt): # 若要求按下alt state_vk_alt = GetKeyState(VK_Alt) if (state_vk_alt == -127 or state_vk_alt == -128): print('------- Stop! --------') break0 = not (MessageBox(0, 'Do you break?', 'Stop!', 1) - 1) # 询问是否退出 else: #不要求按下alt键 break0 = not (MessageBox(0, 'Do you break?', 'Stop!', 1) - 1 ) # 询问是否退出 if (break0): print('------ Break!!! --------') return break0 else: return break0 else: return 0
def get_restart_key(self, timer_thread): restarted = False if GetKeyState(0x11) < 0 and GetKeyState(0x52) < 0 and not restarted: restarted = True timer_thread.restart() else: restarted = False
def get_end_key(self, timer_thread): ended = False if GetKeyState(0x11) < 0 and GetKeyState(0x45) < 0 and not ended: ended = True timer_thread.stop() else: ended = False
def get_start_key(self, timer_thread): started = False if GetKeyState(0x11) < 0 and GetKeyState(0x53) < 0 and not started: started = True timer_thread.start() else: started = False
def main(args): global testJsonPath global outputPath if args.pydev: print("Enabling debugging with pydev") import pydevd pydevd.settrace(suspend=False) inputPath = args.inputJsonPath recursive = args.recursive fileFilter = args.filter print("Input path: {}\n\n".format(inputPath)) # Initialize the Vam window vamWindow = VamWindow(pipe="foto2vamPipe") angles = [0, 35] skipCnt = 0 screenshots = deque(maxlen=2) for root, subdirs, files in os.walk(inputPath): print("Entering directory {}".format(root)) for file in fnmatch.filter(files, fileFilter): try: anglesToProcess = [] + angles for angle in angles: fileName = "{}_{}.png".format(file, angle) fileName = os.path.join(root, fileName) if os.path.exists(fileName) or os.path.exists( "{}.failed".format(fileName)): anglesToProcess.remove(angle) if len(anglesToProcess) == 0: skipCnt += 1 #print("Nothing to do for {}".format(file)) continue print("Processing {} (after skipping {})".format( file, skipCnt)) skipCnt = 0 if (GetKeyState(VK_CAPITAL) or GetKeyState(VK_SCROLL)): print( "WARNING: Suspending script due to Caps Lock or Scroll Lock being on. Push CTRL+PAUSE/BREAK or mash CTRL+C to exit script." ) while GetKeyState(VK_CAPITAL) or GetKeyState(VK_SCROLL): time.sleep(1) # Get screenshots of face and submit them to worker threads inputFile = os.path.join(os.path.abspath(root), file) vamWindow.loadLook(inputFile, anglesToProcess) continue except Exception as e: print("Failed to process {} - {}".format(file, str(e))) if not recursive: break print("Generator done!")
def check_locks(): from win32api import GetKeyState from win32con import VK_CAPITAL, VK_NUMLOCK if GetKeyState(VK_CAPITAL) == 1: pyautogui.press('capslock') print("Capslock turned off") if GetKeyState(VK_NUMLOCK) == 1: pyautogui.press('numlock') print("Numlock turned off")
def get_key_state(self, ch='p'): from win32api import GetKeyState try: ch = ch.upper() nVirtKey = GetKeyState(ord(ch)) except: nVirtKey = GetKeyState(ch) if (nVirtKey == -127 or nVirtKey == -128): return 1 else: return 0
def OnOff(): estadoBloqMayus = GetKeyState(VK_CAPITAL) if estadoBloqMayus == 0: label.configure(image=imagen_off) elif estadoBloqMayus == 1: label.configure(image=imagen_on) root.after(1, OnOff)
def stop_alt(self, ch='s'): try: ch = ch.upper() except: pass VK_Alt = 18 # alt键的虚拟键盘码 from win32api import GetKeyState nVirtKey = GetKeyState(ord(ch)) if (nVirtKey == -127 or nVirtKey == -128): # 按下 state_vk_alt = GetKeyState(VK_Alt) if (state_vk_alt == -127 or state_vk_alt == -128): return 1 else: return 0
def morphs_to_image_proc(config, inputQueue, outputQueue, tmpDir, doneEvent, exitEvent, pydev): if pydev: import pydevd pydevd.settrace(suspend=False) from Utils.Vam.window import VamWindow from Utils.Face.vam import VamFace # Initialize the Vam window vamWindow = VamWindow(pipe="foto2vamPipe") vamFace = config.getBaseFace() inputCnt = config.getShape()[0] while not doneEvent.is_set(): try: while GetKeyState(VK_CAPITAL): time.sleep(1) params = inputQueue.get(block=True, timeout=1) morphs = params[inputCnt:] vamFace.importFloatList(morphs) tmpdir = tempfile.mkdtemp(dir=tmpDir) jsonFile = os.path.join(tmpdir, "face.json") vamFace.save(jsonFile) vamWindow.loadLook(jsonFile, config.getAngles()) vamWindow.syncPipe(vamWindow._pipe) outputQueue.put(tmpdir) except queue.Empty: pass except Exception as e: print("Error in morphs_to_image_proc: {}".format(str(e))) exitEvent.set()
def solve_auto(self): """ Solves rune if present and sends key presses. :return: -1 if rune not detected, result of classify() if successful """ img = self.capture_roi() processed_imgs = self.preprocess(img) if len(processed_imgs) != 4: self.logger.debug("Failed to extract 4 ROI from processed image") return -1 #cv2.imwrite("roi.png", img) tensor = self.images2tensor(processed_imgs) result = self.classify(tensor) if GetKeyState(VK_NUMLOCK): self.key_mgr.single_press(DIK_NUMLOCK) time.sleep(0.2) self.logger.debug("Solved rune with solution %s" % (str(result))) for inp in result: if inp == "up": self.key_mgr.single_press(DIK_UP) elif inp == "down": self.key_mgr.single_press(DIK_DOWN) elif inp == "left": self.key_mgr.single_press(DIK_LEFT) elif inp == "right": self.key_mgr.single_press(DIK_RIGHT) time.sleep(0.1) return len(processed_imgs)
def get_key_state(self, ch='p'): ch = vk.conv_ord(ch) nVirtKey = GetKeyState(ch) if (nVirtKey == -127 or nVirtKey == -128): return 1 else: return 0
def autoAgendamento_Clicked(self): flagEvent.set() if GetKeyState(VK_CAPITAL): pyautogui.press('capslock') x = threading.Thread(target=AutoAgendamento, args=(flagEvent, ), daemon=True) x.start()
def evaluate_get_face_images(self, individual): # Give the user a chance to interrupt the process before we hijack the mouse if (GetKeyState(VK_CAPITAL) or GetKeyState(VK_SCROLL)): print("WARNING: Suspending script due to Caps Lock or Scroll Lock being on. Push CTRL+PAUSE/BREAK or mash CTRL+C to exit script.") while GetKeyState(VK_CAPITAL) or GetKeyState(VK_SCROLL): time.sleep(1) face_images = {} self.protoFace.importFloatList(individual) for angle,_ in self.targetFaces.items(): self.protoFace.setRotation( angle ) self.protoFace.save( self.jsonPath ) self.vamWindow.loadLook() # Delay to allow time for the preset to load time.sleep(.3) face_images[angle] = self.vamWindow.getScreenShot() return face_images
def main(): FormatTXT() if GetKeyState(VK_CAPITAL): pyautogui.press('capslock') ShowMainWindow()
def capture_key(e): if e.name == "caps lock": if (GetKeyState(VK_CAPITAL) & 0x0001) != 0: e1.delete(0, END) e1.insert(END, "On") else: e1.delete(0, END) e1.insert(END, 'Off')
def caps_lock_stuck(text): if GetKeyState(VK_CAPITAL) == 1: keyboard.press(Key.caps_lock) for i in text: if i in this: keyboard.type(i) else: keyboard.press(Key.caps_lock) keyboard.release(Key.caps_lock)
def GET_KEY_STATE(self, set_enable): from win32api import GetKeyState from win32con import VK_NUMLOCK, VK_CAPITAL """ :param str key: numlock / capslock :param bool set_enable: True -> enabled, False -> Disabled :return: desliga ou liga capslock/numlock """ numlock = GetKeyState(VK_NUMLOCK) capslock = GetKeyState(VK_CAPITAL) if set_enable: if numlock == 0 or capslock == 0: pygui.hotkey('numlock') pygui.hotkey('capslock') else: if numlock == 1 or capslock == 1: pygui.hotkey('numlock') pygui.hotkey('capslock')
def execute(self, time_range): """ :param time_range: time_range in seconds :type time_range: int :return right_clicks, left_clicks: count of clicks :type return: tuple of int """ clicks = 0 state_left = GetKeyState(LEFT_MOUSE_ID) timer_end = time() + time_range while time() < timer_end: if GetKeyState(LEFT_MOUSE_ID) != state_left: if state_left < 0: clicks += 1 state_left = GetKeyState(LEFT_MOUSE_ID) self.result = clicks return self.result
def autoConfirma_Clicked(self): flagEvent.set() if GetKeyState(VK_CAPITAL): pyautogui.press('capslock') qtdeViag = self.builder.tkvariables.__getitem__('qtdeViag').get() codViag = self.builder.tkvariables.__getitem__('codViag').get() x = threading.Thread(target=Confirmar, args=(qtdeViag, codViag, flagEvent), daemon=True) x.start()
def on_release(key): global capson global shiftpressed global controlpressed global altpressed capson = GetKeyState(VK_CAPITAL) shiftpressed = (GetKeyState(VK_LSHIFT) + GetKeyState(VK_RSHIFT)) / 2 controlpressed = (GetKeyState(VK_LCONTROL) + GetKeyState(VK_RCONTROL)) / 2 altpressed = (GetKeyState(VK_LMENU) + GetKeyState(VK_RMENU)) / 2
def consignee_and_shipper(driver): while not GetKeyState(13) < 0: if "Total Cargo Weight:" in driver.page_source: return # if not GetKeyState(17)<0: # sleep(3) # if GetKeyState(17)<0: # while not GetKeyState(13)<0: # if "Total Cargo Weight:" in driver.page_source: # return press("tab") elem = driver.find_element_by_id("consigneeName") while elem.id != driver.switch_to.active_element.id: try: elem.click() except: pass driver.execute_script("window.scrollTo(0, 1080)") while not GetKeyState(13) < 0: if "Total Cargo Weight:" in driver.page_source: return # if not GetKeyState(17)<0: # sleep(3) # if GetKeyState(17)<0: # while not GetKeyState(13)<0: # if "Total Cargo Weight:" in driver.page_source: # return press("tab") while not "Total Cargo Weight:" in driver.page_source: clicked = False while not clicked: try: driver.find_element_by_id( "cargoCargoDetailsTabBottom").click() clicked = True except: pass
def keyboard_get_toggles(): if sys.platform == "win32": from win32api import GetKeyState # from pywin32, which we have because PyUserInput depends on it from win32con import VK_CAPITAL, VK_NUMLOCK, VK_SCROLL # from pywin32, which we have because PyUserInput depends on it return { "CapsLock": GetKeyState(VK_CAPITAL) != 0, "NumLock": GetKeyState(VK_NUMLOCK) != 0, "ScrollLock": GetKeyState(VK_SCROLL) != 0, } xset_path = shutil.which("xset") if xset_path: response = subprocess.check_output([xset_path, "q"]).decode("utf-8") result = re.search(r"LED\s+mask:\s+(\d+)", response) if not result: raise ValueError("Could not obtain toggle states from X") toggles = int(result.group(1)) return { "CapsLock": (toggles & 0b1) != 0, "NumLock": (toggles & 0b10) != 0, "ScrollLock": (toggles & 0b100) != 0, } raise ValueError("Could not find X settings controller")
def autoEncerrarEntrega_Clicked(self): flagEvent.set() if GetKeyState(VK_CAPITAL): pyautogui.press('capslock') viagREPOM = self.builder.tkvariables.__getitem__('viagREPOM').get() x = threading.Thread(target=EncerrarKlabin, args=( int(viagREPOM), flagEvent, ), daemon=True) x.start()
def stop(self, ch='p'): ch = ch.upper() from win32api import GetKeyState nVirtKey = GetKeyState(ord(ch)) if (nVirtKey == -127 or nVirtKey == -128): #按下 self.break_flag = 1 return 1 else: self.break_flag = 0 return 0
def autoCalcular_Clicked(self): flagEvent.set() if GetKeyState(VK_CAPITAL): pyautogui.press('capslock') viag = self.builder.tkvariables.__getitem__('viag').get() x = threading.Thread(target=Calcular, args=( int(viag), flagEvent, ), daemon=True) x.start()
def on_press(key): global delay_ok_t1_PASSWORD_LISTNER global t1_PASSWORD_LISTNER global auth global shiftpressed global controlpressed global altpressed global Notification_Timer_on global Notification_Timer_on_Lock shiftpressed = (GetKeyState(VK_LSHIFT) + GetKeyState(VK_RSHIFT)) / 2 controlpressed = (GetKeyState(VK_LCONTROL) + GetKeyState(VK_RCONTROL)) / 2 altpressed = (GetKeyState(VK_LMENU) + GetKeyState(VK_RMENU)) / 2 if delay_ok_t1_PASSWORD_LISTNER == "1": t1_PASSWORD_LISTNER.cancel() if len(str(key)) == 3: auth += str(key)[1] if auth == "12345" and Notification_Timer_on: t2_SENDING_NOTIFICATION.cancel() Notification_Timer_on = False winsound.Beep(300, 100) winsound.Beep(300, 100) Terminate() start_delay_t1_PASSWORD_LISTNER() elif len(str(key)) > 3 and str(key)[:3] == "Key": pressedkey = (str(key))[4:len(str(key))] if pressedkey == "space": auth += " " start_delay_t1_PASSWORD_LISTNER() elif pressedkey == "enter": auth = ""
def MainUpdate(): global Pressed, state_left, root global anchorx, anchory, posx, posy global xsu, ysu, xa, ya, xs, ys a = GetKeyState(0x01) if a != state_left: state_left = a if a < 0: Pressed = True anchorx = mouse.position[0] anchory = mouse.position[1] root.attributes("-fullscreen", False) else: if xa == xs or ya == ys: return Pressed = False root.destroy() print("Saving: " + str(xa), str(ya), str(xs), str(ys)) im = ImageGrab.grab(bbox=(xa, ya, xs, ys)) # Makes screenshot now = datetime.now().strftime( "%Y-%m-%d %H_%M_%S") # Makes date thingy newfile = dirname + str(now) + ".png" # Possible check if file already exists but I'm to lazy im.save(newfile) # Saves screenshot print("Image Saved to: " + dirname) startfile(newfile) # Opens file for user return if Pressed == True: posx = mouse.position[0] posy = mouse.position[1] if anchorx > posx: xa = posx xs = anchorx else: xa = anchorx xs = posx if anchory > posy: ya = posy ys = anchory else: ya = anchory ys = posy xsu = xs - xa ysu = ys - ya root.geometry( str(xsu) + "x" + str(ysu) + "+" + str(xa) + "+" + str(ya)) root.after(1, MainUpdate)
def capture_key(e): if e.name == "caps lock": if (GetKeyState(VK_CAPITAL) & 0x0001) != 0: toaster.show_toast("Caps lock On", " ", threaded=True, icon_path='C:\\win.ico', duration=1) else: toaster.show_toast("Caps lock Off", " ", threaded=True, icon_path='C:\\win.ico', duration=1)