OCamlSDL 0.9.1 : Sdlevent

# Module Sdlevent

    module Sdlevent: sig .. end

SDL event handling

    exception Event_exn of string

The exception used for reporting events-related errors.

### Application focus

`type ``active_state =`

`|` | `MOUSEFOCUS` | `(*` | The app has mouse coverage | `*)`
`|` | `INPUTFOCUS` | `(*` | The app has input focus | `*)`
`|` | `APPACTIVE` | `(*` | The application is active | `*)`

The available application states

    val get_app_state : unit -> active_state list

This function returns the current state of the application. If ACTIVE is set, then the user is able to see your application, otherwise it has been iconified or disabled.

### Events datatypes

`type ``active_event = {`

`` | `gain : `bool`;` | `(*` | Whether given states were gained or lost | `*)`
`` | `ae_state : `active_state list`;` | `(*` | A list of the focus states | `*)`

}
Application visibility event record
`type ``switch_state =`

`|` | `RELEASED`
`|` | `PRESSED`

`type ``keyboard_event = {`

`` | `ke_which : `int`;` | `(*` | The keyboard device index | `*)`
`` | `ke_state : `switch_state`;` | `(*` | PRESSED or RELEASED | `*)`
`` | `keysym : `Sdlkey.t`;` | `(*` | SDL virtual keysym | `*)`
`` | `keymod : `Sdlkey.mod_state`;` | `(*` | current key modifiers | `*)`
`` | `keycode : `char`;` | `(*` | translated character | `*)`
`` | `unicode : `int`;`

}
Keyboard event record
`type ``mousemotion_event = {`

`` | `mme_which : `int`;` | `(*` | The mouse device index | `*)`
`` | `mme_state : `Sdlmouse.button list`;` | `(*` | The current button state | `*)`
`` | `mme_x : `int`;` | `(*` | The X/Y coordinates of the mouse | `*)`
`` | `mme_y : `int`;`
`` | `mme_xrel : `int`;` | `(*` | The relative motion in the X direction | `*)`
`` | `mme_yrel : `int`;` | `(*` | The relative motion in the Y direction | `*)`

}
Mouse motion event record
`type ``mousebutton_event = {`

`` | `mbe_which : `int`;` | `(*` | The mouse device index | `*)`
`` | `mbe_button : `Sdlmouse.button`;` | `(*` | The mouse button index | `*)`
`` | `mbe_state : `switch_state`;` | `(*` | PRESSED or RELEASED | `*)`
`` | `mbe_x : `int`;` | `(*` | The X/Y coordinates of the mouse at press time | `*)`
`` | `mbe_y : `int`;`

}
Mouse button event record
`type ``joyaxis_event = {`

`` | `jae_which : `int`;` | `(*` | The joystick device index | `*)`
`` | `jae_axis : `int`;` | `(*` | The joystick axis index | `*)`
`` | `jae_value : `int`;` | `(*` | The axis value (range: -32768 to 32767) | `*)`

}
Joystick axis motion event record
`type ``joyball_event = {`

`` | `jle_which : `int`;` | `(*` | The joystick device index | `*)`
`` | `jle_ball : `int`;` | `(*` | The joystick trackball index | `*)`
`` | `jle_xrel : `int`;` | `(*` | The relative motion in the X direction | `*)`
`` | `jle_yrel : `int`;` | `(*` | The relative motion in the Y direction | `*)`

}
Joystick axis motion event record
`type ``joyhat_event = {`

`` | `jhe_which : `int`;` | `(*` | The joystick device index | `*)`
`` | `jhe_hat : `int`;` | `(*` | The joystick hat index | `*)`
`` | `jhe_value : `int`;` | `(*` | The hat position value:
                              8   1   2
                              7   0   3
                              6   5   4
Note that zero means the POV is centered. | `*)`

}
Joystick hat position change event record
`type ``joybutton_event = {`

`` | `jbe_which : `int`;` | `(*` | The joystick device index | `*)`
`` | `jbe_button : `int`;` | `(*` | The joystick button index | `*)`
`` | `jbe_state : `switch_state`;` | `(*` | PRESSED or RELEASED | `*)`

}
Joystick button event record
`type ``event =`

`|` | `ACTIVE of `active_event`` | `(*` | Application loses/gains visibility | `*)`
`|` | `KEYDOWN of `keyboard_event`` | `(*` | Keys pressed | `*)`
`|` | `KEYUP of `keyboard_event`` | `(*` | Keys released | `*)`
`|` | `MOUSEMOTION of `mousemotion_event`` | `(*` | Mouse moved | `*)`
`|` | `MOUSEBUTTONDOWN of `mousebutton_event`` | `(*` | Mouse button pressed | `*)`
`|` | `MOUSEBUTTONUP of `mousebutton_event`` | `(*` | Mouse button released | `*)`
`|` | `JOYAXISMOTION of `joyaxis_event`` | `(*` | Joystick axis motion | `*)`
`|` | `JOYBALLMOTION of `joyball_event`` | `(*` | Joystick trackball motion | `*)`
`|` | `JOYHATMOTION of `joyhat_event`` | `(*` | Joystick hat position change | `*)`
`|` | `JOYBUTTONDOWN of `joybutton_event`` | `(*` | Joystick button pressed | `*)`
`|` | `JOYBUTTONUP of `joybutton_event`` | `(*` | Joystick button released | `*)`
`|` | `QUIT` | `(*` | User-requested quit | `*)`
`|` | `SYSWM` | `(*` | System specific event | `*)`
`|` | `VIDEORESIZE of `int * int`` | `(*` | User resized video mode | `*)`
`|` | `VIDEOEXPOSE` | `(*` | Screen needs to be redrawn | `*)`
`|` | `USER of `int`` | `(*` | for your use ! | `*)`

The main event type

    val string_of_event : event -> string

Returns a short string descriptive of the event type, for debugging

### Event masks

    type event_mask = int

Event masks values are ints and should be manipulated with `lor`, `land`, etc.

    val active_mask : event_mask

    val keydown_mask : event_mask

    val keyup_mask : event_mask

    val mousemotion_mask : event_mask

    val mousebuttondown_mask : event_mask

    val mousebuttonup_mask : event_mask

    val joyaxismotion_mask : event_mask

    val joyballmotion_mask : event_mask

    val joyhatmotion_mask : event_mask

    val joybuttondown_mask : event_mask

    val joybuttonup_mask : event_mask

    val quit_mask : event_mask

    val syswmevent_mask : event_mask

    val videoresize_mask : event_mask

    val videoexpose_mask : event_mask

    val userevent_mask : event_mask

    val keyboard_event_mask : event_mask

    val mouse_event_mask : event_mask

    val joystick_event_mask : event_mask

    val all_events_mask : event_mask

`type ``event_kind =`

`|` | `ACTIVE_EVENT`
`|` | `KEYDOWN_EVENT`
`|` | `KEYUP_EVENT`
`|` | `MOUSEMOTION_EVENT`
`|` | `MOUSEBUTTONDOWN_EVENT`
`|` | `MOUSEBUTTONUP_EVENT`
`|` | `JOYAXISMOTION_EVENT`
`|` | `JOYBALL_EVENT`
`|` | `JOYHAT_EVENT`
`|` | `JOYBUTTONDOWN_EVENT`
`|` | `JOYBUTTONUP_EVENT`
`|` | `QUIT_EVENT`
`|` | `SYSWM_EVENT`
`|` | `RESIZE_EVENT`
`|` | `EXPOSE_EVENT`
`|` | `USER_EVENT`

    val make_mask : event_kind list -> event_mask

    val of_mask : event_mask -> event_kind list

### Enabling/Disabling event collecting

    val enable_events : event_mask -> unit

Specified events are collected and added to the event queue (when `pump` is called).

    val disable_events : event_mask -> unit

Specified events are not collected and won't appear in the event queue.

    val get_enabled_events : unit -> event_mask

The mask of currently reported events.

    val get_state : event_kind -> bool

Query the reporting state of an event type.

    val set_state : bool -> event_kind -> unit

Set the reporting state of one individual event type.

### Handling events

    val pump : unit -> unit

Pumps 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 sets the video mode.

    val wait_event : unit -> event

Wait indefinitely for the next available event and return it.

    val wait : unit -> unit

Wait indefinitely for the next available event but leave it in the queue.

    val poll : unit -> event option

Poll for currently pending events and return one if available.

    val has_event : unit -> bool

Poll for currently pending events and return `false` if the queue is empty.

    val peek : ?mask:event_mask -> int -> event list

Checks the event queue for messages : up to 'numevents' events at the front of the event queue, matching 'mask', will be returned and will not be removed from the queue.

    val get : ?mask:event_mask -> int -> event list

Checks the event queue for messages : up to 'numevents' events at the front of the event queue, matching 'mask', will be returned and will be removed from the queue.

    val add : event list -> unit

Add events to the back of the event queue.

### Old event-handling interface

    module Old: sig .. end

Callback-based event handling.