A few more tweaks to the input code.
This commit is contained in:
19
input.py
19
input.py
@ -21,6 +21,7 @@ def get_input(prompt="Enter text:", text=""):
|
|||||||
- Up/Down arrows read full text content
|
- Up/Down arrows read full text content
|
||||||
- Backspace announces deletions
|
- Backspace announces deletions
|
||||||
- Enter submits, Escape cancels
|
- Enter submits, Escape cancels
|
||||||
|
- Control key repeats the original prompt message
|
||||||
- Fully accessible without screen reader dependency
|
- Fully accessible without screen reader dependency
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -37,18 +38,10 @@ def get_input(prompt="Enter text:", text=""):
|
|||||||
|
|
||||||
# Announce the prompt and initial text as a single message
|
# Announce the prompt and initial text as a single message
|
||||||
if text:
|
if text:
|
||||||
message = f"{prompt} Default text: {text}"
|
initial_message = f"{prompt} Default text: {text}"
|
||||||
else:
|
else:
|
||||||
message = f"{prompt} Empty text field"
|
initial_message = f"{prompt} Empty text field"
|
||||||
speak(message)
|
speak(initial_message)
|
||||||
|
|
||||||
# Speak initial cursor position
|
|
||||||
if cursor_pos == 0:
|
|
||||||
speak("Beginning of text")
|
|
||||||
elif cursor_pos == len(text_buffer):
|
|
||||||
speak("End of text")
|
|
||||||
else:
|
|
||||||
speak(f"At character: {text_buffer[cursor_pos]}")
|
|
||||||
|
|
||||||
# Main input loop
|
# Main input loop
|
||||||
while True:
|
while True:
|
||||||
@ -121,6 +114,10 @@ def get_input(prompt="Enter text:", text=""):
|
|||||||
cursor_pos = len(text_buffer)
|
cursor_pos = len(text_buffer)
|
||||||
speak("End of text")
|
speak("End of text")
|
||||||
|
|
||||||
|
elif event.key == pygame.K_LCTRL or event.key == pygame.K_RCTRL:
|
||||||
|
# Repeat the original prompt message
|
||||||
|
speak(initial_message)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Handle regular character input
|
# Handle regular character input
|
||||||
if event.unicode and event.unicode.isprintable():
|
if event.unicode and event.unicode.isprintable():
|
||||||
|
Reference in New Issue
Block a user