Why is '?' not recognized on love.keypressed?

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
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Why is '?' not recognized on love.keypressed?

Post by Germanunkol »

On a German QWERTZ Keyboard layout, the question mark key is not passed to love.keypressed at all.
Why is that? The question mark is part of the normal Ascii-Table, so it should be easily available in Lua (and, of course, I can print it onto the screen properly) - but I can't type it when trying to create an input box.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Why is '?' not recognized on love.keypressed?

Post by Robin »

Do you mean that you get nothing if you try something like "if key == '?' then" or "if string.char(unicode) == '?' then" or that love.keypressed isn't even called when you type a question mark? (I don't have a QWERTZ keyboard myself so it is a bit hard to help you out here.)
Help us help you: attach a .love.
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:00 am, edited 3 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Why is '?' not recognized on love.keypressed?

Post by bartbes »

Unfortunately SDL1.2 is a bit picky about keyboards and keycodes, it seems to only pick up keycodes for keys that exist in a us layout (this may depend on the system it was compiled on).
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Why is '?' not recognized on love.keypressed?

Post by Boolsheet »

*repeats bartbes' message because I'm too lazy to edit this*

When you hit a key, the scancode that the keyboard sends gets translated by a few layers. It gets a bit problematic for non-US keyboard when the SDL 1.2 layer comes up because it doesn't recognize/translate all layouts properly. LÖVE then just shrugs off the keypress.

This should be fixed in LÖVE 0.9.0 because it's now using SDL 2 which has much better support in that regard. Check out the development builds. If it still doesn't work, the LÖVE or SDL layer has an issue. Throw a ticket on the issue tracker in that case.
Shallow indentations.
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:00 am, edited 1 time in total.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Why is '?' not recognized on love.keypressed?

Post by Germanunkol »

Hi,
thanks for all the quick responses?
Robin wrote:Do you mean that you get nothing if you try something like "if key == '?' then" or "if string.char(unicode) == '?' then" or that love.keypressed isn't even called when you type a question mark? (I don't have a QWERTZ keyboard myself so it is a bit hard to help you out here.)
Robin, I meant the latter: love.keypressed will be called when I press the lshift button, but not when I press the key the ? is on.
When other keys are pressed it either interprets them correctly or at least prints "unknown" as the key value and gives the unicode, so I could interpret it. But not so with the öäü, ß and ? keys.
Boolsheet wrote: This should be fixed in LÖVE 0.9.0 because it's now using SDL 2 which has much better support in that regard. Check out the development builds. If it still doesn't work, the LÖVE or SDL layer has an issue. Throw a ticket on the issue tracker in that case.
Indeed, it works in Love 0.9, I tried it a few months back. What I was looking for was a workaround for 0.8.0.
However, giving this some more thought: I might actually switch to 0.9.0 for this project, because it'll probably be a few years before it's done.

@bekey: Your method seems nice, but won't really solve my problem, I believe. Of course, this way I can let people use some other key to print the ?, but since the keypressed event is not called and even love.keyboard.isDown doesn't recoginze the ?, I guess there's not way to fix this, without recompiling Löve.

Too bad. I think I'll make the switch to 0.9 then.

Still, thank you all!
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Why is '?' not recognized on love.keypressed?

Post by Germanunkol »

Follow up problem:

I tried it with Löve 0.9.0. Now I can input the characters just fine, but now font:getWidth() fails on characters like ö, ü, ä ß etc.
The functions I programmed heavily rely on those characters - I'd hate to just throw them away.
Of course I could substitute them in the strings by o,u,a and s, use the new strings for word wrapping and then use the original strings to display the text.
This is extremly inconvenient though, and will be slow. Also, mathing umlauts in Lua is not trivial.

Any suggestions?
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Why is '?' not recognized on love.keypressed?

Post by slime »

Are the files with those strings saved with UTF-8 encoding?
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Why is '?' not recognized on love.keypressed?

Post by Germanunkol »

Uh, that was the problem. Thanks, it's working now!
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], keharriso and 87 guests