MCPcopy Index your code
hub / github.com/python/cpython / translate_key

Function translate_key

Lib/idlelib/config_key.py:24–41  ·  view source on GitHub ↗

Translate from keycap symbol to the Tkinter keysym.

(key, modifiers)

Source from the content-addressed store, hash-verified

22
23
24def translate_key(key, modifiers):
25 "Translate from keycap symbol to the Tkinter keysym."
26 mapping = {'Space':'space',
27 '~':'asciitilde', '!':'exclam', '@':'at', '#':'numbersign',
28 '%':'percent', '^':'asciicircum', '&':'ampersand',
29 '*':'asterisk', '(':'parenleft', ')':'parenright',
30 '_':'underscore', '-':'minus', '+':'plus', '=':'equal',
31 '{':'braceleft', '}':'braceright',
32 '[':'bracketleft', ']':'bracketright', '|':'bar',
33 ';':'semicolon', ':':'colon', ',':'comma', '.':'period',
34 '<':'less', '>':'greater', '/':'slash', '?':'question',
35 'Page Up':'Prior', 'Page Down':'Next',
36 'Left Arrow':'Left', 'Right Arrow':'Right',
37 'Up Arrow':'Up', 'Down Arrow': 'Down', 'Tab':'Tab'}
38 key = mapping.get(key, key)
39 if 'Shift' in modifiers and key in string.ascii_lowercase:
40 key = key.upper()
41 return f'Key-{key}'
42
43
44class GetKeysFrame(Frame):

Callers 1

build_key_stringMethod · 0.85

Calls 2

getMethod · 0.45
upperMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…