sdl2-2.1.0: Both high- and low-level bindings to the SDL library (version 2.0.3).

Safe HaskellNone
LanguageHaskell2010

SDL.Event

Contents

Description

SDL.Event exports an interface for working with the SDL event model. Event handling allows your application to receive input from the user. Internally, SDL stores all the events waiting to be handled in an event queue. Using functions like pollEvent and waitEvent you can observe and handle waiting input events.

The event queue itself is composed of a series of Event values, one for each waiting event. Event values are read from the queue with the pollEvent function and it is then up to the application to process the information stored with them.

Synopsis

Polling events

pollEvent :: MonadIO m => m (Maybe Event) Source

Poll for currently pending events. You can only call this function in the thread that set the video mode.

pollEvents :: (Functor m, MonadIO m) => m [Event] Source

Clear the event queue by polling for all pending events.

mapEvents :: MonadIO m => (Event -> m ()) -> m () Source

Run a monadic computation, accumulating over all known Events.

This can be useful when used with a state monad, allowing you to fold all events together.

pumpEvents :: MonadIO m => m () Source

Pump the event loop, gathering events from the input devices.

This function updates the event queue and internal input device state.

This should only be run in the thread that initialized the video subsystem, and for extra safety, you should consider only doing those things on the main thread in any case.

pumpEvents gathers all the pending input information from devices and places it in the event queue. Without calls to pumpEvents no events would ever be placed on the queue. Often the need for calls to pumpEvents is hidden from the user since pollEvent and waitEvent implicitly call pumpEvents. However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call pumpEvents to force an event queue update.

See SDL_PumpEvents for C documentation.

waitEvent :: MonadIO m => m Event Source

Wait indefinitely for the next available event.

waitEventTimeout Source

Arguments

:: MonadIO m 
=> CInt

The maximum amount of time to wait, in milliseconds.

-> m (Maybe Event) 

Wait until the specified timeout for the next available amount.

Event data

data Event Source

A single SDL event. This event occured at eventTimestamp and carries data under eventPayload.

Constructors

Event 

Fields

eventTimestamp :: Word32

The time the event occured.

eventPayload :: EventPayload

Data pertaining to this event.

data EventPayload Source

An enumeration of all possible SDL event types. This data type pairs up event types with their payload, where possible.

Constructors

WindowShownEvent WindowShownEventData 
WindowHiddenEvent WindowHiddenEventData 
WindowExposedEvent WindowExposedEventData 
WindowMovedEvent WindowMovedEventData 
WindowResizedEvent WindowResizedEventData 
WindowSizeChangedEvent WindowSizeChangedEventData 
WindowMinimizedEvent WindowMinimizedEventData 
WindowMaximizedEvent WindowMaximizedEventData 
WindowRestoredEvent WindowRestoredEventData 
WindowGainedMouseFocusEvent WindowGainedMouseFocusEventData 
WindowLostMouseFocusEvent WindowLostMouseFocusEventData 
WindowGainedKeyboardFocusEvent WindowGainedKeyboardFocusEventData 
WindowLostKeyboardFocusEvent WindowLostKeyboardFocusEventData 
WindowClosedEvent WindowClosedEventData 
KeyboardEvent KeyboardEventData 
TextEditingEvent TextEditingEventData 
TextInputEvent TextInputEventData 
MouseMotionEvent MouseMotionEventData 
MouseButtonEvent MouseButtonEventData 
MouseWheelEvent MouseWheelEventData 
JoyAxisEvent JoyAxisEventData 
JoyBallEvent JoyBallEventData 
JoyHatEvent JoyHatEventData 
JoyButtonEvent JoyButtonEventData 
JoyDeviceEvent JoyDeviceEventData 
ControllerAxisEvent ControllerAxisEventData 
ControllerButtonEvent ControllerButtonEventData 
ControllerDeviceEvent ControllerDeviceEventData 
QuitEvent 
UserEvent UserEventData 
SysWMEvent SysWMEventData 
TouchFingerEvent TouchFingerEventData 
MultiGestureEvent MultiGestureEventData 
DollarGestureEvent DollarGestureEventData 
DropEvent DropEventData 
ClipboardUpdateEvent ClipboardUpdateEventData 
UnknownEvent UnknownEventData 

Window events

data WindowExposedEventData Source

A part of a window has been exposed - where exposure means to become visible (for example, an overlapping window no longer overlaps with the window).

Constructors

WindowExposedEventData 

Fields

windowExposedEventWindow :: Window

The associated Window.

data WindowSizeChangedEventData Source

The window size has changed, either as a result of an API call or through the system or user changing the window size; this event is followed by WindowResizedEvent if the size was changed by an external event, i.e. the user or the window manager.

Keyboard events

data KeyboardEventData Source

A keyboard key has been pressed or released.

Constructors

KeyboardEventData 

Fields

keyboardEventWindow :: Window

The associated Window.

keyboardEventKeyMotion :: InputMotion

Whether the key was pressed or released.

keyboardEventRepeat :: Bool

True if this is a repeating key press from the user holding the key down.

keyboardEventKeysym :: Keysym

A description of the key that this event pertains to.

data TextEditingEventData Source

Keyboard text editing event information.

Constructors

TextEditingEventData 

Fields

textEditingEventWindow :: Window

The associated Window.

textEditingEventText :: Text

The editing text.

textEditingEventStart :: Int32

The location to begin editing from.

textEditingEventLength :: Int32

The number of characters to edit from the start point.

Mouse events

data MouseMotionEventData Source

A mouse or pointer device was moved.

Constructors

MouseMotionEventData 

Fields

mouseMotionEventWindow :: Window

The associated Window.

mouseMotionEventWhich :: MouseDevice

The MouseDevice that was moved.

mouseMotionEventState :: [MouseButton]

A collection of MouseButtons that are currently held down.

mouseMotionEventPos :: Point V2 Int32

The new position of the mouse.

mouseMotionEventRelMotion :: V2 Int32

The relative mouse motion of the mouse.

data MouseButtonEventData Source

A mouse or pointer device button was pressed or released.

Constructors

MouseButtonEventData 

Fields

mouseButtonEventWindow :: Window

The associated Window.

mouseButtonEventMotion :: InputMotion

Whether the button was pressed or released.

mouseButtonEventWhich :: MouseDevice

The MouseDevice whose button was pressed or released.

mouseButtonEventButton :: MouseButton

The button that was pressed or released.

mouseButtonEventClicks :: Word8

The amount of clicks. 1 for a single-click, 2 for a double-click, etc.

mouseButtonEventPos :: Point V2 Int32

The coordinates of the mouse click.

Joystick events

data JoyAxisEventData Source

Joystick axis motion event information

Constructors

JoyAxisEventData 

Fields

joyAxisEventWhich :: JoystickID

The instance id of the joystick that reported the event.

joyAxisEventAxis :: Word8

The index of the axis that changed.

joyAxisEventValue :: Int16

The current position of the axis, ranging between -32768 and 32767.

data JoyBallEventData Source

Joystick trackball motion event information.

Constructors

JoyBallEventData 

Fields

joyBallEventWhich :: JoystickID

The instance id of the joystick that reported the event.

joyBallEventBall :: Word8

The index of the trackball that changed.

joyBallEventRelMotion :: V2 Int16

The relative motion of the trackball.

data JoyHatEventData Source

Joystick hat position change event information

Constructors

JoyHatEventData 

Fields

joyHatEventWhich :: JoystickID

The instance id of the joystick that reported the event.

joyHatEventHat :: Word8

The index of the hat that changed.

joyHatEventValue :: Word8

The new position of the hat.

data JoyButtonEventData Source

Joystick button event information.

Constructors

JoyButtonEventData 

Fields

joyButtonEventWhich :: JoystickID

The instance id of the joystick that reported the event.

joyButtonEventButton :: Word8

The index of the button that changed.

joyButtonEventState :: Word8

The state of the button.

data JoyDeviceEventData Source

Joystick device event information.

Constructors

JoyDeviceEventData 

Fields

joyDeviceEventWhich :: Int32

The instance id of the joystick that reported the event.

Controller events

data ControllerAxisEventData Source

Game controller axis motion event information.

Constructors

ControllerAxisEventData 

Fields

controllerAxisEventWhich :: JoystickID

The joystick instance ID that reported the event.

controllerAxisEventAxis :: Word8

The index of the axis.

controllerAxisEventValue :: Int16

The axis value ranging between -32768 and 32767.

User events

data UserEventData Source

Event data for application-defined events.

Constructors

UserEventData 

Fields

userEventWindow :: Window

The associated Window.

userEventCode :: Int32

User defined event code.

userEventData1 :: Ptr ()

User defined data pointer.

userEventData2 :: Ptr ()

User defined data pointer.

Touch events

data TouchFingerEventData Source

Finger touch event information.

Constructors

TouchFingerEventData 

Fields

touchFingerEventTouchID :: TouchID

The touch device index.

touchFingerEventFingerID :: FingerID

The finger index.

touchFingerEventPos :: Point V2 CFloat

The location of the touch event, normalized between 0 and 1.

touchFingerEventRelMotion :: V2 CFloat

The distance moved, normalized between -1 and 1.

touchFingerEventPressure :: CFloat

The quantity of the pressure applied, normalized between 0 and 1.

Gesture events

data MultiGestureEventData Source

Multiple finger gesture event information

Constructors

MultiGestureEventData 

Fields

multiGestureEventTouchID :: TouchID

The touch device index.

multiGestureEventDTheta :: CFloat

The amount that the fingers rotated during this motion.

multiGestureEventDDist :: CFloat

The amount that the fingers pinched during this motion.

multiGestureEventPos :: Point V2 CFloat

The normalized center of the gesture.

multiGestureEventNumFingers :: Word16

The number of fingers used in this gesture.

data DollarGestureEventData Source

Complex gesture event information.

Constructors

DollarGestureEventData 

Fields

dollarGestureEventTouchID :: TouchID

The touch device index.

dollarGestureEventGestureID :: GestureID

The unique id of the closest gesture to the performed stroke.

dollarGestureEventNumFingers :: Word32

The number of fingers used to draw the stroke.

dollarGestureEventError :: CFloat

The difference between the gesture template and the actual performed gesture (lower errors correspond to closer matches).

dollarGestureEventPos :: Point V2 CFloat

The normalized center of the gesture.

Drag and drop events

data DropEventData Source

An event used to request a file open by the system

Constructors

DropEventData 

Fields

dropEventFile :: CString

The file name.

Clipboard events

Unknown events

Auxiliary event data