MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / KeyEvent

Class KeyEvent

lib/matplotlib/backend_bases.py:1497–1547  ·  view source on GitHub ↗

A key event (key press, key release). A KeyEvent has a number of special attributes in addition to those defined by the parent `Event` and `LocationEvent` classes. Attributes ---------- key : None or str The key(s) pressed. Could be *None*, a single case sensitive

Source from the content-addressed store, hash-verified

1495
1496
1497class KeyEvent(LocationEvent):
1498 """
1499 A key event (key press, key release).
1500
1501 A KeyEvent has a number of special attributes in addition to those defined
1502 by the parent `Event` and `LocationEvent` classes.
1503
1504 Attributes
1505 ----------
1506 key : None or str
1507 The key(s) pressed. Could be *None*, a single case sensitive Unicode
1508 character ("g", "G", "#", etc.), a special key ("control", "shift",
1509 "f1", "up", etc.) or a combination of the above (e.g., "ctrl+alt+g",
1510 "ctrl+alt+G").
1511
1512 Notes
1513 -----
1514 Modifier keys will be prefixed to the pressed key and will be in the order
1515 "ctrl", "alt", "super". The exception to this rule is when the pressed key
1516 is itself a modifier key, therefore "ctrl+alt" and "alt+control" can both
1517 be valid key values.
1518
1519 Examples
1520 --------
1521 ::
1522
1523 def on_key(event):
1524 print('you pressed', event.key, event.xdata, event.ydata)
1525
1526 cid = fig.canvas.mpl_connect('key_press_event', on_key)
1527 """
1528
1529 def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
1530 super().__init__(name, canvas, x, y, guiEvent=guiEvent)
1531 self.key = key
1532
1533 @classmethod
1534 def _from_ax_coords(cls, name, ax, xy, key, *args, **kwargs):
1535 """
1536 Generate a synthetic event at a given axes coordinate.
1537
1538 This method is intended for creating events during testing. The event
1539 can be emitted by calling its ``_process()`` method.
1540 """
1541 # Separate from MouseEvent._from_ax_coords instead of being defined in the base
1542 # class, due to different parameter order in the constructor signature.
1543 x, y = ax.transData.transform(xy)
1544 event = cls(name, ax.figure.canvas, key, x, y, *args, **kwargs)
1545 event.inaxes = ax
1546 event.xdata, event.ydata = xy # Force exact xy to avoid fp roundtrip issues.
1547 return event
1548
1549
1550# Default callback for key events.

Callers 15

_handle_keyMethod · 0.90
key_pressMethod · 0.90
key_releaseMethod · 0.90
key_press_eventMethod · 0.90
key_release_eventMethod · 0.90
_on_key_downMethod · 0.90
_on_key_upMethod · 0.90
keyPressEventMethod · 0.90
keyReleaseEventMethod · 0.90
key_press_eventMethod · 0.90
key_release_eventMethod · 0.90
test_rectangle_rotateFunction · 0.90

Calls

no outgoing calls

Tested by 9

test_rectangle_rotateFunction · 0.72
test_selector_clearFunction · 0.72
test_TextBoxFunction · 0.72
test_polygon_selectorFunction · 0.72
test_pickFunction · 0.72
multi_pressesFunction · 0.72
test_waitforbuttonpressFunction · 0.72
_test_interactive_implFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…