love.keypressed detecting keys incorrectly

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
KaoS
Prole
Posts: 11
Joined: Sat Mar 02, 2013 2:06 am

love.keypressed detecting keys incorrectly

Post by KaoS »

Hi Pro's,

I am making a basic Lua console which involves inputting text and when you press enter that code being run. I am trying to implement a copy and paste feature however when I press "v" on the keyboard the love.keypressed(sKey) function thinks I pressed "lctrl" for some reason and so I cannot implement a ctrl+v key detection.

A copy of the code can be found here http://pastebin.com/24uusABT. On line 67 I check for the user pressing "v" and if the ctrl key is down. if you take a look at line 66 you will see I record any key the user presses in a var and I display that in the top line of the console for troubleshooting, you can use this to test for yourselves

I am using love 0.9.0 so I could possibly use the love.textinput(sText) function however I would like to implement it in the keypressed function if possible. Any assistance would be greatly appreciated

EDIT: I cannot even use the textinput function as it does not detect the "v" when I press ctrl+v
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: love.keypressed detecting keys incorrectly

Post by Azhukar »

KaoS wrote:On line 67 I check for the user pressing "v" and if the ctrl key is down.
Replace line 67 with this:

Code: Select all

if key=="v" and love.keyboard.isDown("lctrl","rctrl") then
love.keypressed is a callback, it is not a function to be called to check for keypress.

I don't understand how you made this mistake since on line 78 you use the correct function. Walk it out.bat is awesome :crazy:
KaoS
Prole
Posts: 11
Joined: Sat Mar 02, 2013 2:06 am

Re: love.keypressed detecting keys incorrectly

Post by KaoS »

I'm not calling it. I define the function and every time a user presses a key then love2d calls it with the key that was pressed as the first parameter. So when the function is called if the first parameter is "v" and the ctrl key is down then paste...

and thanks :awesome: I just randomly felt like coding in batch one day, I'm starting to doubt my sanity... I think KaoShell and infiT are 10x cooler though
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: love.keypressed detecting keys incorrectly

Post by Azhukar »

KaoS wrote:I'm not calling it.
Yes you ARE calling it on line 67. The callback starts at line 64, calling the callback inside itself is nonsense.

This is what you're doing wrong, do you see it?

Code: Select all

function love.keypressed(key)
        if bConsoleActive then
                lastkey=key
                if key=="v" and love.keypressed("lctrl","rctrl") then --ctrl+v
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: love.keypressed detecting keys incorrectly

Post by davisdude »

You could also use love.textinput as far as I know.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
KaoS
Prole
Posts: 11
Joined: Sat Mar 02, 2013 2:06 am

Re: love.keypressed detecting keys incorrectly

Post by KaoS »

Oh my word... this is the most n00by mistake I have ever made to date :ultrashocked: I am embarrassed by the existence of this thread. I apologise for wasting your time. Also you cannot use textinput because if you press ctrl+v it does not call textinput at all
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: love.keypressed detecting keys incorrectly

Post by davisdude »

My bad. Good to know, though.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 3 guests