[SOLVED] Accessing shift+<...> scancodes?

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
User avatar
TimeLoop
Prole
Posts: 28
Joined: Wed Apr 17, 2013 8:20 am

[SOLVED] Accessing shift+<...> scancodes?

Post by TimeLoop »

Hi.

I have a problem with how to know if the player has pressed certain scancodes, specifically those that you obtain by using [shift] + [key].

For example, in an UK keyboard, if I want the character ">" to appear on screen, i need to press [ shift ] + [ . ]
But when using such key combination within LOVE, the engine treats it like two unrelated and separated key presses.

Ofc, I can detect if the player has pressed [ shift ] first, and then [ . ], but the problem now is, if the player is using a non-UK keyboard, to obtain [ > ], I need to press [ shift ] + [ < ], but the spanish key for [ < ] in a UK keyboard is [ \ ], so detecting the [ . ] scancode will not work in non-UK keyboards.

How can I solve this? I CANNOT replace [ > ] with other key/scancode.

Thanks beforehand.
Last edited by TimeLoop on Wed Oct 18, 2017 9:26 pm, edited 1 time in total.
hamberge
Prole
Posts: 25
Joined: Wed Aug 16, 2017 2:55 pm

Re: Accessing shift+<...> scancodes?

Post by hamberge »

I think scancodes are dependent on the specific keys pressed and are independent of which particular keyboard layout you have or whether modifier keys like shift, ctrl, whatever, is pressed. For example, the . key on a US keyboard will produce the same scancode regardless of whether shift, ctrl, whatever, is held down. That is in fact why you are getting the above results. Shift plus . is two separate and unrelated keys being pressed. They just happen to be treated in a certain way when you are in a text editor. It's not just love that does this either, this is pretty much universal. See, e.g., https://msdn.microsoft.com/en-us/librar ... s.60).aspx

I think we need to know more about what exactly you are trying to accomplish. Are you trying to make it so that the user can hold down the key combination that would produce the character ">" and you would determine that regardless of keyboard layout? If so, you may want to rethink what you are trying to accomplish. If you are trying to get text in, you might want to consider the textinput system http://love2d.org/wiki/love.textinput.

Edit: this post has a good explanation:
https://gamedev.stackexchange.com/quest ... rd-layouts
User avatar
TimeLoop
Prole
Posts: 28
Joined: Wed Apr 17, 2013 8:20 am

Re: Accessing shift+<...> scancodes?

Post by TimeLoop »

hamberge wrote: Wed Oct 18, 2017 7:15 pm I think scancodes are dependent on the specific keys pressed and are independent of which particular keyboard layout you have or whether modifier keys like shift, ctrl, whatever, is pressed. For example, the . key on a US keyboard will produce the same scancode regardless of whether shift, ctrl, whatever, is held down. That is in fact why you are getting the above results. Shift plus . is two separate and unrelated keys being pressed. They just happen to be treated in a certain way when you are in a text editor. It's not just love that does this either, this is pretty much universal. See, e.g., https://msdn.microsoft.com/en-us/librar ... s.60).aspx

I think we need to know more about what exactly you are trying to accomplish. Are you trying to make it so that the user can hold down the key combination that would produce the character ">" and you would determine that regardless of keyboard layout? If so, you may want to rethink what you are trying to accomplish. If you are trying to get text in, you might want to consider the textinput system http://love2d.org/wiki/love.textinput.

Edit: this post has a good explanation:
https://gamedev.stackexchange.com/quest ... rd-layouts
Thank you. I solved the problem making use of love.textinput().
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Mathisto and 46 guests