pub enum Event {
Show 13 variants
CloseRequested,
Resized(UVec2),
ScaleFactorChanged(f32),
Focused(bool),
Key {
key: Key,
pressed: bool,
repeat: bool,
},
Text(char),
MouseMoved(Vec2),
MouseButton {
button: MouseButton,
pressed: bool,
},
MouseWheel(Vec2),
GamepadConnected(GamepadId),
GamepadDisconnected(GamepadId),
GamepadButton {
id: GamepadId,
button: GamepadButton,
pressed: bool,
},
GamepadAxis {
id: GamepadId,
axis: GamepadAxis,
value: f32,
},
}Expand description
Something that happened to the window or to an input device.
Events arrive in the order the operating system reported them. The
window’s come from Platform::pump_events,
and the gamepads’ from
Platform::poll_gamepads.
Variants§
CloseRequested
The user asked to close the window. The window stays open: the game decides what happens next.
Resized(UVec2)
The inside of the window has a new size, in physical pixels.
ScaleFactorChanged(f32)
The scale factor is this from now on. One of these comes before any other event.
Focused(bool)
The window gained (true) or lost (false) the keyboard focus.
Right after Focused(false), every key and button that was down gets
a release event, so nothing stays held while the window cannot see it
go up. They come after it, so that a reader can tell them from the
releases the user made: a UI then lets go of a held widget without
taking the release for a click.
Key
A key went down or up.
Fields
Text(char)
A character the user typed, after the key press that typed it.
- One event a character. A character composed of several key presses
(a dead key and a letter, a Compose sequence, an input method’s
choice on Linux and Windows) comes as one event, after the last of
them. Those presses are still
Event::Keys. - A key held down types its character again with each repeat.
- Never a control character: Enter, Tab, Backspace, Escape and Delete
come only as
Event::Keys. - A key pressed with a shortcut’s modifier types nothing. On Linux that is Control, Alt or Super, and Alt Gr types. On Windows it is Control without Alt, which with Control is Alt Gr there, or the Windows key; Alt alone is the window menu’s. On macOS it is ⌘, or Control without Option, and Option types.
- macOS has no input method yet: text that only an input method types (in Chinese or Japanese, say) does not come there.
MouseMoved(Vec2)
The pointer is here now: physical pixels from the top-left corner of the inside of the window, with y growing downward.
MouseButton
A mouse button went down or up.
MouseWheel(Vec2)
The wheel turned, in lines. Positive y is away from the user, and positive x is to the right.
GamepadConnected(GamepadId)
A gamepad was plugged in, or was there when the window opened. It is at rest: what is held on it then follows as button and axis events.
GamepadDisconnected(GamepadId)
A gamepad was unplugged. Before this, it was put back at rest, each button held let go and each axis put back at 0 by events of their own. Its id is never given again.
GamepadButton
A gamepad’s button went down or up.
Fields
Which button, by its place on the pad.
GamepadAxis
A gamepad’s axis has a new value.