Skip to content

Commit

Permalink
Add some more esoteric keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed May 6, 2024
1 parent c86b96f commit 16eba7a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion changes/2220.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Key handling for Insert, Delete, Num Lock, and some uses of Shift was added for GTK and Winforms.
Key handling for Insert, Delete, Num Lock, Scroll Lock, and some other esoteric keys was added for GTK and Winforms. Some uses of bare Shift on GTK were also improved.
5 changes: 5 additions & 0 deletions core/src/toga/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class Key(Enum):
NUMPAD_MULTIPLY = "numpad:*"
NUMPAD_PLUS = "numpad:+"

SCROLLLOCK = "<scroll lock>"
BEGIN = "<begin>"
MENU = "<menu>"
PAUSE = "<pause>"

def is_printable(self) -> bool:
"""Does pressing the key result in a printable character?"""
return not (self.value.startswith("<") and self.value.endswith(">"))
Expand Down
8 changes: 7 additions & 1 deletion gtk/src/toga_gtk/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
Gdk.KEY_X: Key.X,
Gdk.KEY_Y: Key.Y,
Gdk.KEY_Z: Key.Z,
Gdk.KEY_Caps_Lock: Key.CAPSLOCK,
Gdk.KEY_Tab: Key.TAB,
Gdk.KEY_bracketleft: Key.OPEN_BRACKET,
Gdk.KEY_bracketright: Key.CLOSE_BRACKET,
Expand All @@ -123,6 +124,8 @@
Gdk.KEY_question: Key.QUESTION,
Gdk.KEY_Insert: Key.INSERT,
Gdk.KEY_Delete: Key.DELETE,
Gdk.KEY_Begin: Key.BEGIN,
Gdk.KEY_Menu: Key.MENU,
Gdk.KEY_Home: Key.HOME,
Gdk.KEY_End: Key.END,
Gdk.KEY_Page_Up: Key.PAGE_UP,
Expand Down Expand Up @@ -152,12 +155,15 @@
Gdk.KEY_KP_Up: Key.UP,
Gdk.KEY_KP_Down: Key.DOWN,
Gdk.KEY_KP_Delete: Key.DELETE,
Gdk.KEY_KP_Insert: Key.INSERT,
Gdk.KEY_KP_Add: Key.NUMPAD_PLUS,
Gdk.KEY_KP_Subtract: Key.NUMPAD_MINUS,
Gdk.KEY_KP_Multiply: Key.NUMPAD_MULTIPLY,
Gdk.KEY_KP_Divide: Key.NUMPAD_DIVIDE,
Gdk.KEY_KP_Delete: Key.DELETE,
Gdk.KEY_KP_Begin: Key.BEGIN,
Gdk.KEY_Pause: Key.PAUSE,
Gdk.KEY_ISO_Left_Tab: Key.TAB,
Gdk.KEY_Scroll_Lock: Key.SCROLLLOCK,
Gdk.KEY_Shift_L: Key.SHIFT,
Gdk.KEY_Shift_R: Key.SHIFT,
}
Expand Down
2 changes: 2 additions & 0 deletions winforms/src/toga_winforms/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
Key.RIGHT.value: WinForms.Keys.Right,
Key.NUMLOCK.value: WinForms.Keys.NumLock,
Key.NUMPAD_DECIMAL_POINT.value: WinForms.Keys.Decimal,
Key.SCROLLLOCK.value: WinForms.Keys.Scroll,
Key.MENU.value: WinForms.Keys.Menu,
}
WINFORMS_KEYS.update(
{str(digit): getattr(WinForms.Keys, f"D{digit}") for digit in range(10)}
Expand Down

0 comments on commit 16eba7a

Please sign in to comment.