Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions GUI_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
root_widget.title("KeyBoard Simulator")

# Width and Height
root_widget.geometry('780x480')
root_widget.geometry("780x480")

# Image
frame = tk.Frame(root_widget, width=600, height=400)
frame.pack()
frame.place(anchor='center', relx=0.5, rely=0.5)
body_image = ImageTk.PhotoImage(Image.open('gui_assets/type.jpg'))
frame.place(anchor="center", relx=0.5, rely=0.5)
body_image = ImageTk.PhotoImage(Image.open("gui_assets/type.jpg"))
label_for_body_image = tk.Label(frame, image=body_image)
label_for_body_image.pack()

# Labeling the window title
root_window_title = tk.Label(root_widget, text="AutoType 🖊", fg="#8FBDD3", font=('', 62))
root_window_title = tk.Label(
root_widget, text="AutoType 🖊", fg="#8FBDD3", font=("", 62)
)
root_window_title.pack()

# Input Box for Time Delay
Expand All @@ -40,7 +42,9 @@
# Logic
# Function for Addition of Time Delay
def add_time_delay():
mylable_time = tk.Label(root_widget, text=f"Time Delay of {entry_for_time_delay.get()} seconds added")
mylable_time = tk.Label(
root_widget, text=f"Time Delay of {entry_for_time_delay.get()} seconds added"
)
mylable_time.pack()


Expand All @@ -58,13 +62,27 @@ def file_writer():


# Button widget instance
button_for_add_time_delay = tk.Button(root_widget, text="Add time Delay in Seconds", activebackground='#345', activeforeground='white', padx=5,
pady=5, command=add_time_delay)
button_for_add_time_delay = tk.Button(
root_widget,
text="Add time Delay in Seconds",
activebackground="#345",
activeforeground="white",
padx=5,
pady=5,
command=add_time_delay,
)
button_for_add_time_delay.pack()

# Button widget instance
button_for_writing_file = tk.Button(root_widget, text="Write File", activebackground='#345', activeforeground='white', padx=5, pady=5,
command=file_writer)
button_for_writing_file = tk.Button(
root_widget,
text="Write File",
activebackground="#345",
activeforeground="white",
padx=5,
pady=5,
command=file_writer,
)
button_for_writing_file.pack()

root_widget.mainloop()
2 changes: 1 addition & 1 deletion Simulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .simulate_keyboard import Type
from .simulate_keyboard import Type
6 changes: 3 additions & 3 deletions Simulator/simulate_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def __init__(self, x, y):
self.y = y
"""
if path:
with open(path, 'r') as file:
with open(path, "r") as file:
code = file.read()

keyboard = Controller()
for line in code.split('\n'):
for line in code.split("\n"):
keyboard.type(line)
# It was observed that a small sleep in between each lines, makes Autotype perform better
sleep(0.1)
keyboard.tap(Key.enter)
keyboard.tap(Key.home)
keyboard.tap(Key.home)
55 changes: 39 additions & 16 deletions command_line_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
from Simulator import Type
import time


def autotype_cli(
path: Optional[str] = typer.Option(default="",
help=typer.style("the path to the file 🗂", fg=typer.colors.MAGENTA),
prompt=True, confirmation_prompt=True, show_default="Empty File Path"),
delay: Optional[int] = typer.Option(default=3,
help=typer.style(
"time ⌛️ delay before typing (in seconds)",
fg=typer.colors.MAGENTA),
show_default=3,
prompt=True)):
path: Optional[str] = typer.Option(
default="",
help=typer.style("the path to the file 🗂", fg=typer.colors.MAGENTA),
prompt=True,
confirmation_prompt=True,
show_default="Empty File Path",
),
delay: Optional[int] = typer.Option(
default=3,
help=typer.style(
"time ⌛️ delay before typing (in seconds)", fg=typer.colors.MAGENTA
),
show_default=3,
prompt=True,
),
):
"""
A quick and small python script that helps you autotype on websites that have copy paste disabled like Moodle, HackerEarth contests etc as it is difficult to efficiently debug your code on an online compiler.

Expand All @@ -25,22 +33,37 @@ def autotype_cli(
return: Prints the File Given.
"""
if path and not os.path.isfile(path):
file_path = typer.style(f"{path}", fg=typer.colors.BRIGHT_WHITE, bg=typer.colors.BRIGHT_RED, bold=True)
error_message = typer.style("is not found Please Specify the correct Path.", fg=typer.colors.RED)
file_path = typer.style(
f"{path}",
fg=typer.colors.BRIGHT_WHITE,
bg=typer.colors.BRIGHT_RED,
bold=True,
)
error_message = typer.style(
"is not found Please Specify the correct Path.", fg=typer.colors.RED
)
typer.echo(f"{file_path + ' ' + error_message} ")
raise typer.Exit(code=0)
else:
total = 0
with typer.progressbar(range(100), label=typer.style("Writing File in Progress -> ", fg=typer.colors.GREEN,
bold=True)) as progress:
with typer.progressbar(
range(100),
label=typer.style(
"Writing File in Progress -> ", fg=typer.colors.GREEN, bold=True
),
) as progress:
for value in progress:
time.sleep(0.01)
total += 1
Type(path, delay)
successfull_file_path = typer.style(f"{path} File", fg=typer.colors.BRIGHT_GREEN)
time_taken = typer.style(f"is written in {abs(delay)} seconds", fg=typer.colors.BRIGHT_WHITE)
successfull_file_path = typer.style(
f"{path} File", fg=typer.colors.BRIGHT_GREEN
)
time_taken = typer.style(
f"is written in {abs(delay)} seconds", fg=typer.colors.BRIGHT_WHITE
)
typer.echo(f"{successfull_file_path + ' ' + time_taken}")


if __name__ == '__main__':
if __name__ == "__main__":
typer.run(autotype_cli)