예제 #1
0
def printtime():
    winput.press_key(VK_CONTROL)
    winput.press_key(VK_LSHIFT)
    time.sleep(0.1)
    winput.click_key(VK_OEM_1)
    winput.release_key(VK_CONTROL)
    winput.release_key(VK_LSHIFT)
예제 #2
0
async def play_from_txt():
    print("Started replaying from txt!")
    set_state("REPLAYING_TXT")
    bps = []
    with open(replay_buffer_path / f"{GAME_NAME}.txt", "r") as f:
        for data in f:
            vals = data[:-1].split(",")
            bps.append(vals)
    bps = np.array(bps)
    bps = np.char.replace(bps, "lshift", "shiftleft")
    key_list = list(bps)
    print(key_list)
    while key_list:
        start = time.time()
        action, value = key_list[0]
        value = value.strip()

        if action == "down":
            # pyautogui.keyDown(value)
            vk_key = vk_mapping[action]
            winput.press_key(vk_key)

        if action == "delay":
            while (time.time() - start) * 1000 < float(value):
                await asyncio.sleep(0)

        if action == "up":
            # pyautogui.keyUp(value)
            vk_key = vk_mapping[action]
            winput.release_key(vk_key)

        key_list = key_list[1:]
        await asyncio.sleep(0)

    set_state("RECORDING")
    print(
        "\n\nDone replaying, switching to recording.\nA human is playing now.\n\n"
    )
    await asyncio.sleep(0)
예제 #3
0
import winput
from winput.vk_codes import *

import time

def slow_click(vk_code): # delay each keypress by 1/10 of a second
    time.sleep(0.1)
    winput.click_key(vk_code)

# open the RUN menu (WIN + R)
winput.press_key(VK_LWIN)
winput.click_key(VK_R)
winput.release_key(VK_LWIN)

time.sleep(0.5)

# enter "notepad.exe"
slow_click(VK_N)
slow_click(VK_O)
slow_click(VK_T)
slow_click(VK_E)
slow_click(VK_P)
slow_click(VK_A)
slow_click(VK_D)
slow_click(VK_OEM_PERIOD)
slow_click(VK_E)
slow_click(VK_X)
slow_click(VK_E)
slow_click(VK_RETURN)

time.sleep(1)
예제 #4
0
def copy():
    winput.press_key(VK_CONTROL)
    winput.click_key(VK_C)
    winput.release_key(VK_CONTROL)
예제 #5
0
def ctrl_a():
    winput.press_key(VK_CONTROL)
    winput.click_key(VK_A)
    winput.release_key(VK_CONTROL)
예제 #6
0
def tab_b():
    winput.press_key(VK_MENU)
    winput.click_key(VK_TAB)
    time.sleep(0.5)
    winput.click_key(VK_TAB)
    winput.release_key(VK_MENU)
예제 #7
0
def tab():
    winput.press_key(VK_MENU)
    winput.click_key(VK_TAB)
    winput.release_key(VK_MENU)
예제 #8
0
def paste():
    winput.press_key(VK_CONTROL)
    winput.click_key(VK_V)
    winput.release_key(VK_CONTROL)
def Replayrecording(recordingname, numberoftimes):
    global status
    global line
    line = ''

    for i in range(int(numberoftimes)):
        print('')
        print('Replay number ' + str(i + 1))
        print('')

        if i == 0:
            countdown(10)
        else:
            countdown(3)

        with open(recordingname, "r") as f:
            starttime = datetime.now()

            line = f.readline()
            print('')
            while line != '':
                keyboard.press_and_release('shift')

                linesplit = line.split(',')
                if (('LMB' or 'RMB') in linesplit[0]):

                    if ('0:00:00.00' in linesplit[4]):
                        print(linesplit[4])
                        print(linesplit[0])

                        tbposx = linesplit[1].split(',')
                        posx = tbposx[0][1:]
                        posy = linesplit[2][1:-1]

                        winput.set_mouse_pos(int(posx), int(posy))

                        mousebtn = ''
                        if 'LMB' in linesplit[0]:
                            mouse.click(button='left')
                        if 'RMB' in linesplit[0]:
                            mouse.click(button='right')

                        previoustime = datetime.now()
                        line = f.readline()

                    else:
                        currenttime = datetime.now()
                        while (str(currenttime -
                                   starttime)[0:8]) not in linesplit[4]:
                            currenttime = datetime.now()
                            #print('not exactly the same' + str(currenttime - previoustime))
                        #out of while loop

                        print(linesplit[4])
                        print(linesplit[0])

                        tbposx = linesplit[1].split(',')
                        posx = tbposx[0][1:]

                        posy = linesplit[2][1:-1]
                        winput.set_mouse_pos(int(posx), int(posy))

                        mousebtn = ''
                        if 'LMB' in linesplit[0]:
                            mousebtn = 'left'
                        elif 'RMB' in linesplit[0]:
                            mousebtn = 'right'

                        #winput.press_mouse_button(mousebtn)
                        mouse.click(button=mousebtn)

                        previoustime = datetime.now()
                        line = f.readline()

                #not mouse click
                else:
                    previoustime = datetime.now()
                    #currenttime = datetime.now()
                    if ('0:00:00.00' in linesplit[3]):
                        print(linesplit[3])
                        print(linesplit[0])
                        winput.press_key(int(linesplit[0]))
                        previoustime = datetime.now()
                        line = f.readline()

                    else:
                        currenttime = datetime.now()
                        while (str(currenttime -
                                   starttime)[0:8]) not in linesplit[3]:
                            currenttime = datetime.now()
                            #print('not exactly the same' + str(currenttime - previoustime))

                        print(linesplit[3])
                        print(linesplit[0])
                        winput.press_key(int(linesplit[0]))
                        previoustime = datetime.now()
                        line = f.readline()

            f.close()
            endtime = datetime.now()
예제 #10
0
 def execute(self):
     winput.press_key(self.vk_code)
예제 #11
0
def copy():
    winput.press_key(VK_CONTROL)
    time.sleep(0.2)
    winput.click_key(VK_C)
    time.sleep(0.2)
    winput.release_key(VK_CONTROL)
예제 #12
0
def paste():
    winput.press_key(VK_CONTROL)
    time.sleep(0.2)
    winput.click_key(VK_V)
    winput.release_key(VK_CONTROL)