Пример #1
0
 def test_block_key(self):
     blocked = keyboard.block_key('a')
     self.do(d_a + d_b, d_b)
     self.do([make_event(KEY_DOWN, 'A', -1)],
             [make_event(KEY_DOWN, 'A', -1)])
     keyboard.unblock_key(blocked)
     self.do(d_a + d_b, d_a + d_b)
def enable():
    global winBlocked
    if winBlocked == True:
        winBlocked = False
        keyboard.unblock_key('win')
        disable.configure(state=ACTIVE)
        enable.configure(state=DISABLED)
        dLabel.configure(text='Current Status: ENABLED')
    else:
        disable.configure(state=ACTIVE)
        enable.configure(state=DISABLED)
Пример #3
0
def check_pause():
    global _insert_mode, _insert_mode_temp
    if not keyboard.is_pressed(
            Key['ExitInsertMode']) and _insert_mode != _insert_mode_temp:
        _insert_mode_temp = _insert_mode
        if _insert_mode:
            keyboard.block_key(Key['ExitInsertMode'])
            for name in Key:
                if name != 'ExitInsertMode':
                    keyboard.unblock_key(Key[name])
            play_buffer = enter_sound.play()
        else:
            keyboard.unblock_key(Key['ExitInsertMode'])
            for name in Key:
                if name != 'ExitInsertMode':
                    keyboard.block_key(Key[name])
            play_buffer = exit_sound.play()
def thread_scheduler():
    '''
    Thread for constant running the two functions 
    '''
    t_end = time.time() + 60
    keyboard.block_key('print screen')

    while time.time() < t_end:
        screen_sharing_thread = threading.Thread(target=screen_sharing)
        multiple_people_thread = threading.Thread(target=multiple_people)

        screen_sharing_thread.start()
        multiple_people_thread.start()

        screen_sharing_thread.join()
        multiple_people_thread.join()

    keyboard.unblock_key('print screen')
Пример #5
0
def take_pic():
    if "diep.io" in get_foreground_window_title():
        [keyboard.block_key(k) for k in block_keys]
        keyboard.press("l")
        time.sleep(.1)
        keyboard.press_and_release("alt+prtscn")
        time.sleep(.05)
        keyboard.release("l")
        [keyboard.unblock_key(k) for k in block_keys]
        time.sleep(.1)
        img = ImageGrab.grabclipboard()
        time.sleep(.1)
        img2 = img.crop((3 * img.width // 7, 13 * img.height // 14,
                         4 * img.width // 7, img.height))
        for x in range(img2.width):
            for y in range(img2.height):
                p = img2.getpixel((x, y))
                img2.putpixel(
                    (x, y), (0, 0, 0) if all(map(lambda c: c > 185, p))
                    and not all(map(lambda c: 207 > c > 195, p))
                    and p not in [(198, 198, 198), (205, 205, 205),
                                  (202, 202, 202)] else (0xff, 0xff, 0xff))
        img2.save("testimg.png", "PNG")
        time.sleep(.1)
        prc = subprocess.run("Tesseract-OCR\\tesseract.exe testimg.png stdout",
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        text = prc.stdout.strip().split(b"\r\n")
        _score, _class = None, None
        for l in text:
            if b"Score" in l.strip():
                _score = int(l.strip().split()[1].decode().replace(
                    ",", "").replace(".", ""))
            elif l.strip().startswith(b"Lvl "):
                _class = l.strip().split()[2].decode()
        if _score is not None and _class is not None:
            print(_class, "with", _score)
            if _class in high_scores:
                if _score > high_scores[_class][0]:
                    if high_scores[_class][1] in os.listdir("highscores"):
                        os.remove("highscores\\" + high_scores[_class][1])
                else:
                    return
            filename = _class + "-" + str(_score) + "-" + datetime.now(
            ).strftime("%m~%d~%Y-%H~%M") + ".png"
            high_scores[_class] = (_score, filename)
            img.save("highscores\\" + filename, "PNG")
            with open("highscores.json", "w") as high_scores_json_file:
                json.dump(high_scores, high_scores_json_file)
        else:
            print(text)
            take_pic()  # Fixme: maybe not a good idea...
Пример #6
0
def read_tablet(args, remote_device):
    """Loop forever and map evdev events to mouse"""

    import keyboard
          
    from pynput.mouse import Button, Controller

    lifted = True
    Rlifted = True
    Mlifted = True

    new_x = new_y = False

    mouse = Controller()

    monitor = get_monitors()[args.monitor]
    log.debug('Chose monitor: {}'.format(monitor))

    while True:
        _, _, e_type, e_code, e_value = struct.unpack('2IHHi', remote_device.read(16))

        if keyboard.is_pressed('alt+1'):
            monitor = get_monitors()[0]

        elif keyboard.is_pressed('alt+2'):
            monitor = get_monitors()[1]

        elif keyboard.is_pressed('alt+3'):
            monitor = get_monitors()[2]

        elif e_type == e_type_abs:

            # handle x direction
            if e_code == e_code_stylus_xpos:
                log.debug(e_value)
                x = e_value
                new_x = True

            # handle y direction
            if e_code == e_code_stylus_ypos:
                log.debug('\t{}'.format(e_value))
                y = e_value
                new_y = True

            # handle draw & modifiers
            if e_code == e_code_stylus_pressure:
                log.debug('\t\t{}'.format(e_value))
                if e_value > args.threshold:
                    if lifted and keyboard.is_pressed('ctrl') :
                        lifted = False
                        Rlifted = False
                        keyboard.block_key('ctrl')
                        keyboard.release('ctrl')
                        mouse.press(Button.right)
                    if lifted and keyboard.is_pressed('shift') :
                        lifted = False
                        Mlifted = False
                        keyboard.block_key('shift')
                        keyboard.release('shift')
                        mouse.press(Button.middle)
                    elif lifted:
                        log.debug('PRESS')
                        lifted = False
                        mouse.press(Button.left)
                else:
                    if not lifted and not Rlifted :
                        lifted = True
                        Rlifted = True
                        mouse.release(Button.right)
                        keyboard.unblock_key('ctrl')
                    if not lifted and not Mlifted :
                        lifted = True
                        Mlifted = True
                        mouse.release(Button.middle)
                        keyboard.unblock_key('shift')
                    elif not lifted :
                        log.debug('RELEASE')
                        lifted = True
                        mouse.release(Button.left)


            # only move when x and y are updated for smoother mouse
            if new_x and new_y:
                mapped_x, mapped_y = remap(
                    x, y,
                    wacom_width, wacom_height,
                    monitor.width, monitor.height,
                    args.mode, args.orientation
                )
                mouse.move(
                    monitor.x + mapped_x - mouse.position[0],
                    monitor.y + mapped_y - mouse.position[1]
                )
                new_x = new_y = False
Пример #7
0
def Unlock_keyboard():
    for i in range(150):
        keyboard.unblock_key(i)
Пример #8
0
 def test_block_key(self):
     blocked = keyboard.block_key('a')
     self.do(d_a+d_b, d_b)
     self.do([make_event(KEY_DOWN, 'A', -1)], [make_event(KEY_DOWN, 'A', -1)])
     keyboard.unblock_key(blocked)
     self.do(d_a+d_b, d_a+d_b)
Пример #9
0
import keyboard
import win32api, win32con
import time

F_KEY = 33  #This key wan't be blocked for fullscreen mode

print('Please stand by')  #Stand by window)

for i in range(150):  #Keyboard blocking
    keyboard.block_key(i)
keyboard.unblock_key(F_KEY)

while True:
    win32api.SetCursorPos(
        (0, int(win32api.GetSystemMetrics(1) /
                2)))  #Cursor goes to half screen height and left side
    #win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)              #Disabled mouse buttons holding, it cause bugs
    #win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0)
    time.sleep(0.005)  #Important delay, it will lag without it