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 .
Prof_Ants
Prole
Posts: 14 Joined: Mon Feb 20, 2012 9:04 am
Post
by Prof_Ants » Mon Mar 05, 2012 10:57 am
I can't seem to find it detailed in the wiki, but am I able to declare a love.keyboard.isDown with multiple keys?
I tried this (to no avail):
Code: Select all
if love.keyboard.isDown("lctrl" + "d") then
speed = 100
end
Last edited by
Prof_Ants on Mon Mar 05, 2012 11:10 am, edited 1 time in total.
SimonLarsen
Party member
Posts: 100 Joined: Thu Mar 31, 2011 4:47 pm
Location: Denmark
Contact:
Post
by SimonLarsen » Mon Mar 05, 2012 11:03 am
I think the wiki makes it pretty clear that you can give it multiple comma separated keys:
Code: Select all
Synopsis
anyDown = love.keyboard.isDown( key1, key2, key3, ... )
Arguments
* KeyConstant keyN
A key to check.
Returns
* boolean anyDown
True if any supplied key is down, false if not.
Prof_Ants
Prole
Posts: 14 Joined: Mon Feb 20, 2012 9:04 am
Post
by Prof_Ants » Mon Mar 05, 2012 11:06 am
What I am aiming to do is declare a key press combination. Will the comma separate statement produce this affect?
IMP1
Prole
Posts: 43 Joined: Mon Oct 03, 2011 8:46 pm
Post
by IMP1 » Mon Mar 05, 2012 11:20 am
Code: Select all
if love.keyboard.isDown("lctrl") and love.keyboard.isDown("d") then
-- speed = 100 or whatever
end
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Mon Mar 05, 2012 12:12 pm
Why your initial idea doesn't work is because of this:
Code: Select all
if love.keyboard.isDown("lctrl" + "d") then
Let's look at that argument:
That is the same as writing
Since there is no key named lctrld, it can never be down, and the call always returns false.
tentus
Inner party member
Posts: 1060 Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:
Post
by tentus » Mon Mar 05, 2012 1:15 pm
Robin wrote: Why your initial idea doesn't work is because of this:
Code: Select all
if love.keyboard.isDown("lctrl" + "d") then
Let's look at that argument:
That is the same as writing
Since there is no key named lctrld, it can never be down, and the call always returns false.
(Robin, we're not using Javascript right now!)
Actually, arithmetic on strings isn't supported in Lua. To concatenate strings ("lctrl" + "d" = "lctrld") you need to use the .. operator ("lctrl" .. "d" = "lctrld"). The above fails because you can't add words together.
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Mon Mar 05, 2012 2:45 pm
Shit, you're right.
Forget what I said.
T-Bone
Inner party member
Posts: 1492 Joined: Thu Jun 09, 2011 9:03 am
Post
by T-Bone » Mon Mar 05, 2012 8:35 pm
Another thing that might be good to keep in mind:
Often when you have key combinations in many applications, you typically hold one key down and then click the other one (like Ctrl + C). A good way to implement this is
Code: Select all
function love.keypressed(k)
if k == "c" and love.keyboard.isDown("ctrl") then
--stuff
end
end
tentus
Inner party member
Posts: 1060 Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:
Post
by tentus » Mon Mar 05, 2012 9:47 pm
T-Bone wrote: Code: Select all
if k == "c" and love.keyboard.isDown("ctrl") then
Wow, somehow it had never occurred to me to do it that way- good tip!
Users browsing this forum: Ahrefs [Bot] , Amazon [Bot] , Bing [Bot] , Google [Bot] and 10 guests