Any way to ignore keyboard presses for a set amount of time?

N

Noba

Guest
So with my game I've put in a "Press enter to start!" screen just before the main menu, but I have a problem where when you press enter, as soon as you reach the next screen it will detect enter as being pressed for the first button on the main menu, so it will send you to the screen after that. I've got no idea why this is happening, is there maybe a way to make the game ignore any keyboard pressed or something for the first few seconds/steps in the first room?
 

rIKmAN

Member
So with my game I've put in a "Press enter to start!" screen just before the main menu, but I have a problem where when you press enter, as soon as you reach the next screen it will detect enter as being pressed for the first button on the main menu, so it will send you to the screen after that. I've got no idea why this is happening, is there maybe a way to make the game ignore any keyboard pressed or something for the first few seconds/steps in the first room?
Use keyboard_check_pressed() instead of keyboard_check()
 
F

FabioF

Guest
set an alarm in the key press event, every kind of code must be in the alarm event

pseudo code:

press key "enter" one time with keyboard_check_pressed() -->set the alarm[0] to 3 or lower, depends on your needs (must be positive)

in the alarm[0] event --->every other kind of coding stuffs related to what you want to do
 

rIKmAN

Member
I did that, but for some reason it didn't work.
The *_check_pressed functions only fire for 1 frame and then require the keyboard/mouse button to be pressed again before registering as another press.

If using these functions still exhibits the same behaviour you described in your OP then it sounds like the problem may be elsewhere.

Post your code so we can see what's going on, as "it didn't work" isn't enough information to help you.

Also when you say "screen" do you mean room?
 
B

Blakkid489

Guest
I normally use timers {alarms) to stop key presses
so....
Create:
Code:
canPress = false;
timer1 = 10;
Step:
Code:
keyEnter = keyboard_check_pressed(vk_enter);

if timer1 > 0 timer1 -= 1
if timer1 == 0;
{
     timer1 = -1;
     canPress = true;
}

if (canPress) && (keyEnter)
{
     //do something
     canPress = false;
     timer1 = 10;
}
This is how I do it. I'm sure there's easier ways to handle this but, hasn't done me wrong yet o_O
 
N

Noba

Guest
The *_check_pressed functions only fire for 1 frame and then require the keyboard/mouse button to be pressed again before registering as another press.

If using these functions still exhibits the same behaviour you described in your OP then it sounds like the problem may be elsewhere.

Post your code so we can see what's going on, as "it didn't work" isn't enough information to help you.

Also when you say "screen" do you mean room?
Yes I do!
I'll try the other code that was posted first, then if it doesn't I'll send the code.
I normally use timers {alarms) to stop key presses
so....
Create:
Code:
canPress = false;
timer1 = 10;
Step:
Code:
keyEnter = keyboard_check_pressed(vk_enter);

if timer1 > 0 timer1 -= 1
if timer1 == 0;
{
     timer1 = -1;
     canPress = true;
}

if (canPress) && (keyEnter)
{
     //do something
     canPress = false;
     timer1 = 10;
}
This is how I do it. I'm sure there's easier ways to handle this but, hasn't done me wrong yet o_O
Alright, Thanks! I'll try it out.
 

TheouAegis

Member
Use io_clear(). It resets the status of the keyboard and mouse.

if keyboard_check_pressed(vk_enter)
{
io_clear();
room_goto(rm_level_one);
}
 
Top