ACSUtils provides a set of wrappers for GetPlayerInput to make writing correct input code easier.
ACSUtils provide a way to easily check these all these states for every key without writing compliated GetPlayerInput
expressions.
Say, you have an on-screen button to sell items that can be clicked with mouse:
if (/* check that mouse cursor is inside the button */) if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_ATTACK)) // check left mouse button click SellItem();
This code is wrong. If the player clicks the button once, it will likely cause him to sell multiple items. That's because this code checks if the mouse button is down. But the mouse button may be down for multiple tics after a click, as it may not be immediately released.
To avoid this bug, you need to check if the button was up the previous tic, but is now down. And that's exactly what the pressed state means. The KeyPressed
function contains all the repetitive code to perform this check:
if (/* check that mouse cursor is inside the button */) if (KeyPressed(BT_ATTACK)) // check left mouse button click SellItem();
Now the button works correctly. Performing an action on releasing the button can be done the same way using KeyReleased
.
To check one key or a key combination:
bool KeyUp(int key)
bool KeyDown(int key)
bool KeyPressed(int key)
bool KeyReleased(int key)
bool KeyToggled(int key)
Examples:
Checking one key:
if (KeyPressed(BT_ATTACK)) print(s:"You clicked left mouse button");
Checking a key