Disable key repeat?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Disable key repeat?

Post by hasen »

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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Disable key repeat?

Post by raidho36 »

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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Disable key repeat?

Post by zorg »

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 :3True 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.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Disable key repeat?

Post by hasen »

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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Disable key repeat?

Post by grump »

zorg wrote: Fri Feb 16, 2018 5:13 pm You can use keypressed, keyreleased
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Disable key repeat?

Post by hasen »

grump wrote: Fri Feb 16, 2018 5:29 pm
zorg wrote: Fri Feb 16, 2018 5:13 pm You can use keypressed, keyreleased
hasen wrote: Fri Feb 16, 2018 4:01 pm I'd rather not use love.keypressed in this case either.
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: Disable key repeat?

Post by pgimeno »

Sounds like you don't want to use the best way, so maybe you should ask about the next best way instead?
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Disable key repeat?

Post by hasen »

pgimeno wrote: Fri Feb 16, 2018 5:43 pm Sounds like you don't want to use the best way, so maybe you should ask about the next best way instead?
Nobody has responded since I gave more details.
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Disable key repeat?

Post by Tjakka5 »

Because the best way is to just use keypressed / released

Code: Select all

function love.keypressed(key)
  if key == "up" then
    print("Enter the new room")
  end
end
And that will do exactly what you need it to.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: Disable key repeat?

Post by hasen »

Tjakka5 wrote: Fri Feb 16, 2018 6:06 pm Because the best way is to just use keypressed / released

Code: Select all

function love.keypressed(key)
  if key == "up" then
    print("Enter the new room")
  end
end
And that will do exactly what you need it to.
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.

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests