L
L
Limons2021-05-04 12:19:00
Python
Limons, 2021-05-04 12:19:00

How to properly record keys for later playback?

I need to make a record of a certain sequence of pressed buttons, on the rack in consequence to play it.

Everything I came up with:

import keyboard
import time
timer = time.time()
timer = round(timer, 2)
dodo = 0
def print_pressed_keys(e):
    global dodo
    timeTwo = round(time.time(),2)
    perem = timeTwo - timer - dodo
    perem = round(perem, 2)
    dodo += perem
    ti = "time.sleep("+ str(perem) + ")\n"
    print(ti)
    f = open("key_records.txt", 'a')
    f.write(ti)
    if e.event_type == 'down':
        g = "pg.keyDown(@" + str(e.name) + "@)\n"
        f.write(g)
    else:
        g = "pg.keyUp(@" + str(e.name) + "@)\n"
        f.write(g)
    f.close()

keyboard.hook(print_pressed_keys)
keyboard.wait()


But firstly, for some reason, the python stops responding as soon as I open the game (windowed mode), and secondly .. maybe there is a smarter and more polished method?

@ - I would then replace them with ", but in the code itself (via visual studio)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Limons, 2021-05-04
@Limons

1) You need to run as admin for something to work, but for full-fledged movements in the game, you should not use pg.press or keyDown-Up, since the game does not read click data.
2) this library has internal. delay, which makes it...bad.
What other methods are there for this purpose? Help me please!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question