Xin v1.1
Yet Another XInput Extension
By JacksonYarr

Features

- Full Xbox 360 Controller Support within GameMaker.
- Button Pressed and Released Functions
- Compensation for Thumbstick & Trigger Deadzones
- Support for 4 Controllers, All Buttons & Force Feedback (Rumbling).

v1.1 Updates

- Fixed deadzone issue with thumbsticks causing limited range (0.25 - 1). Range is now correctly (0 - 1).

- The functions xin_check(), xin_check_pressed(), and xin_check_released() now work with the left and right triggers.


Functions

xin_update(index);

Updates the state of the specified controller (0 - 3 or all). This needs to be called before new input can be received from the controller. Returns true or false.

(False generally indicates the specified controller is not connected.)

If the keyword all is specified, the function will return the total number of controllers successfully updated.

Warning: This function can be resource intensive, particularly when called with the keyword all. It is strongly recommended that the function only ever be called for the controllers currently active. (i.e. Only ever use the keyword all to infrequently detect the total number of attached controllers, or if all 4 controllers are actually being used.)

Note: Returns -1 if the specified index is invalid.


xin_get_state(index, button);

Retrieves the current state of an input on the specified controller with a value of variable intensity (i.e. Thumbsticks and Triggers).

Returns a value between -1 and 1 indicating the intensity of the specified input.

Button must be one of the following constants:

xb_leftTrigger
xb_rightTrigger
xb_leftThumbX
xb_leftThumbY
xb_rightThumbX
xb_rightThumbY

Note: Returns 0 if the specified controller index or button is invalid.

Note: The Y value returned when using constants xb_leftThumbY and xb_rightThumbY is pre-inverted to compensate for GameMakers inverted Y drawing. (i.e. Pressing the thumbstick up will return a negative Y value, since -1 is the direction of up in GameMaker.)


xin_check(index, button);

Checks whether the specified button is being pressed on the controller with the given index. Returns true or false.

Button must be one of the following constants:

xb_a
xb_b
xb_x
xb_y
xb_leftShoulder
xb_rightShoulder
xb_leftThumb
xb_rightThumb
xb_up
xb_down
xb_left
xb_right
xb_start
xb_back
xb_leftTrigger
xb_rightTrigger

Note: Returns -1 if the specified controller index or button is invalid.

Note: Use the function xin_get_state() to check the intensity of the left and right triggers.


xin_check_pressed(index, button);

Checks whether the specified button has been pressed on the controller with the given index since the controller was last updated. Returns true or false.

See the xin_check function for a list of button constants.

Note: Returns -1 if the specified controller index or button is invalid.


xin_check_released(index, button);

Checks whether the specified button has been released on the controller with the given index since the controller was last updated. Returns true or false.

See the xin_check function for a list of button constants.

Note: Returns -1 if the specified controller index or button is invalid.


xin_set_rumble(index, left, right)

Sets the force feedback 'rumble' level on the controller with the specified index (0 - 3 or all). Left indicates the intensity of the left motor (0 to 1), a low frequency rumble motor. Right indicates the intensity of the right motor (0 to 1), a high frequency vibration motor.

Returns true, false or the total number of successfully set controllers if the keyword all is specified.

Warning: As with the xin_update function, use of the keyword all should be infrequent (unless 4 controllers are actually active).

Note: Returns -1 if the specified controller index, left intensity or right intensity is invalid.


xin_get_input(index);

This function will return values (that correspond to a button constant) of all buttons currently being pressed on the specified controller. Returns false when there are no more buttons to report.

This function can be used in conjunction with a while loop to retrieve all current button input. (Excluding Trigger & Thumbstick positions)

Note: This function is similar to xin_check, however differs in the sense that there's no overhead checking the state of buttons that aren't being pressed.

Note: Returns -1 if the specified controller index or button is invalid.

Warning: This function will not report left or right trigger presses.


xin_get_input_bitmask(index);

[Advanced Function] This function will return a decimal representation of a bitmask indicating all buttons currently being pressed on the specified controller.

Information on the bitmask values of each controller button is available at the Windows Dev Center.

Note: Using this value you can replicate the xin_get_input function without the overhead of potentially numerous external calls.

Note: Returns -1 if the specified controller index is invalid.


License

CC0 1.0 Universal (CC0 1.0)
Public Domain Dedication

To the extent possible under law, Jack Hood (JacksonYarr) has waived all copyright and related or neighbouring rights to Xin. This work is published from: Australia.

(You can copy, modify and distribute the work, even for commercial purposes, all without asking permission.)

http://creativecommons.org/publicdomain/zero/1.0/


Attribution is by no means required; however it's always greatly appreciated.