Module OcsfmlWindow.Joystick

module Joystick: sig .. end
Give access to the real-time state of the joysticks.

Joystick provides an interface to the state of the joysticks.

It only contains static functions, so it's not meant to be instanciated. Instead, each joystick is identified by an index that is passed to the functions of this class.

This class allows users to query the state of joysticks at any time and directly, without having to deal with a window and its events. Compared to the JoystickMoved, JoystickButtonPressed and JoystickButtonReleased events, Joystick can retrieve the state of axes and buttons of joysticks at any time (you don't need to store and update a boolean on your side in order to know if a button is pressed or released), and you always get the real state of joysticks, even if they are moved, pressed or released when your window is out of focus and no event is triggered.

SFML supports:

Unlike the keyboard or mouse, the state of joysticks is sometimes not directly available (depending on the OS), therefore an update() function must be called in order to update the current state of joysticks. When you have a window with event handling, this is done automatically, you don't need to call anything. But if you have no window, or if you want to check joysticks state before creating one, you must call Joystick.update explicitely.

Usage example:

    (* The id of joystick #0 *)
    let id = OcsfmlWindow.id_from_int 0

    (* Is joystick #0 connected? *)
    let connected = OcsfmlWindow.Joystick.is_connected id in    

    (* How many buttons does joystick #0 support? *)
    let buttons = OcsfmlWindow.Joystick.get_button_count id in
    
    (* Does joystick #0 define a X axis? *)
    let hasX = OcsfmlWindow.Joystick.has_axis id OcsfmlWindow.Joystick.X in
    
    (* Is button #2 pressed on joystick #0? *)
    let pressed = OcsfmlWindow.Joystick.is_button_pressed id 2 in
    
    (* What's the current position of the Y axis on joystick #0? *)
    let position = 
      OcsfmlWindow.Joystick.get_axis_position id OcsfmlWindow.Joystick.Y 
    in
    ...
    


type id = private int 
type of a joystick identifier
val count : int
Maximum number of supported joysticks.
val buttonCount : int
Maximum number of supported buttons.
val axisCount : int
Maximum number of supported axes.
type axis = 
| X
| Y
| Z
| R
| U
| V
| PovX
| PovY
Axes supported by SFML joysticks.
val id_from_int : int -> id
Create a joystick_id from an int n
Returns a joystick_id if n is between 0 and count-1, raise Invalid_argument otherwise
val is_connected : id -> bool
Check if a joystick is connected.
Returns True if the joystick is connected, false otherwise
val get_button_count : id -> int
Return the number of buttons supported by a joystick.

If the joystick is not connected, this function returns 0.
Returns Number of buttons supported by the joystick

val has_axis : id -> axis -> bool
Check if a joystick supports a given axis.

If the joystick is not connected, this function returns false.
Returns True if the joystick supports the axis, false otherwise

val is_button_pressed : id -> int -> bool
Check if a joystick button is pressed.

If the joystick is not connected, this function returns false.
Returns True if the button is pressed, false otherwise

val get_axis_position : id -> axis -> float
Get the current position of a joystick axis.

If the joystick is not connected, this function returns 0.
Returns Current position of the axis, in range -100 .. 100

val update : unit -> unit
Update the states of all joysticks.

This function is used internally by SFML, so you normally don't have to call it explicitely. However, you may need to call it if you have no window yet (or no window at all): in this case the joysticks states are not updated automatically.