SourceClass Modifiers
from egui import Modifiersclass Modifiers:State of the modifier keys. These must be fed to egui.
The best way to compare Modifiers is by using Modifiers.matches_logically or Modifiers.matches_exact.
To access the Modifiers you can use the egui.Context.input function
NOTE: For cross-platform uses, ALT+SHIFT is a bad combination of modifiers as on mac that is how you type special characters, so those key presses are usually not reported to egui.
Constants§
ALT: Final[Modifiers]§
COMMAND: Final[Modifiers]§
CTRL: Final[Modifiers]§
MAC_CMD: Final[Modifiers]§
NONE: Final[Modifiers]§
SHIFT: Final[Modifiers]§
Properties§
@property
def alt(self, /) -> bool§
@alt.setter
def alt(self, /, value: bool) -> None§
@property
def alt_pressed(self, /) -> bool§
@alt_pressed.setter
def alt_pressed(self, /, value: bool) -> None§
@property
def command(self, /) -> bool§
@command.setter
def command(self, /, value: bool) -> None§
@property
def command_pressed(self, /) -> bool§
@command_pressed.setter
def command_pressed(self, /, value: bool) -> None§
@property
def ctrl(self, /) -> bool§
@ctrl.setter
def ctrl(self, /, value: bool) -> None§
@property
def ctrl_pressed(self, /) -> bool§
@ctrl_pressed.setter
def ctrl_pressed(self, /, value: bool) -> None§
@property
def mac_cmd(self, /) -> bool§
@mac_cmd.setter
def mac_cmd(self, /, value: bool) -> None§
@property
def mac_cmd_pressed(self, /) -> bool§
@mac_cmd_pressed.setter
def mac_cmd_pressed(self, /, value: bool) -> None§
@property
def shift(self, /) -> bool§
@shift.setter
def shift(self, /, value: bool) -> None§
@property
def shift_pressed(self, /) -> bool§
@shift_pressed.setter
def shift_pressed(self, /, value: bool) -> None§
Methods§
Sourcedef all(self, /) -> bool§
Sourcedef any(self, /) -> bool§
Sourcedef cmd_ctrl_matches(self, /, pattern: Modifiers) -> bool§
Checks only cmd/ctrl, not alt/shift.
self here are the currently pressed modifiers,
and the argument the pattern we are testing for.
This takes care to properly handle the difference between
egui.Modifiers.ctrl, egui.Modifiers.command and egui.Modifiers.mac_cmd.
Sourcedef command_only(self, /) -> bool§
true if only egui.Modifiers.ctrl or only egui.Modifiers.mac_cmd is pressed.
Sourcedef contains(self, /, query: Modifiers) -> bool§
Whether another set of modifiers is contained in this set of modifiers with proper handling of egui.Modifiers.command.
Sourcedef is_none(self, /) -> bool§
Sourcedef matches_any(self, /, pattern: Modifiers) -> bool§
Check if any of the modifiers match exactly.
Returns true if the same modifier is pressed in self as in pattern,
for at least one modifier.
Behavior:
Sourcedef matches_exact(self, /, pattern: Modifiers) -> bool§
Check for equality but with proper handling of egui.Modifiers.command.
self here are the currently pressed modifiers,
and the argument the pattern we are testing for.
Note that this will require the shift and alt keys match, even though
these modifiers are sometimes required to produce some logical keys.
For instance, to press + on an English keyboard, you need to press shift and =,
but on a Swedish keyboard you can press the dedicated + key.
Therefore, you often want to use egui.Modifiers.matches_logically instead.
Example:
Behavior:
Sourcedef matches_logically(self, /, pattern: Modifiers) -> bool§
Checks that the ctrl/cmd matches, and that the shift/alt of the argument is a subset
of the pressed key (self).
This means that if the pattern has not set shift, then self can have shift set or not.
The reason is that many logical keys require shift or alt on some keyboard layouts.
For instance, in order to press + on an English keyboard, you need to press shift and =,
but a Swedish keyboard has dedicated + key.
So if you want to make a KeyboardShortcut looking for Cmd + +, it makes sense
to ignore the shift key.
Similarly, the Alt key is sometimes used to type special characters.
However, if the pattern (the argument) explicitly requires the shift or alt keys
to be pressed, then they must be pressed.
Example:
Behavior:
Sourcedef plus(self, /, other: Modifiers) -> Modifiers§
Sourcedef shift_only(self, /) -> bool§
Is shift the only pressed button?