def handleBrackets(word, i, release):
    #numeric >> insert wait
    if (word[i].isnumeric()):
        moveDecimal = False
        temp = 0
        while (word[i] != '}'):
            if (word[i] == '.'):
                decimalPlace = 1
                moveDecimal = True
            elif (moveDecimal == True):
                temp = temp + (int(word[i]) / (decimalPlace * 10))
                decimalPlace = decimalPlace + 1
            else:
                temp = (temp * 10) + int(word[i])
            i = i + 1
        time.sleep(temp)
        return i, False
    #special key
    else:
        temp = word[i]
        i = i + 1
        while (word[i] != '}'):
            temp = temp + word[i]
            i = i + 1
        try:
            key = findKey(temp)
            keyboard().press(key)
            if (release): keyboard().release(key)
            return i, key
        except:
            print("ERROR: can't press Key.", temp)
        return i, False
def typeThis(word):
    i = 0
    while (i < len(word)):
        #either special key or a wait
        if (word[i] == '{'):
            i = i + 1
            i = handleBrackets(word, i, True)[0]
        #press multiple keys at once
        elif (word[i] == '<'):
            i = i + 1
            temp = []
            while (word[i] != '>'):
                #either special key or a wait
                if (word[i] == '{'):
                    i = i + 1
                    i, key = handleBrackets(word, i, False)
                    if (key != False): temp.append(key)
                else:
                    keyboard().press(word[i])
                    temp.append(word[i])
                i = i + 1
            for j in temp:
                keyboard().release(j)
        #mouse clicks
        elif (word[i] == '('):
            i = i + 1
            while (word[i] != ')'):
                if (word[i] == 'l'):
                    mouse().press(Button.left)
                    mouse().release(Button.left)
                elif (word[i] == 'r'):
                    mouse().press(Button.right)
                    mouse().release(Button.right)
                else:
                    print('ERROR: not valid mouse input: ', word[i])
                i = i + 1
        else:
            keyboard().press(word[i])
            keyboard().release(word[i])
        i = i + 1
    "Key.space": 0,
    "Key.alt_r": 0,
    "Key.cmd_r": 0,
    "Key.menu": 0,
    "Key.ctrl_r": 0,
    "Key.insert": 0,
    "Key.home": 0,
    "Key.page_up": 0,
    "Key.end": 0,
    "Key.page_down": 0,
    "Key.left": 0,
    "Key.up": 0,
    "Key.right": 0,
    "Key.down": 0,
    "Key.num_lock": 0,
    "'/'": 0,
    "'*'": 0,
    "'-'": 0,
    "'+'": 0,
    "<12>": 0,
    "Key.delete": 0,
    "clicked": 0,
}


def WriteToFile(key):
    print(key)


keyboard(on_release=WriteToFile).start()
pip3 install pynput
这个库让你可以控制和监控输入设备。
对于每一种输入设备,它包含一个子包来控制和监控该种输入设备:
pynput.mouse:包含控制和监控鼠标或者触摸板的类。
pynput.keyboard:包含控制和监控键盘的类。
"""

import time

#  键盘操作
from pynput.keyboard import Controller as keyboard, Key
# 鼠标操作
from pynput.mouse import Controller as mouse, Button

mouse = mouse()
keyboard = keyboard()


def open_terminal():
    # 移动到 iterm的位置,点击左键
    print('当前鼠标位置 {0}'.format(mouse.position))
    mouse.position = (1180, 1000)
    print('现在我们移动到了 {0}'.format(mouse.position))
    mouse.click(Button.left, 1)
    time.sleep(1)


def open_logined_tabs(num: int):
    """
    打开几个tab
    """
Beispiel #5
0
        else:
            actionQueue.append(Action("key", (key.char, "down")))


def keyReleaseHandler(key):
    if recording:
        if type(key) is Key:
            actionQueue.append(Action("key", (key.name, "up")))
        else:
            actionQueue.append(Action("key", (key.char, "up")))


mListener = mouse(on_click=clickHandler)
mListener.start()

kListener = keyboard(on_press=keyPressHandler, on_release=keyReleaseHandler)
kListener.start()

layout = [[sg.Text("IDLE", key="status"), sg.Button("Record"), sg.Button("Playback"), sg.Input("1", key="iterations", size=(10, 10))]]
window = sg.Window(title="Micrsoft Office Generator", layout=layout, margins=(20, 20))
while True:
    event, values = window.read()

    if event == "Record":
        if not recording:
            actionQueue = []
            recording = True
            window.FindElement("status").update("REC")
        else:
            recording = False
            window.FindElement("status").update("IDLE")