Skip to content

Add Keyboard Support to Canvas #4218

@corranwebster

Description

@corranwebster

What is the problem or limitation you are having?

The Canvas widget is has no keyboard handling. It would be useful to be able to do things like scroll a plot using arrow keys or capture simple keyboard input for games.

Describe the solution you'd like

Add a callback for keyboard events on the Canvas widget. The callback should be given the key pressed as a Toga Key expression, along with any modifiers, and ideally the text that results from that key combination with the current keyboard layout, if any.

Describe alternatives you've considered

Leaving it as is, and implementing a more robust input handling system at a higher level that is independent of the Canvas widget. For example the proposal doesn't handle composed keys or entering text in Chinese/Japanese/Korean. These require additional special handling which should be its own subsystem (see eg. hoe Gtk handles composing characters).

Additional context

This is related to #3994 in so far as the Canvas element can have keypress handlers. Looking at how HTML/Javascript handles key presses may give a guide to the information that is passed to the callback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features, or improvements to existing features.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions