Usage¶
InputCheck()¶
The core of this system is the inputCheck()
function.
How this works is you can give it an input of any type (keyboard, gamepad, mouse),
or an array of inputs, and if that one input or any of the inputs in the array are pressed it will return true
.
Read more about defining inputs here.
You can also supply the gamepad device to check. Here is the manual for gamepads.
So the syntax is:
inputCheck(input/array, mode, gamepad_device);
Here is an example of moving right:
if (inputCheck([vk_right, "d", gp_padr, gp_axislr], CHECK_MODE.DOWN)) x += 4;
The mode parameter determins how the input is checked, it can be CHECK_MODE.DOWN, CHECK_MODE.PRESSED, or CHECK_MODE.RELEASED Read more about checking methods here.
There is also a function for each input type (keyboard, gamepad, mouse). If you only need to check one type use these:
keyCheck()
- for keyboard
gpCheck()
- for gamepads
mbCheck()
- for mouse
These functions essentially replace the built in check
, check_pressed
, and check_released
functions but combine them into one, with a mode
parameter.
InputSystem()¶
The InputSystem()
allows you to organise your inputs into categories and check them all in one line.
To use it you will have to create one first. Most likely in a create event. The syntax is like this.
in_sys = new InputSystem({ category_1: [input1, input2, input3...], category_2: [input1, input2, input3...], category_3: [input1, input2, input3...] });
And here is and example:
in_sys = new InputSystem({ right: [vk_right, "d", gp_padr, gp_axislr], left: [vk_left, "a", gp_padl, gp_axisll], jump: [vk_up, "w", gp_a], shoot: [vk_space, gp_shoulderrb, gp_x] });
Read more about defining inputs here.
And then to check them do the following. Most likely in a step event.
in = in_sys.check();
Here is an example how you can use this to move your player.
/// Create event in_sys = new InputSystem({ right: [vk_right, "d", gp_padr, gp_axislr], left: [vk_left, "a", gp_padl, gp_axisll], jump: [vk_up, "w", gp_a], shoot: [vk_space, gp_shoulderrb, gp_x] }); /// Step event var input = in_sys.check(); if (input.right.down) x += 4; if (input.left.down) x -= 4; if (input.jump.pressed) y -= 10; if (input.shoot.down) shoot();
Now the variable in
holds the result of the check. To get the input do in.category.checking_method
.
The category is one of the names you defined when you created the system (e.g. right).
The checking method can be .down
, .pressed
, or .released
. You can read more about the checking methods here.
The input system also has more useful methods and variables you can change.
- Here are the variables:
.inputs
- It holds the systems inputs. You can change the inputs in game by changing this variable..gamepad_device
- The gamepad device to check for. Set it to any number between0
and12
.
For the gamepad_device
I recommend using the global.gamepads_connected
variable if you are controlling a player.
Read more about it here.
- And here is the list of methods you can use.
.check
- Checks for the inputs..save
- Saves the input system into a file..load
- Loads a saved input system from a file..describe
- Lists the currents inputs to the output window. Good for debugging purposes..clear
- Clears the input struct.
Here is an example how you can use these variables and methods.
/// Create event // Create system in_sys = new InputSystem({ right: [vk_right, "d", gp_padr, gp_axislr], left: [vk_left, "a", gp_padl, gp_axisll] }); // Load in save file if (file_exists("input_save.json")) in_sys.load("input_save.json"); // Add an "up" category to the system in_sys.inputs.up = [vk_up, "w", gp_padu, gp_axislu]; /// Cleanup event in_sys.save("input_save.json"); in_sys.clear(); delete in_sys;
Defining inputs¶
This sytem uses different ways to define inputs than the default. Here is the list what you can use and what you cannot:
Keyboard¶
- For letters through A-Z and for numbers 0-9:
Accepted: string with the letter or the number, the case doesn’t matters (e.g. “a”, “1”)
Not accepted:
ord(chr)
function
For other keys use the vk_
constants. Here is a list of them.
Also the system has a few bounus vk_ constants. See the full list here.
Gamepad¶
For gamepad buttons use the existing gp_
constants. Here is a list of them.
Also this system adds four new constants the gp_a
, gp_b
, gp_x
and gp_y
. You use these instead of the gp_face
constants.
- For gamepad analog sticks the system adds eight new constants:
gp_axislr
- Left stick rightgp_axisll
- Left stick leftgp_axislu
- Left stick upgp_axisld
- Left stick downgp_axisrr
- Right stick rightgp_axisrl
- Right stick leftgp_axisru
- Right stick upgp_axisrd
- Right stick down
You cannot use the: gp_axislh
, gp_axislv
, gp_axisrh
and gp_axisrv
constants.
Mouse¶
For mouse buttons simply use the existing mb_
constants. Here is a list of them.
Checking methods¶
- You can check inputs in three ways:
down - Returns
true
continuously if the input is currently held downpressed - Returns
true
only at the moment when the input is pressed but not continuouslyreleased - Return
true
only at the moment when the input is released
Gamepads connected array¶
This system has a global.gamepads_connected
array. Which makes handling gamepad connections/disconnections much easier.
What it does is if a gamepad connects it adds it to the first empty index in the array. And if one disconnects it removes it.
This is good because gamemaker indexes all connected gamepads with a number from 0
to how many gamepads are connected.
But if you want to swap controller index 0
for an other one, and disconnect the controller,
gamemaker will reindex all that comes after it so the index 1
controller will be index 0
, index 2
will be 1
etc.
So essentially now everyone controls a different player in the game.
So when you supply the gamepad_device
to a function, and you don’t want the controllers to change index when one disconnects,
use the global.gamepads_connected[0]
instead of just 0
.
Bonus vk constants¶
- Here is the list of the vk constants this systems adds:
vk_left_cmd
- Left command key (macOS only)vk_right_cmd
- Right command key (macOS olny)vk_semicolon
- Semicolonvk_comma
- Commavk_dot
- Dotvk_equal
- Equal signvk_slash
- Slashvk_backslash
- Backslashvk_singlequote
- Singlequotevk_pilcrow
- Pilcrowvk_backtick
- Backtickvk_opening_square_bracket
- Opening square bracketvk_closing_square_breacket
- Closing square bracket