def keyboard_callback(event):
    global counter3
    global counter4
    global previousvk

    if str(
            event.action
    ) == '256' and event.vkCode != winput.VK_F1 and event.vkCode != winput.VK_F2 and event.vkCode != winput.VK_SHIFT and event.vkCode != winput.VK_TAB and event.vkCode != winput.VK_MENU and event.vkCode != winput.VK_CONTROL and event.vkCode != winput.VK_CAPITAL:

        eventvk = str(event.vkCode)
        print(str(event.vkCode))
        now = datetime.now()
        date_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")
        SendKeyPressData(str(event.vkCode), '', date_time)

    if event.vkCode == winput.VK_F1:
        if counter4 == 0:
            print('F1 was pressed the application will pause')
            counter4 = 1
            winput.unhook_mouse()
            winput.unhook_keyboard()
            input('To continue press the enter key..')
            #winput.hook_mouse( mouse_callback )
            winput.hook_keyboard(keyboard_callback)

            # enter message loop
            winput.wait_messages()

        elif counter4 == 1:
            counter4 = 0

    #to stop keyshare press F2 Key
    if event.vkCode == winput.VK_F2:  # quit on pressing Numlock. make it later in a way that it can be switched back on
        print('F2 key was pressed. Pythonmation has stopped')
        winput.stop()
Esempio n. 2
0
def choose_stop_recording_key():
    global stop_recording_key, root

    # root.update()

    winput.hook_keyboard(choose_stop_recording_key_hook)

    winput.wait_messages()

    winput.unhook_keyboard()
Esempio n. 3
0
def choose_stop_recording_key():
    global button_choose_stop_recording_key, stop_recording_key, root
    button_choose_stop_recording_key.config(text="Press key...",
                                            state=DISABLED)

    root.update()

    winput.hook_keyboard(choose_stop_recording_key_hook)

    winput.wait_messages()

    winput.unhook_keyboard()
Esempio n. 4
0
def StartApp():
    print("Press Num Lock to quit")

    # hook input
    winput.hook_mouse(mouse_callback)
    winput.hook_keyboard(keyboard_callback)

    # enter message loop
    winput.wait_messages()

    # remove input hook
    winput.unhook_mouse()
    winput.unhook_keyboard()
Esempio n. 5
0
def createNewMacro(name=None):
    global macros, current_macro, last_time, options, start_time, last_flip

    if not name:
        name = "Macro #{}".format(len(macros))

    start_time = time.time()
    last_time = 0
    last_flip = time.time()

    winput.hook_mouse(hookAllEvents)
    winput.hook_keyboard(hookAllEvents)
    winput.wait_messages()

    if current_macro:
        macros[name] = current_macro
        current_macro = []
Esempio n. 6
0
def start_logging(game):
    global start
    start = time.time()
    # log start time
    with open(session_file, "a") as f:
        json.dump({"input start": start}, f)
    # set the hook
    hook_keyboard(on_keyboard_event)
    hook_mouse(on_mouse_event)
    start_game(game)
    update_json(session_file, {"game start": time.time(), "game": game})
    start_recording()
    time.sleep(1)
    update_json(session_file, {"recording start": get_obs_log_time()})
    # set exit handler to log session data
    print("registering exit handler")
    atexit.register(exit_handler)
    # listen for input
    wait_messages()
        if event.vkCode == winput.VK_PRIOR:  # 按Page Up 退出
            print("关闭hook并退出")
            winput.stop()


if __name__ == "__main__":
    key_tab_num = 0
    send_massage_num = 0

    print("********************************")
    print("* 统计发送了多少条消息的小程序 *")
    print("*     --统计规则:              *")
    print("*        每两次tab发送一条消息 *")
    print("*                              *")
    print("* Page Down: 显示统计结果      *")
    print("* page Up:   退出程序          *")
    print("********************************")
    print("\n")

    # **

    # HOOK 输入
    winput.hook_keyboard(keyboard_callback)

    # 进入消息循环
    winput.wait_messages()

    # remove
    winput.unhook_keyboard()
Esempio n. 8
0
def key():
    winput.hook_keyboard( keyboard_callback )
    winput.wait_messages()
    winput.unhook_keyboard()
def createNewMacro(name=None):
    winput.hook_keyboard(hookAllEvents)
    winput.wait_messages()
def StartApp():
    try:
        thechoice = GetInput()

        if thechoice == 2:
            print('')
            countdown('5rec')
            print("Press F1 to pause. Press F2 to quit")

            # hook input
            ##winput.hook_mouse( mouse_callback )
            winput.hook_keyboard(keyboard_callback)

            # enter message loop
            winput.wait_messages()

            # remove input hook
            ##winput.unhook_mouse()
            winput.unhook_keyboard()

        elif thechoice == 1:
            print(
                'Enter the full name of the recording file to replay, or choose one from the list below by typing the number (example Num0)'
            )
            linecounter = 0
            with open("replayhistory.txt", "r") as f:
                for line in f:
                    if line != '':
                        print('Num' + str(linecounter) + ': ' + line[:-1])
                        linecounter = int(linecounter)
                        linecounter = linecounter + 1

                f.close()

            isshortcut = False
            recordingname = input('')
            recordingnum = '-1'
            historyfilelines = ''
            if (('Num' in recordingname) or ('num' in recordingname)):
                recordingnum = recordingname.replace('Num', '')
                recordingnum = recordingname.replace('num', '')
                isshortcut = True

            if recordingnum != '-1':
                with open("replayhistory.txt", "r") as f:
                    historyfilelines = f.readlines()
                    f.close()

                recordingname = historyfilelines[int(recordingnum)][:-1]

            if isshortcut == False:
                with open("replayhistory.txt", "a") as f:
                    f.write(recordingname + '\n')
                    f.close()

            print('How many times do you want to replay')
            nrofreplays = input('')
            nrofreplays = int(nrofreplays)
            Replayrecording(recordingname, nrofreplays)
            ##winput.unhook_mouse()
            winput.unhook_keyboard()

    except Exception as e:
        print('Exception was thrown. ' + str(e))
        ##winput.unhook_mouse()
        winput.unhook_keyboard()
Esempio n. 11
0
def create_macro(name, start_at, screen_width, screen_height):
    global start, raw_data, stop_recording_key

    mode = config.get("recording_mode", "key")

    duration = config.get("recording_duration", 10)

    stop_recording_key = config.get("recording_stop_key", winput.VK_ESCAPE)

    mouse_enabled = config.get("record_mouse", True)

    keyboard_enabled = config.get("record_keyboard", True)

    assert mode in ("timer", "key")

    assert type(duration) in (float, int) and duration > 0

    assert type(stop_recording_key) == int and 0 <= stop_recording_key <= 2**15

    assert type(mouse_enabled) == type(keyboard_enabled) == bool

    assert mouse_enabled or keyboard_enabled

    raw_data = []

    while True:
        if time.time() > start_at:
            break
        time.sleep(0.0001)

    start = perf_counter_ns()

    start_mouse_pos = None

    if mode == "timer":
        if mouse_enabled:
            start_mouse_pos = winput.get_mouse_pos()
            winput.hook_mouse(callback)

        if keyboard_enabled:
            winput.hook_keyboard(callback)

        while True:
            now = perf_counter_ns()

            if now >= start + duration * 1000000000:
                break

            winput.get_message()

    elif mode == "key":
        if mouse_enabled:
            start_mouse_pos = winput.get_mouse_pos()
            winput.hook_mouse(callback)

        if keyboard_enabled:
            winput.hook_keyboard(callback_with_stop_key)
        else:
            winput.hook_keyboard(callback_only_stop_key)

        winput.wait_messages()

    winput.unhook_mouse()
    winput.unhook_keyboard()

    return Macro.from_raw_data(name, start, start_mouse_pos, screen_width,
                               screen_height, raw_data)