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 »

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
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

Re: Keyboard

Post by randomnovice »

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: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: Keyboard

Post by sphyrth »

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: Bing [Bot], Google [Bot] and 1 guest