🧪 Version 0.2.2 is our alpha release candidate. Please send us bug reports and suggestions!

Sketchingpy

Creative coding and interactive science everywhere for everyone: web, desktop, mobile, Jupyter, and more. Open source!

Reference for get_name (Keyboard)

Get the name of a key. This is part of the reference section.

Purpose

Get a string describing a key. Note the following values for special keys are maintained formally:
Name Value Constant
Alt 'alt' sketchingpy.const.KEYBOARD_ALT_BUTTON
Arrow: Left Key 'left' sketchingpy.const.KEYBOARD_LEFT_BUTTON
Arrow: Up Key 'up' sketchingpy.const.KEYBOARD_UP_BUTTON
Arrow: Right Key 'right' sketchingpy.const.KEYBOARD_RIGHT_BUTTON
Arrow: Down Key 'down' sketchingpy.const.KEYBOARD_DOWN_BUTTON
Ctrl 'ctrl' sketchingpy.const.KEYBOARD_CTRL_BUTTON
Shift 'shift' sketchingpy.const.KEYBOARD_SHIFT_BUTTON
Space 'space' sketchingpy.const.KEYBOARD_SPACE_BUTTON
Super 'super' sketchingpy.const.KEYBOARD_SUPER_BUTTON
Tab 'tab' sketchingpy.const.KEYBOARD_TAB_BUTTON
Alphanumeric keys will have their literal value like the a key will be 'a' in get_name. Other keys will have a best effort value like the minus key ('-') will be reported as 'minus' in get_name.

Snippet

Get a key currently pressed.
buttons = sketch.get_keyboard().get_keys_pressed()
if len(buttons) > 0:
print(buttons[0].get_name())

Examples

Availability

Available for Sketch2DApp and Sketch2DWeb. Note that, on web, some keys may be intercepted by the operating system like the ctrl key and may not be available to the sketch.

See also