Keyboard

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.
Post Reply
Blunzzy
Prole
Posts: 1
Joined: Sat May 23, 2020 8:01 pm

Keyboard

Post by Blunzzy » Sat May 23, 2020 8:03 pm

Hello, I was wondering what was the command I need to use if I want an action when I press a key on the keyboard but when I release it, the action stops. Anyone know the answer?

randomnovice
Citizen
Posts: 95
Joined: Sat May 09, 2015 9:15 pm

Re: Keyboard

Post by randomnovice » Sat May 23, 2020 10:21 pm

Hi,

By no means an expert but I think you could...

a) Test in love.update() using love.keyboard.isDown("key").

b) Activate a flag in love.keypressed(key) and deactivated it in love.keyreleased(key).

sphyrth
Party member
Posts: 172
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: Keyboard

Post by sphyrth » Sun May 24, 2020 2:02 am

Let's translate that into code:

Method 1:

Code: Select all

function love.update()
...
   if love.keyboard.isDown('a') then -- Let's press 'A' for example
     -- Do Action
   end
end
* You can put an "else <Stop Action>" if you really need it.

Method 2:

Code: Select all

function love.keypressed(key)
  if key == 'a' then
    -- Do Action
  end
end

function love.keyreleased(key)
  if key == 'a' then
    -- Stop Action
  end
end

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 35 guests