Exemplo n.º 1
0
def stop_check():
    try:
        return win32api.GetAsyncKeyState(win32con.VK_F8)
    except:
        if is_stopped:
            global is_stopped
            is_stopped = False
            return True
        else:
            return False
Exemplo n.º 2
0
def clicker(settings):

    #loading settings
    start_first_key = give_vk_id(settings[0])
    start_second_key = give_vk_id(settings[1])
    end_first_key = give_vk_id(settings[2])
    end_second_key = give_vk_id(settings[3])
    speed = 1 / int(settings[4])
    mouse_click = settings[5]

    while True:
        #Check if start keys is pressed

        if win32api.GetAsyncKeyState(
                start_first_key) != 0 and win32api.GetAsyncKeyState(
                    start_second_key) != 0:

            while True:

                #Get the current position of the cursor
                (x, y) = win32api.GetCursorPos()

                #Click
                if mouse_click == "left":
                    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y,
                                         0, 0)
                    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0,
                                         0)
                else:
                    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, x, y,
                                         0, 0)
                    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, x, y, 0,
                                         0)

                #Wait sometime
                sleep(speed)

                #Check if end keys is pressed
                if win32api.GetAsyncKeyState(
                        end_first_key) != 0 and win32api.GetAsyncKeyState(
                            end_second_key) != 0:

                    break
Exemplo n.º 3
0
def detect(call, keys):
    keypress = 0
    for a in range(0, len(keys)):
        key = win32api.GetAsyncKeyState(VK_CODE[keys[a]])
        if key != 0:
            keypress += 1
        else:
            keypress == 0
    if keypress == len(keys):
        call()
    def onDismissal(self):
        """
        Called by the primary message window when the primary message
        has been dismissed.  Note that the PM may still be on the
        screen when this function is called (e.g., it may be doing its
        fade-out animation).
        """

        #logging.info( "Primary message dismissed." )
        if self.__primaryMessage is None:
            return

        oldMsg = self.__primaryMessage
        if oldMsg.isMini() and not oldMsg.isFinished():
            self.__newMiniMessage(oldMsg)
        self.__primaryMessage = None

        if self.__onDismissalFunc:
            # Run onDismissal function if CTRL key is used to dismiss the
            # message
            try:
                # TODO: Implement this on all platforms, currently it works only on Win32
                # Quite impossible to do in Linux (there is no API to access
                # keyboard physical state)
                import win32con  # @UnresolvedImport
                import win32api  # @UnresolvedImport

                # If CTRL key is being held
                if win32api.GetAsyncKeyState(
                        win32con.VK_CONTROL) << 1:  # @UndefinedVariable
                    # Wait for CTRL key release before executing the dismissal
                    # function
                    while win32api.GetAsyncKeyState(
                            win32con.VK_CONTROL) << 1:  # @UndefinedVariable
                        time.sleep(0.01)
                    try:
                        self.__onDismissalFunc()
                    except Exception as e:
                        logging.error(e)
            except:
                pass
            finally:
                self.__onDismissalFunc = None
Exemplo n.º 5
0
 def get_key_press(self):
     for i in range(0, 0xff):
         state = win32api.GetAsyncKeyState(i)
         if state & 0x0001:
             if i == 0x1:
                 self.mouse_clicks += 1
                 return time.time()
             elif i > 32 and i < 127:
                 self.keystrokes += 1
     return None
Exemplo n.º 6
0
 def overwatch(self):
     if self.preller == 0:
         if self.StatusOfApp == 0:
             wakeUpKey = {0x10: 'shift', 0x20: 'space'}
             for i in range(1, 256):
                 if win32api.GetAsyncKeyState(i):
                     if i in wakeUpKey:
                         self.startUp()
                         self.preller = 4
         if self.StatusOfApp == 1:
             shutDownKey = {0x10: 'shift', 0x20: 'space'}
             for i in range(1, 256):
                 if win32api.GetAsyncKeyState(i):
                     if i in shutDownKey:
                         self.hibernate()
                         self.preller = 4
             if self.getHandleOfThisWindow(
             ) != win32gui.GetForegroundWindow():
                 self.hibernate()
Exemplo n.º 7
0
    def drawImage(self):
        c_coords, xpad, ypad, pixel_size, delay = [
            getattr(self.settings, attr)
            for attr in ['c_coords', 'xpad', 'ypad', 'pixel_size', 'delay']
        ]
        # check if image exists
        if len(self.imgs) == 0:
            return
        img = self.imgs[self.imgNum]
        img_np = np.asarray(img)
        max_line_len = 8
        for i in range(1, 22, 1):
            colour_ar = img_np == i
            coord_ar = []
            count = 0
            prev_x = 0
            prev_y = 0
            buffer = []
            for index, x in np.ndenumerate(colour_ar):
                if x:
                    if index[1] == prev_x + 1 and index[0] == prev_y:
                        if count < max_line_len + 1:
                            count += 1
                    else:
                        count = 0
                    if count < max_line_len + 1 and index != (0, 0):
                        coord_ar.append(buffer)
                        buffer = []
                    if count == max_line_len:
                        buffer = [coord_ar[-max_line_len][0]]
                        coord_ar = coord_ar[:-max_line_len]
                    if count == max_line_len + 1:
                        buffer.pop()
                    buffer.append(index)
                    prev_x = index[1]
                    prev_y = index[0]

            win32api.SetCursorPos(list(c_coords.values())[i])
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
            for chunk in coord_ar:
                for i, coord in enumerate(chunk):
                    win32api.SetCursorPos((int(xpad + coord[1] * pixel_size),
                                           int(ypad + coord[0] * pixel_size)))
                    if coord[1] - chunk[0][1] > 0:
                        if i == len(chunk) - 1:
                            time.sleep(0.017)
                    if i == 0:
                        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0,
                                             0)
                        time.sleep(delay)
                    if i == len(chunk) - 1:
                        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
                if win32api.GetAsyncKeyState(win32con.VK_SHIFT):
                    return
Exemplo n.º 8
0
    def key_check(self):
        key_presssed = {}
        for key in self.keys:
            old_down = self.key_down[key] if key in self.key_down else False
            new_down = wapi.GetAsyncKeyState(ord(key))
            self.key_down[key] = new_down

            # key was just released
            key_presssed[key] = old_down and not new_down

        for q in range(10):
            if wapi.GetAsyncKeyState(ord(str(q))):
                quality = q * 10 if q > 0 else 5
                self.send_command('Q;{}'.format(quality))
                break

        if key_presssed['F']:
            self.send_command("F")

        if key_presssed['C']:
            self.send_command("A;C")
            self.control = True
        elif key_presssed['M']:
            self.send_command("A;M")
            self.control = False

        if self.control:
            if self.key_down['A']:
                self.steering += TURN_AMOUNT / (1.0 + np.abs(self.speed))
            if self.key_down['D']:
                self.steering -= TURN_AMOUNT / (1.0 + np.abs(self.speed))

            if self.key_down['S']:
                self.speed -= BRAKE_AMOUNT
            elif self.key_down['W']:
                self.speed += ACCELERATE_AMOUNT

            self.speed = np.clip(self.speed, -1.0, 1.0)
            self.steering = np.clip(self.steering, -1.0, 1.0)

            self.steering *= 0.995
            self.speed *= 0.995
Exemplo n.º 9
0
    def start_count(self):
        while True:
            main_window.update()
            if win32api.GetAsyncKeyState(self.START_KEY) != 0:
                self.START_FLAG = True
            if win32api.GetAsyncKeyState(self.STOP_KEY) != 0:
                self.START_FLAG = False
            if self.START_FLAG:
                main_window.update()
                self.curr_time_sec += 1
                time.sleep(1)
                if self.curr_time_sec >= 60:
                    self.curr_time_sec -= 60
                    self.curr_time_min += 1
                if self.curr_time_min >= 60:
                    self.curr_time_min -= 60
                    self.curr_time_hour += 1

                print(self.get_curr_time())
                self.time_label.config(text=self.get_curr_time())
Exemplo n.º 10
0
def clicker():
    global cps

    while True:
        while win32api.GetAsyncKeyState(
                win32con.VK_MENU) != 0 and win32api.GetAsyncKeyState(
                    90) != 0:  #alt+z
            (x, y) = win32api.GetCursorPos()
            win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0)
            win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, x, y, 0, 0)
            cps += 1
            time.sleep(getSpeed())
        while win32api.GetAsyncKeyState(
                win32con.VK_MENU) != 0 and win32api.GetAsyncKeyState(
                    88) != 0:  #alt+x
            (x, y) = win32api.GetCursorPos()
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
            cps += 1
            time.sleep(getSpeed())
Exemplo n.º 11
0
def key_check():

    keys = []

    for key in keyList:

        if wapi.GetAsyncKeyState(ord(key)):

            keys.append(key)

    return keys
Exemplo n.º 12
0
def spacebar():
    global direccion
    while (1):
        if win32api.GetAsyncKeyState(VK_CODE['spacebar']) < 0:
            if direccion == 0:
                direccion = 1
                print 'palante'
            else:
                direccion = 0
                print 'patras'
            time.sleep(0.5)
Exemplo n.º 13
0
def main():
    wave_duration = 500
    time_per_frame = 25
    colors = get_available_keys()
    if not colors:
        return

    print(
        "Working... Use \"KP_PLUS\" or \"KP_MINUS\" to increase or decrease speed.\nPress Escape to close program"
    )
    while not win32api.GetAsyncKeyState(win32con.VK_ESCAPE):
        perform_pulse_effect(colors, wave_duration, time_per_frame)
        if win32api.GetAsyncKeyState(win32con.VK_ADD) and wave_duration > 100:
            wave_duration -= 100
            print(wave_duration)
        if win32api.GetAsyncKeyState(
                win32con.VK_SUBTRACT) and wave_duration < 2000:
            wave_duration += 100
            print(wave_duration)
        time.sleep(0.025)
Exemplo n.º 14
0
def initializeBoard(gameboard):
    sct.get_pixels(SNAPSHOT_AREA)
    image = Image.frombytes('RGB', (sct.width, sct.height), sct.image)
    image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)
    for r in range(ROWS):
        for c in range(COLS):
            colorVal = getCandyColor(r+1, c+1, image)
            colorName = categorizeColor(colorVal)
            gameboard[r][c] = colorName
    if win32api.GetAsyncKeyState(ord('D')) < 0:
        debug(gameboard, image)
Exemplo n.º 15
0
def mouse_clicks_to_output():
    """
	Return a 1 when a mouse click is detected, else return a 0
	"""
    # Mouse left click is 0x01
    # [0x01]
    output = 0  # default output is not-clicked

    if wapi.GetAsyncKeyState(0x01):
        output = 1

    return output
Exemplo n.º 16
0
def mouse_listener():
    mouse = {0x01: 'leftClick', 0x02: 'rightClick'}
    while True:
        for i in range(1, 256):
            if win32api.GetAsyncKeyState(i):
                if i in mouse:
                    print(mouse[i])
                    print(time.time())
                    print(pyautogui.position())
                else:
                    print(chr(i))
        time.sleep(.01)
Exemplo n.º 17
0
    def make_keymask_match(self,
                           modifier_list,
                           ignored_modifier_keycode=None,
                           ignored_modifier_keynames=None):
        log("make_keymask_match%s", (modifier_list, ignored_modifier_keycode,
                                     ignored_modifier_keynames))
        log(
            "keys pressed=%s", ",".join(
                str(VK_NAMES.get(i, i)) for i in range(256)
                if win32api.GetAsyncKeyState(i) > 0))
        current = set(self.get_current_mask())
        wanted = set(modifier_list or [])
        log("make_keymask_match: current mask=%s, wanted=%s, ignoring=%s/%s",
            current, wanted, ignored_modifier_keycode,
            ignored_modifier_keynames)
        if current == wanted:
            return

        def is_ignored(modifier):
            if not ignored_modifier_keynames:
                return False
            for keyname in ignored_modifier_keynames:  #ie: ["Control_R"]
                keycode = KEYCODES.get(
                    keyname)  #ie: "Control_R" -> VK_RCONTROL
                if keycode > 0:
                    key_mod = MOD_KEYS.get(keycode)  #ie: "control"
                    if key_mod == modifier:
                        return True
            return False  #not found

        def change_mask(modifiers, press, info):
            for modifier in modifiers:
                if is_ignored(modifier):
                    log("change_mask: ignoring %s", modifier)
                    continue
                #find the keycode:
                for k, v in MOD_KEYS.items():
                    if ignored_modifier_keycode and ignored_modifier_keycode == k:
                        log("change_mask: ignoring %s / %s",
                            VK_NAMES.get(k, k), v)
                        continue
                    if v == modifier:
                        #figure out if this is the one that needs toggling:
                        is_pressed = win32api.GetAsyncKeyState(k)
                        log("make_keymask_match: %s pressed=%s", k, is_pressed)
                        if bool(is_pressed) != press:
                            log("make_keymask_match: using %s to %s %s",
                                VK_NAMES.get(k, k), info, modifier)
                            fake_key(k, press)
                            break

        change_mask(current.difference(wanted), False, "remove")
        change_mask(wanted.difference(current), True, "add")
Exemplo n.º 18
0
Arquivo: VPP.py Projeto: REDxEYE/VPP
 def ActuallPlay(self, notes):
     if 'list' not in str(type(notes)):
         sheet = []
         sheetN = notes.split('\n')
         for s in itertools.chain(sheetN):
             ss = s.split(' ')
             for a in ss:
                 sheet.append(a)
         while '' in sheet:
             sheet.remove('')
         for note in sheet:
             note = note.split(':')
             if win32api.GetAsyncKeyState(win32con.VK_INSERT) != 0:
                 break
             KB.Press(note[0], note[1], self.SpeedMult.get())
     else:
         for note in notes:
             note = note.split(':')
             if win32api.GetAsyncKeyState(win32con.VK_INSERT) != 0:
                 break
             KB.Press(note[0], note[1], self.SpeedMult.get())
Exemplo n.º 19
0
def info():
    print("Press 'q' to quit")
    while (True):
        if win32api.GetAsyncKeyState(ord('Q')):
            print("exited")
            sys.exit()

        p = win32api.GetCursorPos()
        col = windll.gdi32.GetPixel(dc, p[0], p[1])
        print("x:%d y:%d col:%02X%02X%02X" % (p[0], p[1], (col >> 16) & 0xff,
                                              (col >> 8) & 0xff, (col) & 0xff))
        time.sleep(0.001)
Exemplo n.º 20
0
def main(file_name, starting_value):
    file_name = file_name
    starting_value = starting_value
    training_data = []

    for i in list(range(1))[::-1]:
        print(i + 1)
        time.sleep(1)

    last_time = time.time()
    paused = False
    print('STARTING!!!')
    while (True):
        if not paused:
            screen = grab_screen(region=(65, 320, 450 + 65, 160 + 320))

            # resize to something a bit more acceptable for a CNN
            screen = cv2.resize(screen, (width, height))

            # run a color convert
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)

            #set threshold for clean image
            ret, screen = cv2.threshold(screen, 127, 255,
                                        cv2.THRESH_BINARY_INV)

            output = keys_to_output()
            training_data.append([screen, output])

            cv2.imshow('window', cv2.resize(screen, (width, height)))
            if cv2.waitKey(25) & 0xFF == ord('q'):
                cv2.destroyAllWindows()
                break

            if len(training_data) % 100 == 0:
                print(len(training_data))

                if len(training_data) == 1000:
                    np.save(file_name, training_data)
                    print('SAVED')
                    training_data = []
                    starting_value += 1
                    file_name = 'training_data-{}.npy'.format(starting_value)

        if wapi.GetAsyncKeyState(0x54):
            if paused:
                paused = False
                print('unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                time.sleep(1)
Exemplo n.º 21
0
def key_check():
    """
    Method to get pressed keys by user.
    Author: https://github.com/Box-Of-Hats
    :return: pressed keys list
    """
    keys = []
    key_list = ["\b"] + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ 123456789,.'£$/\\")
    for key in key_list:
        if win32api.GetAsyncKeyState(ord(key)):
            keys.append(key)
    return keys
def getKey():
    """获取按键

    Returns:
        list -- 按键列表
    """

    keys = []
    for key in key_list:
        if win32api.GetAsyncKeyState(ord(key)):
            keys.append(key)
    return keys
Exemplo n.º 23
0
def get_key_pressed():
    #Since for pong we can only go up and down, these are the only keys we will verify
    #Code for upkey is 38 and for down is 40

    up_pressed = wapi.GetAsyncKeyState(38)
    down_pressed = wapi.GetAsyncKeyState(40)
    exit_pressed = wapi.GetAsyncKeyState(ord("Q"))

    #if exit was pressed, return -1
    if exit_pressed:
        return -1

    #if the both keys are not pressed, or both pressed, return 0
    if down_pressed == up_pressed:
        return 0

    if up_pressed:
        return 1

    if down_pressed:
        return 2
Exemplo n.º 24
0
def kb_clear_all():  #reset keys
    win32api.GetAsyncKeyState(repeat_key)
    win32api.GetAsyncKeyState(ctrl_key)
    win32api.GetAsyncKeyState(win32con.VK_ESCAPE)
    win32api.GetAsyncKeyState(ord('A'))
    win32api.GetAsyncKeyState(ord('B'))
    win32api.GetAsyncKeyState(ord('C'))
Exemplo n.º 25
0
def AllStatus(st):
    global triggerBotEnabled
    global autoBHOPEnabled
    global glowESPEnabled
    global soundESPEnabled
    global rcsEnabled
    global noFlashEnabled

    while True:
        if win32api.GetAsyncKeyState(0x74):
            glowESPEnabled = not glowESPEnabled
            changeStat(st)
            time.sleep(1)
        if win32api.GetAsyncKeyState(0x75):
            rcsEnabled = not rcsEnabled
            changeStat(st)
            time.sleep(1)
        if win32api.GetAsyncKeyState(0x76):
            soundESPEnabled = not soundESPEnabled
            changeStat(st)
            time.sleep(1)
        if win32api.GetAsyncKeyState(0x77):
            triggerBotEnabled = not triggerBotEnabled
            changeStat(st)
            time.sleep(1)
        if win32api.GetAsyncKeyState(0x78):
            autoBHOPEnabled = not autoBHOPEnabled
            changeStat(st)
            time.sleep(1)
        if win32api.GetAsyncKeyState(0x79):
            noFlashEnabled = not noFlashEnabled
            changeStat(st)
            time.sleep(1)
Exemplo n.º 26
0
def main():
    last_time = time.time()

    # 'movement' = 'roam', 'sound', or 'none'
    # 'game_mode' = 'defuse' or 'deathmatch'
    logic_dict = {
        'aim_roi': aim_roi,
        'movement': 'sound',
        'game_mode': 'deathmatch'
    }
    logic_thread = threading.Thread(target=logic.play, args=(logic_dict, None))
    logic_thread.daemon = True
    logic_thread.start()

    tesser_dict = {'input': {}, 'output': {}}
    tesser_thread = threading.Thread(target=tesser.image_to_text,
                                     kwargs=tesser_dict)
    tesser_thread.daemon = True
    tesser_thread.start()

    detector.setup()

    while True:
        print('Main thread FPS: {}'.format(1 / (time.time() - last_time)))
        last_time = time.time()

        window = win32gui.GetForegroundWindow()
        if win32gui.GetWindowText(
                window) != 'Counter-Strike: Global Offensive':
            logic.set_pause(True)

        frame = np.asarray(
            screenshot.grab(window_name='Counter-Strike: Global Offensive'))

        for key in tesser_rois.keys():
            tesser_dict['input'][key] = (crop(frame, tesser_rois[key][0]),
                                         tesser_rois[key][1])

        for key in tesser_dict['output'].keys():
            logic_dict[key] = tesser_dict['output'][key][0]

        image, detection_data = detector.detect(crop(frame, aim_roi))

        logic_dict['shape'] = image.shape
        logic_dict.update(detection_data)

        cv2.imshow('BOT Fritz', image)

        # END key to quit
        if cv2.waitKey(1) & win32api.GetAsyncKeyState(0x23):
            cv2.destroyAllWindows()
            break
Exemplo n.º 27
0
def main(weapon_filename):
    running = True
    no_recoil = False
    weapons_list, current_weapon_index = load_weapons(weapon_filename)
    overlay = OverlayLabel()
    overlay.set_size(20, 2)  # size in symbols
    print("INFO: Starting WeaponDetector daemon...")
    weapon_detector = WeaponDetectorThread(weapons_list)
    weapon_detector.setDaemon(True)
    weapon_detector.start()
    print("INFO: Everything looks ok, so I'm going to my general routine ;)")

    while running:
        if weapon_detector.out is not None:
            current_weapon_index = weapon_detector.out
        construct_overlay(overlay, weapons_list, current_weapon_index,
                          no_recoil)
        if win32api.GetAsyncKeyState(F4):
            no_recoil = toggle_recoil(no_recoil)
            weapon_detector.no_recoil = no_recoil
            time.sleep(0.2)
        if win32api.GetAsyncKeyState(F10):
            running = not running
            beep_exit()
            weapon_detector.terminate()
            print("INFO: Exiting!")
            time.sleep(0.5)
        if win32api.GetAsyncKeyState(NUM_4):
            current_weapon_index = prev_weapon(weapons_list,
                                               current_weapon_index)
            time.sleep(0.2)
        if win32api.GetAsyncKeyState(NUM_6):
            current_weapon_index = next_weapon(weapons_list,
                                               current_weapon_index)
            time.sleep(0.2)
        if is_lmb_pressed() and no_recoil and not cursor_detector():
            process_no_recoil(overlay, weapons_list, current_weapon_index,
                              no_recoil)
        time.sleep(0.01)
Exemplo n.º 28
0
 def get_key_press(self):
     # from 0 to binary 11111111
     for i in range(0, 0xff):
         state = win32api.GetAsyncKeyState(i)
         # 0x0001 = 16-bit value
         if state & 0x0001:
             # 0x1 represents a virtual left-click of a mouse.
             if i == 0x1:
                 self.mouse_clicks += 1
                 return time.time()
             elif i > 32 and i < 127:
                 self.keystrokes += 1
     return None
Exemplo n.º 29
0
def followPath(path, callback):
    global pos
    getNextPos(path)
    while not win32api.GetAsyncKeyState(0x1B):
        adjustVector()
        sleep(.1)
        if (closeto(now, go)):
            pos += 1
            if (pos >= len(path)):
                pos = 0  #and check if full
                callback()
            todo(go)
            getNextPos(path)
Exemplo n.º 30
0
 def process(self, screenshot):
   debug = CBotDebugState(screenshot, self.logger)
   
   if (win32api.GetAsyncKeyState(ord('A')) & 1) == 1:
     self.saveScreenshot(screenshot)
   
   if BotState.IDLE == self.state:
     return self._onIdle(screenshot, debug)
   
   if BotState.MOVING == self.state:
     return self._onMoving(screenshot, debug)
     
   return ([], debug)