Example #1
0
def key_tap(vkcodes, repeats=1, delay=0):
    keyboard_inputs = (INPUT * (2 * len(vkcodes)))()
    for i, vkcode in enumerate(vkcodes):
        keyboard_inputs[(i * 2)] = INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT(vkcode))
        keyboard_inputs[(i * 2) + 1] = INPUT(INPUT_KEYBOARD,
                                             ki=KEYBDINPUT(
                                                 vkcode,
                                                 dwFlags=KEYEVENTF_KEYUP))

    count = 0
    for _ in range(0, repeats):
        count += SENDINPUT(2 * len(vkcodes), keyboard_inputs, sizeof(INPUT))
        sleep(delay)

    return count
Example #2
0
def key_release(vkcodes):
    keyboard_inputs = (INPUT * len(vkcodes))()
    for i, vkcode in enumerate(vkcodes):
        keyboard_inputs[i] = INPUT(INPUT_KEYBOARD,
                                   ki=KEYBDINPUT(vkcode,
                                                 dwFlags=KEYEVENTF_KEYUP))

    return SENDINPUT(len(vkcodes), keyboard_inputs, sizeof(INPUT))
Example #3
0
def mouse_wheel_move(movement, horizontal=False):
    mouse_input = INPUT(
        INPUT_MOUSE,
        mi=MOUSEINPUT(
            mouseData=movement,
            dwFlags=MOUSEEVENTF_HWHEEL if horizontal else MOUSEEVENTF_WHEEL))

    return SENDINPUT(1, byref(mouse_input), sizeof(INPUT))
Example #4
0
def mouse_move(input_x, input_y, absolute=False):
    mouse_input = INPUT(
        INPUT_MOUSE,
        mi=MOUSEINPUT(input_x,
                      input_y,
                      dwFlags=MOUSEEVENTF_MOVE +
                      (MOUSEEVENTF_ABSOLUTE if absolute else 0)))

    return SENDINPUT(1, byref(mouse_input), sizeof(INPUT))
Example #5
0
def text_write(text, ignore_modifiers=False):
    layout = get_keyboard_layout(0)

    inputs = []
    for char in text:
        result = vk_key_scan(char, layout)

        if not ignore_modifiers:
            if MODIFIER_SHIFT & result.shiftState:
                inputs.append(INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT(SHIFT_KEY)))
            if MODIFIER_CTRL & result.shiftState:
                inputs.append(INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT(CTRL_KEY)))
            if MODIFIER_ALT & result.shiftState:
                inputs.append(INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT(ALT_KEY)))

        if inputs and result.vkCode == inputs[-1].ki.wVk:
            inputs.append(INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT()))

        inputs.append(INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT(result.vkCode)))

        if not ignore_modifiers:
            if MODIFIER_SHIFT & result.shiftState:
                inputs.append(
                    INPUT(INPUT_KEYBOARD,
                          ki=KEYBDINPUT(SHIFT_KEY, dwFlags=KEYEVENTF_KEYUP)))
            if MODIFIER_CTRL & result.shiftState:
                inputs.append(
                    INPUT(INPUT_KEYBOARD,
                          ki=KEYBDINPUT(CTRL_KEY, dwFlags=KEYEVENTF_KEYUP)))
            if MODIFIER_ALT & result.shiftState:
                inputs.append(
                    INPUT(INPUT_KEYBOARD,
                          ki=KEYBDINPUT(ALT_KEY, dwFlags=KEYEVENTF_KEYUP)))

    keyboard_inputs = (INPUT * len(inputs))()
    for i, value in enumerate(inputs):
        keyboard_inputs[i] = value

    return SENDINPUT(len(inputs), keyboard_inputs, sizeof(INPUT))
Example #6
0
def key_press(vkcodes):
    keyboard_inputs = (INPUT * len(vkcodes))()
    for i, vkcode in enumerate(vkcodes):
        keyboard_inputs[i] = INPUT(INPUT_KEYBOARD, ki=KEYBDINPUT(vkcode))

    return SENDINPUT(len(vkcodes), keyboard_inputs, sizeof(INPUT))
Example #7
0
def mouse_event(flags):
    mouse_inputs = (INPUT * len(flags))()
    for i, flag in enumerate(flags):
        mouse_inputs[i] = INPUT(INPUT_MOUSE, mi=MOUSEINPUT(dwFlags=flag))

    return SENDINPUT(len(flags), mouse_inputs, sizeof(INPUT))