SDL Wiki

SDL_EventType

An enumeration of the types of events that can be delivered.

Values

SDL_EVENT_FIRST

do not remove (unused)

Application events

SDL_EVENT_QUIT

user-requested quit; see Remarks for details

Android, iOS and WinRT events; see Remarks for details

SDL_EVENT_TERMINATING

OS is terminating the application

SDL_EVENT_LOW_MEMORY

OS is low on memory; free some

SDL_EVENT_WILL_ENTER_BACKGROUND

application is entering background

SDL_EVENT_DID_ENTER_BACKGROUND

application entered background

SDL_EVENT_WILL_ENTER_FOREGROUND

application is entering foreground

SDL_EVENT_DID_ENTER_FOREGROUND

application entered foreground

Display events

SDL_DISPLAYEVENT

Display state change

Window events

SDL_WINDOWEVENT

window state change

SDL_EVENT_SYSWM

system specific event

Keyboard events

SDL_EVENT_KEY_DOWN

key pressed

SDL_EVENT_KEY_UP

key released

SDL_EVENT_TEXT_EDITING

keyboard text editing (composition)

SDL_EVENT_TEXT_INPUT

keyboard text input

SDL_EVENT_KEYMAP_CHANGED

keymap changed due to a system event such as an input language or keyboard layout change (>= SDL 2.0.4)

Mouse events

SDL_EVENT_MOUSE_MOTION

mouse moved

SDL_EVENT_MOUSE_BUTTON_DOWN

mouse button pressed

SDL_EVENT_MOUSE_BUTTON_UP

mouse button released

SDL_EVENT_MOUSE_WHEEL

mouse wheel motion

Joystick events

SDL_EVENT_JOYSTICK_AXIS_MOTION

joystick axis motion

SDL_EVENT_JOYSTICK_HAT_MOTION

joystick hat position change

SDL_EVENT_JOYSTICK_BUTTON_DOWN

joystick button pressed

SDL_EVENT_JOYSTICK_BUTTON_UP

joystick button released

SDL_EVENT_JOYSTICK_ADDED

joystick connected

SDL_EVENT_JOYSTICK_REMOVED

joystick disconnected

Controller events

SDL_EVENT_GAMEPAD_AXIS_MOTION

controller axis motion

SDL_EVENT_GAMEPAD_BUTTON_DOWN

controller button pressed

SDL_EVENT_GAMEPAD_BUTTON_UP

controller button released

SDL_EVENT_GAMEPAD_ADDED

controller connected

SDL_EVENT_GAMEPAD_REMOVED

controller disconnected

SDL_EVENT_GAMEPAD_REMAPPED

controller mapping updated

Touch events

SDL_EVENT_FINGER_DOWN

user has touched input device

SDL_EVENT_FINGER_UP

user stopped touching input device

SDL_EVENT_FINGER_MOTION

user is dragging finger on input device

Clipboard events

SDL_EVENT_CLIPBOARD_UPDATE

the clipboard changed

Drag and drop events

SDL_EVENT_DROP_FILE

the system requests a file open

SDL_EVENT_DROP_TEXT

text/plain drag-and-drop event

SDL_EVENT_DROP_BEGIN

a new set of drops is beginning (>= SDL 2.0.5)

SDL_EVENT_DROP_COMPLETE

current set of drops is now complete (>= SDL 2.0.5)

Audio hotplug events

SDL_EVENT_AUDIO_DEVICE_ADDED

a new audio device is available (>= SDL 2.0.4)

SDL_EVENT_AUDIO_DEVICE_REMOVED

an audio device has been removed (>= SDL 2.0.4)

Render events

SDL_EVENT_RENDER_TARGETS_RESET

the render targets have been reset and their contents need to be updated (>= SDL 2.0.2)

SDL_EVENT_RENDER_DEVICE_RESET

the device has been reset and all textures need to be recreated (>= SDL 2.0.4)

These are for your use, and should be allocated with SDL_RegisterEvents()

SDL_EVENT_USER

a user-specified event

SDL_EVENT_LAST

only for bounding internal arrays

Code Examples

SDL_Event e;
while (SDL_PollEvent(&e)) {
    if (e.type == SDL_EVENT_KEY_DOWN) {
        SDL_Log("User just pressed down a key!");
    }
}

Remarks

SDL_EVENT_QUIT

SDL_EVENT_QUIT events are generated for a variety of reasons. An application can choose to ignore the event, for example, if it wants to offer a prompt asking the user to save the current work.

An SDL_EVENT_QUIT event is generated when the user clicks on the close button of the last existing window. This happens in addition to the SDL_WINDOWEVENT/SDL_EVENT_WINDOW_CLOSE_REQUESTED event, so the application can check whichever is appropriate, or both, or neither. If the application ignores this event and creates another window, SDL_EVENT_QUIT will be sent again the next time the user clicks on the last remaining window's close button.

SDL_EVENT_QUIT is not limited to window closing. On Mac OS X, pressing Command-Q (the standard keyboard shortcut for "Quit this application") will cause SDL to generate an SDL_EVENT_QUIT event, regardless of what windows exist at the time. The application is still responsible for terminating itself properly, however. Applications that completely ignore Command-Q will fail Mac App Store certification.

On POSIX systems, SDL_Init() installs signal handlers for SIGINT (keyboard interrupt) and SIGTERM (system termination request), if handlers do not already exist, that generate SDL_EVENT_QUIT events as well. There is no way to determine the cause of an SDL_EVENT_QUIT event, but setting a signal handler in your application will override the default generation of quit events for that signal.

Android, iOS and WinRT Events

What we currently label as "Android, iOS and WinRT events" are specific to mobile and embedded devices that have different requirements than your usual desktop application. These events must be handled in an event filter, since often the OS needs an immediate response and will terminate your process shortly after sending the event, and if it sits in the SDL event queue, it'll be too late. You can handle everything else through a normal SDL_PollEvent() loop, but you should set up a callback with SDL_SetEventFilter() for these specific events.

This is how these events currently map to the underlying OS:

SDL event

What

iOS

Android

WinRT

SDL_EVENT_TERMINATING

The application is being terminated by the OS.

applicationWillTerminate()

onDestroy()

Exiting()

SDL_EVENT_LOW_MEMORY

The application is low on memory, free memory if possible.

applicationDidReceiveMemoryWarning()

onLowMemory()

--

SDL_EVENT_WILL_ENTER_BACKGROUND

The application is about to enter the background.

applicationWillResignActive()

onPause()

Suspending()

SDL_EVENT_DID_ENTER_BACKGROUND

The application did enter the background and may not get CPU for some time.

applicationDidEnterBackground()

onPause()

Suspending()

SDL_EVENT_WILL_ENTER_FOREGROUND

The application is about to enter the foreground.

applicationWillEnterForeground()

onResume()

Resuming()

SDL_EVENT_DID_ENTER_FOREGROUND

The application is now interactive.

applicationDidBecomeActive()

onResume()

Resuming()

SDL_JoyAxisEvent
SDL_JoyButtonEvent
SDL_JoyHatEvent
SDL_JoyDeviceEvent
SDL_GamepadAxisEvent
SDL_GamepadButtonEvent
SDL_GamepadDeviceEvent
SDL_KeyboardEvent
SDL_MouseButtonEvent
SDL_MouseMotionEvent
SDL_MouseWheelEvent
SDL_QuitEvent
SDL_SysWMEvent
SDL_TextEditingEvent
SDL_TextInputEvent
SDL_UserEvent
SDL_WindowEvent
SDL_DropEvent
SDL_AudioDeviceEvent
SDL_TouchFingerEvent
SDL_PollEvent
SDL_SetEventFilter

CategoryEnum, CategoryEvents


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.