I'm new to python and I'm working on a small autoclicker that you can turn on & off using the letter 's', however when I press it the autoclicker starts but I can't turn it off unless I use the letter 'k' which is used to stop the program completely, this is what my code looks like:
from pynput.mouse import Controller, Button
import keyboard as kb
import time
import multiprocessing
def click():
isToggled = False
mouse = Controller()
while True:
if isToggled:
mouse.click(Button.left)
time.sleep(0.01)
if kb.is_pressed('s'):
if isToggled:
isToggled = False
else:
isToggled = True
elif kb.is_pressed('k'):
break
if __name__ == '__main__':
p = multiprocessing.Process(target=click)
p.start()
p.join()