Page 1 of 1

love.keypressed detecting keys incorrectly

Posted: Thu Feb 06, 2014 2:47 pm
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

Re: love.keypressed detecting keys incorrectly

Posted: Thu Feb 06, 2014 2:57 pm
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:

Re: love.keypressed detecting keys incorrectly

Posted: Thu Feb 06, 2014 3:46 pm
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

Re: love.keypressed detecting keys incorrectly

Posted: Thu Feb 06, 2014 3:47 pm
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

Re: love.keypressed detecting keys incorrectly

Posted: Thu Feb 06, 2014 8:12 pm
by davisdude
You could also use love.textinput as far as I know.

Re: love.keypressed detecting keys incorrectly

Posted: Fri Feb 07, 2014 7:23 am
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

Re: love.keypressed detecting keys incorrectly

Posted: Fri Feb 07, 2014 7:44 pm
by davisdude
My bad. Good to know, though.