Module OcsfmlWindow.Event

module Event: sig .. end
Defines a system event and its parameters.

Event.t holds all the informations about a system event that just happened.

Events are retrieved using the Window.poll_event and Window.wait_event functions.

A Event.t instance contains the type of the event (mouse moved, key pressed, window closed, ...) as well as the details about this particular event.

Usage example:

    
    let rec poll_events window =
      let open OcsfmlWindow.Event in
      match window#poll_event with
        | Some e -> 
           begin match e with
             | Closed -> window#close
             | KeyPressed { code = KeyCode.Escape ; _ } ->
                 window#close
             | Resized { width ; height } -> 
                 do_something_with_the_new_size width height 
           end ;
           poll_events window 
        | None -> ()
    in poll_events my_window
    


type mouseButton = 
| LeftButton
| RightButton
| MiddleButton
| XButton1
| XButton2
| MouseButtonCount
type sizeEvent = {
   width : int; (*New width, in pixels.*)
   height : int; (*New height, in pixels.*)
}
Size events parameters (Resized)

Keyboard event parameters (KeyPressed, KeyReleased)

type keyEvent = {
   code : OcsfmlWindow.KeyCode.t; (*Code of the key that has been pressed.*)
   alt : bool; (*Is the Alt key pressed?*)
   control : bool; (*Is the Control key pressed?*)
   shift : bool; (*Is the Shift key pressed?*)
   system : bool; (*Is the System key pressed?*)
}
type textEvent = {
   unicode : int; (*UTF-32 unicode value of the character.*)
}
Text event parameters (TextEntered)
type mouseCoord = {
   x : int;
   y : int;
}
type mouseMoveEvent = mouseCoord 
Mouse move event parameters (MouseMoved)

coordinates of the mouse pointer

type mouseButtonEvent = mouseButton * mouseCoord 
Mouse buttons events parameters (MouseButtonPressed, MouseButtonReleased)

Code of the button that has been pressed and coordinates of the mouse pointer

type mouseWheelEvent = int * mouseCoord 
Mouse wheel events parameters (MouseWheelMoved)

Number of ticks the wheel has moved (positive is up, negative is down) and coordinates of the mouse pointer

type joystickConnectEvent = OcsfmlWindow.Joystick.id 
Joystick connection events parameters (JoystickConnected, JoystickDisconnected)

Index of the joystick (in range 0 .. Joystick.count - 1)

type joystickMoveEvent = OcsfmlWindow.Joystick.id * OcsfmlWindow.Joystick.axis * float 
Joystick axis move event parameters (JoystickMoved)

Index of the joystick (in range 0 .. Joystick.count - 1), axis on which the joystick moved and new position on the axis (in range -100 .. 100)

type joystickButtonEvent = OcsfmlWindow.Joystick.id * int 
Joystick buttons events parameters (JoystickButtonPressed, JoystickButtonReleased)

Index of the joystick (in range 0 .. Joystick.count - 1) and index of the joystick (in range 0 .. Joystick.count - 1)

type t = 
| Closed (*The window requested to be closed.*)
| LostFocus (*The window lost the focus.*)
| GainedFocus (*The window gained the focus.*)
| Resized of sizeEvent (*The window was resized.*)
| TextEntered of textEvent (*A character was entered.*)
| KeyPressed of keyEvent (*A key was pressed.*)
| KeyReleased of keyEvent (*A key was released.*)
| MouseWheelMoved of mouseWheelEvent (*The mouse wheel was scrolled.*)
| MouseButtonPressed of mouseButtonEvent (*A mouse button was pressed.*)
| MouseButtonReleased of mouseButtonEvent (*A mouse button was released.*)
| MouseMoved of mouseMoveEvent (*The mouse cursor moved.*)
| MouseEntered (*The mouse cursor entered the area of the window.*)
| MouseLeft (*The mouse cursor left the area of the window.*)
| JoystickButtonPressed of joystickButtonEvent (*A joystick button was pressed.*)
| JoystickButtonReleased of joystickButtonEvent (*A joystick button was released.*)
| JoystickMoved of joystickMoveEvent (*The joystick moved along an axis.*)
| JoystickConnected of joystickConnectEvent (*A joystick was connected.*)
| JoystickDisconnected of joystickConnectEvent (*A joystick was disconnected.*)
Enumeration of the different types of events.