Skip to content
Toga
0.5.3.dev143+gabcc6cdb6

Keys

A symbolic representation of keys used for keyboard shortcuts.

Most keys have a constant that matches the text on the key, or the name of the key if the text on the key isn't a legal Python identifier.

However, due to differences between platforms, there's no representation of "modifier" keys like Control, Command, Option, or the Windows Key. Instead, Toga provides three generic modifier constants, and maps those to the modifier keys, matching the precedence with which they are used on the underlying platforms:

Platform MOD_1 MOD_2 MOD_3
Linux Control Alt Tux/Windows/Meta
macOS Command (⌘) Option Control (^)
Windows Control Alt Not supported

Key combinations can be expressed by combining multiple Key values with the + operator.

from toga import Key

just_an_a = Key.A
shift_a = Key.SHIFT + Key.A
# Windows/Linux - Control-Shift-A:
# macOS - Command-Shift-A:
modified_shift_a = Key.MOD_1 + Key.SHIFT + Key.A

The order of addition is not significant. Key.SHIFT + Key.A and Key.A + Key.SHIFT will produce the same key representation.

Reference

toga.Key

Bases: Enum

An enumeration providing a symbolic representation for the characters on a keyboard.

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

EXCLAMATION

AT

HASH

DOLLAR

PERCENT

CARET

AMPERSAND

ASTERISK

OPEN_PARENTHESIS

CLOSE_PARENTHESIS

MINUS

UNDERSCORE

EQUAL

PLUS

OPEN_BRACKET

CLOSE_BRACKET

OPEN_BRACE

CLOSE_BRACE

BACKSLASH

PIPE

SEMICOLON

COLON

QUOTE

DOUBLE_QUOTE

COMMA

LESS_THAN

FULL_STOP

GREATER_THAN

SLASH

QUESTION

BACK_QUOTE

TILDE

ESCAPE

TAB

SPACE

BACKSPACE

ENTER

CAPSLOCK

SHIFT

MOD_1

MOD_2

MOD_3

F1

F2

F3

F4

F5

F6

F7

F8

F9

F10

F11

F12

F13

F14

F15

F16

F17

F18

F19

EJECT

HOME

END

INSERT

DELETE

PAGE_UP

PAGE_DOWN

UP

DOWN

LEFT

RIGHT

NUMLOCK

NUMPAD_0

NUMPAD_1

NUMPAD_2

NUMPAD_3

NUMPAD_4

NUMPAD_5

NUMPAD_6

NUMPAD_7

NUMPAD_8

NUMPAD_9

NUMPAD_CLEAR

NUMPAD_DECIMAL_POINT

NUMPAD_DIVIDE

NUMPAD_ENTER

NUMPAD_EQUAL

NUMPAD_MINUS

NUMPAD_MULTIPLY

NUMPAD_PLUS

SCROLLLOCK

BEGIN

MENU

PAUSE

is_printable()

Does pressing the key result in a printable character?

__add__(other)

Allow two Keys to be concatenated, or a string to be concatenated to a Key.

Produces a single string definition.

e.g., Toga.Key.MOD_1 + 'a' -> "<mod 1>a" Toga.Key.MOD_1 + Toga.Key.SHIFT + 'a' -> "<mod 1><shift>a"

__radd__(other)

Same as add.