Skip to content
Open
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
8 changes: 7 additions & 1 deletion typing_speed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def __init__(self):
self.input_textbox.configure(state="disabled")

self.input_textbox.bind("<KeyRelease>", self.handle_typing)
# Suppress newline insertion so Enter doesn't add a blank line
self.input_textbox.bind("<Return>", lambda e: "break")

# ── RESULT LABEL ───────────────────────────────────────
Expand Down Expand Up @@ -443,6 +444,7 @@ def __init__(self):
)
self.pause_button.grid(row=0, column=1, padx=10)

# Bind Enter to start the test when not typing
self.bind("<Return>", self.handle_enter)

# ======================
Expand Down Expand Up @@ -551,6 +553,7 @@ def start_test(self):
if self.timer_running:
return

# Read user-selected duration
self.test_duration = DURATION_OPTIONS.get(
self.duration_var.get(), DEFAULT_DURATION
)
Expand Down Expand Up @@ -657,6 +660,7 @@ def toggle_pause(self):
self.after_cancel(self.live_wpm_after_id)
else:
self.pause_button.configure(text="Pause")
# Shift start_time forward by the length of the pause
pause_duration = time.time() - self.pause_start
self.start_time += pause_duration
self.update_timer()
Expand All @@ -679,6 +683,7 @@ def handle_typing(self, event):
"Return", "Shift_L", "Shift_R",
"Control_L", "Control_R", "Alt_L", "Alt_R",
):
# Per-character correct/incorrect sound
if index <= len(self.current_sentence) and index > 0:
expected = self.current_sentence[index - 1]
if typed[-1] == expected:
Expand All @@ -688,6 +693,7 @@ def handle_typing(self, event):

self.update_sentence_display()

# Check if sentence is completed
if typed.strip() == self.current_sentence.strip():
self.check_result()

Expand Down Expand Up @@ -759,7 +765,7 @@ def check_result(self):
self.live_wpm_after_id = None

if not self.timer_running:
return
return # Guard against double-fire

self.timer_running = False
beep(1200, 300)
Expand Down