Handling complex keyboard input

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.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Handling complex keyboard input

Post by zorg »

rmcode wrote: Wed Nov 08, 2017 11:03 pmI'm looking into input handling atm. As far as I understand the best way to go is using scancodes because they aren't dependent on the user's keyboard locale. Naturally there aren't scancodes for some keys like "?" or "A". What's the best practise to handle these?
You don't. You have all the scancodes that are available on most modern keyboards, that's it.
rmcode wrote: Wed Nov 08, 2017 11:03 pmI could use love.textinput to get the actual character produced by "lshift" + "1" for example, but I couldn't check for this character in anything like "love.keyboard.isDown" right?
Yes and you're right.
rmcode wrote: Wed Nov 08, 2017 11:03 pmI thought I could maybe save

Code: Select all

command = { keycombination = "lshift", "1", actualCharacter = "!" }
That's not a bad idea, though you probably wanted to write something like this instead:

Code: Select all

command = { keycombination = {"lshift", "1"}, actualCharacter = "!" }
rmcode wrote: Wed Nov 08, 2017 11:03 pmBut how would I get the actualCharacter that's produced by lshift+1 on the users keyboard? :D
With textinput, but again, you should only use it as an indicator, if anything; also, getting the non-modified key is also somewhat hard if you want to not use key nor scancodes, since you'd need both the un-modified textinput and the modified one, which you can't really get at the same time (For example, for me, the '$' sign is 'AltGr'+'é', but 'AltGr' is where [rAlt] should be, and 'é' is the key next to [l] (on the right), which has both a different key and scancode (hell, my example is double problematic, since alt-gr maps to ctrl+alt with SDL)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Handling complex keyboard input

Post by rmcode »

grump wrote: Thu Nov 09, 2017 2:19 am Keys and characters are entirely different things. You keep conflating them. What you request is physically impossible, because you can't scan keys that do not exist. You need to decide if you want to check for keys or want to check for character input. There is no easy way to convert one into the other.
I'm just using basic LÖVE terminology (https://love2d.org/wiki/love.keypressed, https://love2d.org/wiki/KeyConstant, https://love2d.org/wiki/Scancode ... key, scancode) and I am aware that the "key" in this case doesn't necessarily map to an actual button on the keyboard and it's actually a character. But if you would have read through my previous posts thoroughly instead of focusing on pinning me down on some terminology-thing ...
But how do I know which button combination produced that character? Or is there a way to use the produced character to check for "isDown" events.
BUTTON COMBINATION ... and I specifically asked wether you can check for A CHARACTER in isDown events. mean I'm even talking about "characters" in my OP
I could use love.textinput to get the actual character produced by "lshift" + "1" for example, but I couldn't check for this character in anything like "love.keyboard.isDown" right?
Anyway ... thanks I guess!?
zorg wrote: Thu Nov 09, 2017 2:53 am You don't.
Ok thanks.
zorg wrote: Thu Nov 09, 2017 2:53 am Yes and you're right.
Hm that sucks, but then I'll just ignore these and use the actual key combinations.
rmcode wrote: Wed Nov 08, 2017 11:03 pm With textinput, but again, you should only use it as an indicator, if anything; also, getting the non-modified key is also somewhat hard if you want to not use key nor scancodes, since you'd need both the un-modified textinput and the modified one, which you can't really get at the same time (For example, for me, the '$' sign is 'AltGr'+'é', but 'AltGr' is where [rAlt] should be, and 'é' is the key next to [l] (on the right), which has both a different key and scancode (hell, my example is double problematic, since alt-gr maps to ctrl+alt with SDL)
Yup, sounds like a huge headache. I wonder how CDDA does it, but like slime mentioned in Discord yesterday, maybe their key bindings are broken on non standard layouts.
slime wrote: Thu Nov 09, 2017 2:12 am You should allow key combinations and assign a sensible default for the average user, and allow rebinding.
Ok then I'll do it like that.

Thanks for the help.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Handling complex keyboard input

Post by grump »

rmcode wrote: Thu Nov 09, 2017 9:05 am But if you would have read through my previous posts thoroughly instead of focusing on pinning me down on some terminology-thing ...
I did, and in fact the correct answer was in my very first reply:
Use textinput if you need the character generated by that input, and scancodes if you want positional input and don't care about the character.
You needed it explained to you several times in different words until you got it, fine. No need to get pissy at me, dude.
pinning me down on some terminology-thing
When talking about keyboard input, the difference between keys and characters is probably the most important distinction to make. If you keep using the wrong words, people must assume you do not understand the thing you're talking about. It's programming, it's important to be exact.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Handling complex keyboard input

Post by rmcode »

I did, and in fact the correct answer was in my very first reply:
I don't see how that was an answer to my OP, because I said myself that I could use love.textinput to get the complex characters. I wanted to know how I can use them to handle user input / controls. Anyway I got my answers from the other two participants and I don't want to argue any longer. So let's leave it at that.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 30 guests