Disable key repeat?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Disable key repeat?
I'm using love.keyboard.isDown and it seems to repeat as default and I can't see a way to disable that nor does there seem to be the function love.keyboard.isUp..? Any way to set it so if the player holds the key down it doesn't repeat? I'd rather not use love.keypressed in this case either. I only want to disable it for one particular key. I'd obviously need key repeat for moving.
Re: Disable key repeat?
The isDown function returns "true" for as long as the button is depressed, "false" otherwise. Simple, really. You can get individual press or release events using event handler, and they will indicate if it's a system repeated press or not.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Disable key repeat?
You can use keypressed, keyreleased and isDown in update to simulate a 4-stage system (pressed,held,released,"free"), and obviously you only want the state when a key wasn't pressed before, but got pressed down, and isn't being held.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Disable key repeat?
Hmm well, another question to make it more specific. The player is entering a door by pressing up but if the key is held down as soon as he enters the new room he goes back to the old one. In fact it's impossible to stop him from going in and out loads of times with a single keypress. Is there another way to avoid this when entering doors?
I mean, what would be the best way to handle this? I thought about timers and such but thought there might be a more eloquent and simple way to solve this issue.
I mean, what would be the best way to handle this? I thought about timers and such but thought there might be a more eloquent and simple way to solve this issue.
Re: Disable key repeat?
Sounds like you don't want to use the best way, so maybe you should ask about the next best way instead?
Re: Disable key repeat?
Because the best way is to just use keypressed / released
And that will do exactly what you need it to.
Code: Select all
function love.keypressed(key)
if key == "up" then
print("Enter the new room")
end
end
Re: Disable key repeat?
Ok so there's no real good way to do it. Up is also jump which does want to repeat you see and down will also need to enter a door or crouch as long as down is held. So they need to repeat or not repeat depending on if the player is next to a door or not. Or more specifically, upon entering the new room it should stop repeating.Tjakka5 wrote: ↑Fri Feb 16, 2018 6:06 pm Because the best way is to just use keypressed / released
And that will do exactly what you need it to.Code: Select all
function love.keypressed(key) if key == "up" then print("Enter the new room") end end
The other problem is I already have love.keypressed in the main game object to detect things like escape to quit or pause game but this enter room key check is in the player object. I can't have two love.keypressed functions at the same as one cancels out the other. These are all the reasons that I did not want to use keypressed. It wasn't because I didn't like the name or something.
Who is online
Users browsing this forum: No registered users and 4 guests