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

Re: Disable key repeat?

Post by zorg »

hasen wrote: Sun Feb 18, 2018 3:32 pm
raidho36 wrote: Sat Feb 17, 2018 12:05 pm LÖVE mainly handles input via events, the "isDown" is for quick and dirty hacks mid-development and you shouldn't rely on it.
I don't know, I see that the most in other people's finished source code. It's even used in Mari0 the most well known Love2d game.
Be aware that Maurice (its dev) did state that mari0's source is pretty much hacked together... although i guess you could ask him on Discord since i really don't want to say things in others' stead;

that said, if there's a good enough reason to, using isDown isn't hacky at all; one such reason is implementing a multi-state key detection lib, for example; you couldn't detect held keys without the isDown function that way, nor ones that are currently "idle".
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 »

zorg wrote: Sun Feb 18, 2018 4:09 pm
hasen wrote: Sun Feb 18, 2018 3:32 pm
raidho36 wrote: Sat Feb 17, 2018 12:05 pm LÖVE mainly handles input via events, the "isDown" is for quick and dirty hacks mid-development and you shouldn't rely on it.
I don't know, I see that the most in other people's finished source code. It's even used in Mari0 the most well known Love2d game.
Be aware that Maurice (its dev) did state that mari0's source is pretty much hacked together... although i guess you could ask him on Discord since i really don't want to say things in others' stead;

that said, if there's a good enough reason to, using isDown isn't hacky at all; one such reason is implementing a multi-state key detection lib, for example; you couldn't detect held keys without the isDown function that way, nor ones that are currently "idle".
When I said 'even used in Mari0' I actually didn't mean 'only used in Mari0'. It's even used in Kikito's bump demos and his Kongame. You're right it's not hacky at all and it's what I see mainly used for movement control.
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:46 pm
Besides that, you should not base your game's behavior around keypressed repeating. The delay between repeats can differ from os to os, and may even be customized in some environments.
If you want your player to be able to be constantly jumping while holding the up key, you should instead be using love.keyboard.isDown.

Last but not least, to fix your "defining multiple callbacks" problem, you want to propagate events if they are not satisfied.
For example, when you click on screen you first want to tell your UI code there was a keypress.
It will return true if it "used" it, or false if it didn't click on anything.
If it returns false you can then propagate it to the next system, and the next and the next.

Code: Select all

function love.mousepressed(...)
  if not menu.mousepressed(...) then
    if not player.mousepressed(...) then
      -- Etc
    end
  end
end
Again you're dealing with priorities here.

Hope that helps!
Not sure what that code is supposed to mean. Both menu and player.mousepressed, or keypressed detect ANY key...how would they ever return false?
Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests