I previously posted a question for codereview:
And I received some great feedback and changes to do in the code.
I have done many of the changes mentioned in the answers and here is the final code:
from pynput.keyboard import Controller
from time import sleep
def auto_click(key: str, n_clicks: int, delay: float):
keyboard = Controller()
for _ in range(n_clicks):
keyboard.tap(key)
sleep(delay)
def main():
key = input("Key to be autopressed: ")
try:
n_clicks = int(input("Number of autopresses (integer): "))
except ValueError:
print("\n The number of autopresses should be an integer value, defaulting to 1. \n")
n_clicks = 1
try:
delay = float(input("Delay between each autopress in seconds (integer/float): "))
except ValueError:
print("\n The delay between each autoclick should be an integer or a decimal value, defaulting to 1 (second). \n")
delay = 1
auto_click(key, n_clicks, delay)
if __name__ == '__main__':
main()
What is it that you think should be made better in this code? Any feedback and suggestions would be much appreciated.
Here's the github repo: