• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

simulated keypress, keyboard_check equivalent?

J

Joe B-W

Guest
Hi all,

Does anyone have much experience with using the keyboard_key_press and keyboard_key_release functions to simulate keyboard input?

Context: my students are making 4 player games with gamepads, and at some point we may convert these games to run on an arcade machine using an I_PAC (which converts the arcade controller input into keyboard in order to interface with a PC). For that to work, I either need to double up all of their code when I port it, or find some smart way of building in a gamepad input > keyboard input conversion that's running in the background. Something like Player 1 presses face button A > simulated keypress of keyboard b > ingame action. I'm leaning toward building the ports of the student projects after they're finished to avoid confusing them, but I just wanted to work out whether there was a simple non-intrusive solution I could build into our project templates before they start.

Now, I may be getting ahead of myself but I noticed we only have keyboard_key_press and keyboard_key_release but no equivalent for causing a key to act as if it was held... I guess my main technical question would be: if I trigger a keyboard_key_press every frame for 10 frames, does the system recognize it as "key was pressed" on the first frame and then "key was held down" for the following 9?

Thanks!
 
Code:
keyboard_check(vk_key)
Will check to see if vk_key is being held. Additionally
Code:
shoot_button = keyboard_check(vk_key) || gamepad_button_check(gp_button);
Will make the shoot_button variable true if EITHER the vk_key is being held or the gp_button is being held (of course, vk_key and gp_button aren't real commands, just placeholders for whatever you wanted). On that note, this is why it is better to set up variables for input, rather than relying directly on keyboard_check or gamepad_button_check. You can add as many keys/buttons as you like by using the or command if you're setting it to a variable and then using that variable to check for the input.
 
Last edited:

TheouAegis

Member
keyboard_key_press is the same as holding a key. You can IMMEDIATELY follow it uo with keyboard_key_release() to simulate a tap. It will register as both instant actions that step; not sure if it counts as a normal key held though at that point.
 
Lel, I read that totally wrong. I don't think there's any need for simulated key presses in this type of thing though? Just have a variable that holds all the inputs you want and check to see if that variable is true, rather than trying to trigger a key press with another button press.
 
Top