Пример #1
0
def replay(speed, barlen=0):
    if recording:
        print("? Now recording, can't replay")
        return False

    if not (0.0 < speed and speed <= 10):
        print('? Replay speed is too fast or too slow.')
        return False

    if not tstamp:
        print('? nothing to play')
        return False

    print('Replay keying:', len(tstamp), 'marks and spaces...')
    print('(Dots or marks longer than', maxdelay, 'seconds will be trucated)')

    # setups for progress bar
    #
    if 1 <= barlen:
        progbar = utl.ProgressBar(barlen, int(len(tstamp)))
        progbar.begin()

        barstep = int(len(tstamp) / barlen / 2) + 1  # frequency of bar update
        barcount = 0

    try:
        # replay loop
        #
        for i in range(len(tstamp) - 1):
            if key.abort_requested():
                key.space()
                progbar.end(False)
                return False
            elif keystat[i] == key.PRESSED:
                key.mark()
            elif keystat[i] == key.RELEASED:
                key.space()

            if 1 <= barlen:
                barcount += 1
                if barstep < barcount:
                    progbar.update(i)
                    barcount = 0

            if 0 <= maxdelay:
                time.sleep(min(maxdelay, (tstamp[i + 1] - tstamp[i]) / speed))
            else:
                time.sleep((tstamp[i + 1] - tstamp[i]) / speed)

        if 1 <= barlen:
            # complete progressbar
            progbar.end(True)

    except KeyboardInterrupt:
        if 1 <= barlen:
            print()
        key.space()

    return True
Пример #2
0
def action(state):
    global pressing

    # almost pass-through
    #
    if state == key.PRESSED:
        key.mark()
        key.abort_request()  # request to abort text keyer
        pressing = True
    elif state == key.RELEASED:
        key.space()
        pressing = False