0
import keyboard, time

print('You can use :smile: on discord if you want to use emojis.')
write = input('Enter the text you want to autotype:')

def typeman():

    time.sleep(1)
    keyboard.write(write)
    keyboard.press_and_release('enter')

while True:
    if keyboard.is_pressed("w"):
        while True:
            if keyboard.is_pressed("s"):
                break
            typeman()

This code used to work a couple of months ago, when I press W it types write variable automatically, when I press S it's supposed to stop, but it doesn't work anymore. how to I fix this, and when it used to work I had to hold S for a while for it to stop, how do I break easier?

  • 1
    Have you tried using `try..catch` so when `s` is pressed, it throws exception that stops the read itself? Ref: https://stackoverflow.com/a/63654927/14631885 – Dhana D. Aug 20 '21 at 16:28

1 Answers1

1

The nested loops you created were unneeded, using an if and while statement does the trick just fine!

import keyboard, time

print('You can use :smile: on discord if you want to use emojis.')
write = input('Enter the text you want to autotype:')


def typeman():
    keyboard.write(write)
    keyboard.press_and_release('enter')

while True:
    if keyboard.is_pressed("w"): # Check whether to start or not
        while not keyboard.is_pressed("s"): # While s isnt pressed
            typeman()
            time.sleep(1)
    # To end that while