Page 1 of 1
[SOLVED] Accessing shift+<...> scancodes?
Posted: Wed Oct 18, 2017 6:48 pm
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.
Re: Accessing shift+<...> scancodes?
Posted: Wed Oct 18, 2017 7:15 pm
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
Re: Accessing shift+<...> scancodes?
Posted: Wed Oct 18, 2017 9:26 pm
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().