S or /

SourceClass InputState

from egui import InputState
class InputState:

Input state that egui updates each frame.

You can access this with egui.Context.input.

You can check if egui is using the inputs using egui.Context.egui_wants_pointer_input and egui.Context.egui_wants_keyboard_input.

Properties§

Source@property def content_rect(self, /) -> Rect§

Returns the region of the screen that is safe for content rendering

Returns the viewport_rect with the safe_area_insets removed.

If you want to render behind e.g. the dynamic island on iOS, use egui.InputState.viewport_rect.

See also RawInput.safe_area_insets.

@property def focused(self, /) -> bool§
@focused.setter def focused(self, /, focused: bool) -> None§
@property def max_texture_side(self, /) -> int§
@max_texture_side.setter def max_texture_side(self, /, max_texture_side: int) -> None§
@property def modifiers(self, /) -> Modifiers§
@modifiers.setter def modifiers(self, /, modifiers: Modifiers) -> None§
Source@property def pixels_per_point(self, /) -> float§

Also known as device pixel ratio, > 1 for high resolution screens.

@pixels_per_point.setter def pixels_per_point(self, /, pixels_per_point: float) -> None§
@property def pointer(self, /) -> PointerState§
@pointer.setter def pointer(self, /, pointer: PointerState) -> None§
@property def predicted_dt(self, /) -> float§
@predicted_dt.setter def predicted_dt(self, /, predicted_dt: float) -> None§
@property def raw(self, /) -> RawInput§
@raw.setter def raw(self, /, raw: RawInput) -> None§
@property def raw_scroll_delta(self, /) -> Vec2§
@raw_scroll_delta.setter def raw_scroll_delta(self, /, raw_scroll_delta: Vec2) -> None§
Source@property def safe_area_insets(self, /) -> SafeAreaInsets§

Get the safe area insets.

This represents the area of the screen covered by status bars, navigation controls, notches, or other items that obscure part of the screen.

See egui.InputState.content_rect to get the viewport_rect with the safe area insets removed.

@safe_area_insets.setter def safe_area_insets(self, /, safe_area_insets: SafeAreaInsets) -> None§
@property def screen_rect(self, /) -> Rect§
@screen_rect.setter def screen_rect(self, /, screen_rect: Rect) -> None§
Source@property def smooth_scroll_delta(self, /) -> Vec2§

How many points the user scrolled, smoothed over a few frames.

The delta dictates how the content should move.

A positive X-value indicates the content is being moved right, as when swiping right on a touch-screen or track-pad with natural scrolling.

A positive Y-value indicates the content is being moved down, as when swiping down on a touch-screen or track-pad with natural scrolling.

egui.ScrollArea will both read and write to this field, so that at the end of the frame this will be zero if a scroll-area consumed the delta.

@smooth_scroll_delta.setter def smooth_scroll_delta(self, /, smooth_scroll_delta: Vec2) -> None§
@property def stable_dt(self, /) -> float§
@stable_dt.setter def stable_dt(self, /, stable_dt: float) -> None§
@property def time(self, /) -> float§
@time.setter def time(self, /, time: float) -> None§
@property def unstable_dt(self, /) -> float§
@unstable_dt.setter def unstable_dt(self, /, unstable_dt: float) -> None§
Source@property def viewport_rect(self, /) -> Rect§

Returns the full area available to egui, including parts that might be partially covered, for example, by the OS status bar or notches (see egui.InputState.safe_area_insets).

Usually you want to use egui.InputState.content_rect instead.

This rectangle includes e.g. the dynamic island on iOS. If you want to only render below the that (not behind), then you should use egui.InputState.content_rect instead.

See also RawInput.safe_area_insets.

@viewport_rect.setter def viewport_rect(self, /, viewport_rect: Rect) -> None§

Methods§

Sourcedef aim_radius(self, /) -> float§

How imprecise do we expect the mouse/touch input to be? Returns imprecision in points.

Sourcedef any_touches(self, /) -> bool§

True if there currently are any fingers touching egui.

Sourcedef consume_key(self, /, modifiers: Modifiers, key: Key) -> bool§

Check for a key press. If found, True is returned and the key pressed is consumed, so that this will only return True once.

Includes key-repeat events.

This uses Modifiers.matches_logically to match modifiers, meaning extra Shift and Alt modifiers are ignored. Therefore, you should match most specific shortcuts first, i.e. check for Cmd-Shift-S ("Save as…") before Cmd-S ("Save"), so that a user pressing Cmd-Shift-S won't trigger the wrong command!

Sourcedef consume_shortcut(self, /, shortcut: KeyboardShortcut) -> bool§

Check if the given shortcut has been pressed.

If so, True is returned and the key pressed is consumed, so that this will only return True once.

This uses Modifiers.matches_logically to match modifiers, meaning extra Shift and Alt modifiers are ignored. Therefore, you should match most specific shortcuts first, i.e. check for Cmd-Shift-S ("Save as…") before Cmd-S ("Save"), so that a user pressing Cmd-Shift-S won't trigger the wrong command!

Sourcedef count_and_consume_key(self, /, modifiers: Modifiers, key: Key) -> int§

Count presses of a key. If non-zero, the presses are consumed, so that this will only return non-zero once.

Includes key-repeat events.

This uses Modifiers.matches_logically to match modifiers, meaning extra Shift and Alt modifiers are ignored. Therefore, you should match most specific shortcuts first, i.e. check for Cmd-Shift-S ("Save as…") before Cmd-S ("Save"), so that a user pressing Cmd-Shift-S won't trigger the wrong command!

@staticmethod def default() -> InputState§
def events(self, /) -> list[Event]§
def events_len(self, /) -> int§
Sourcedef filtered_events(self, /, filter: EventFilter) -> list[Event]§

Get all events that matches the given filter.

Sourcedef has_touch_screen(self, /) -> bool§

True if we have ever received a touch event.

Sourcedef is_scrolling(self, /) -> bool§

True if there is an active scroll action that might scroll more when using egui.InputState.smooth_scroll_delta.

Sourcedef key_down(self, /, key: Key) -> bool§

Is the given key currently held down?

Keys released this frame are NOT considered down.

Sourcedef key_pressed(self, /, key: Key) -> bool§

Was the given key pressed this frame?

Includes key-repeat events.

Sourcedef key_released(self, /, key: Key) -> bool§

Was the given key released this frame?

def keys_down(self, /) -> list[Key]§
Sourcedef multi_touch(self, /) -> MultiTouchInfo |None§

Returns details about the currently ongoing multi-touch gesture, if any. Note that this method returns None for single-touch gestures (click, drag, …).

By far not all touch devices are supported, and the details depend on the egui integration backend you are using. eframe web supports multi touch for most mobile devices, but not for a Trackpad on MacOS, for example. The backend has to be able to capture native touch events, but many browsers seem to pass such events only for touch screens, but not touch pads.

Refer to MultiTouchInfo for details about the touch information available.

Consider using zoom_delta() instead of MultiTouchInfo.zoom_delta as the former delivers a synthetic zoom factor based on ctrl-scroll events, as a fallback.

Sourcedef num_presses(self, /, key: Key) -> int§

How many times was the given key pressed this frame?

Includes key-repeat events.

Sourcedef physical_pixel_size(self, /) -> float§

Size of a physical pixel in logical gui coordinates (points).

Sourcedef rotation_delta(self, /) -> float§

Rotation in radians this frame, measuring clockwise (e.g. from a rotation gesture).

def set_keys_down(self, /, keys_down: Sequence[Key]) -> None§
Sourcedef time_since_last_scroll(self, /) -> float§

How long has it been (in seconds) since the last scroll event?

Sourcedef translation_delta(self, /) -> Vec2§

Panning translation in pixels this frame (e.g. from scrolling or a pan gesture)

The delta indicates how the content should move.

A positive X-value indicates the content is being moved right, as when swiping right on a touch-screen or track-pad with natural scrolling.

A positive Y-value indicates the content is being moved down, as when swiping down on a touch-screen or track-pad with natural scrolling.

Sourcedef viewport(self, /) -> ViewportInfo§

Info about the active viewport

def viewport_close_requested(self, /) -> bool§
Sourcedef zoom_delta(self, /) -> float§

Uniform zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture). * zoom = 1: no change * zoom < 1: pinch together * zoom > 1: pinch spread

If your application supports non-proportional zooming, then you probably want to use egui.InputState.zoom_delta_2d instead.

Sourcedef zoom_delta_2d(self, /) -> Vec2§

2D non-proportional zoom scale factor this frame (e.g. from ctrl-scroll or pinch gesture).

For multitouch devices the user can do a horizontal or vertical pinch gesture. In these cases a non-proportional zoom factor is a available. In other cases, this reverts to Vec2.splat(self.zoom_delta()).

For horizontal pinches, this will return [z, 1], for vertical pinches this will return [1, z], and otherwise this will return [z, z], where z is the zoom factor: * zoom = 1: no change * zoom < 1: pinch together * zoom > 1: pinch spread