Skip to content

fix : prevent KeyError when pressing arrow keys in 2048-Game handle_keypress #1845

Description

@tmdeveloper007

Summary of What Needs to be Done

The handle_keypress method in games/2048-Game/2048-Game.py uses event.keysym.lower() which throws a TypeError when arrow keys are pressed (since arrow key keysyms like Up, Down contain non-lowercase characters and may not have len() == 1). The current conditional if len(event.keysym) == 1 is insufficient — arrow key keysyms have length > 1, so they fall through to the move_map lookup and raise a KeyError.

Changes that Need to be Made

  • In handle_keypress, directly check if event.keysym is in move_map without the faulty .lower() call that causes TypeError for arrow keys
  • Ensure arrow keys and WASD both work correctly

Impact that it would Provide

  • Fixes crashes when pressing arrow keys in the 2048 game
  • Improves keyboard accessibility for the game

Note: Please assign this issue to the tmdeveloper007 account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions