Get the character from the key
Ulrar opened this issue · 5 comments
Hi,
I don't see any way to convert from Keyboard.PKey for example to the actual character P, to know what the player is typing. How would I do that, besides the obvious twenty-six case on the key ?
Thanks
I'm not sure there is currently another way at present in helm. Helm doesn't implement subscriptions to or support for manipulating of a text input field.
Here's how one can create them in haskell.
https://hackage.haskell.org/package/sdl2-2.4.0.1/docs/SDL-Input-Keyboard.html#g:2
Under text input/editing events here you can see how data gets fed back from sdl2.
https://hackage.haskell.org/package/sdl2-2.4.0.1/docs/SDL-Event.html#g:6
A helm-friendly abstraction around this would be needed to do it the "easy way".
Might be possible to do in helm via Cmd but I can't really say for sure yet as I'm still learning.
Hey,
I think you might have misunderstood my question, I was just looking for a function to get the char from a key pressed event, not any kind of pre-made text field.
I've since made it myself (I'll skip the handling of shift for uppercase letters, but you get it) :
keyCodeToChar k = case k of
KB.AKey -> "a"
KB.BKey -> "b"
KB.CKey -> "c"
KB.DKey -> "d"
KB.EKey -> "e"
KB.FKey -> "f"
KB.GKey -> "g"
KB.HKey -> "h"
KB.IKey -> "i"
KB.JKey -> "j"
KB.KKey -> "k"
KB.LKey -> "l"
KB.MKey -> "m"
KB.NKey -> "n"
KB.OKey -> "o"
KB.PKey -> "p"
KB.QKey -> "q"
KB.RKey -> "r"
KB.SKey -> "s"
KB.TKey -> "t"
KB.UKey -> "u"
KB.VKey -> "v"
KB.WKey -> "w"
KB.XKey -> "x"
KB.YKey -> "y"
KB.ZKey -> "z"
KB.Number0Key -> "0"
KB.Number1Key -> "1"
KB.Number2Key -> "2"
KB.Number3Key -> "3"
KB.Number4Key -> "4"
KB.Number5Key -> "5"
KB.Number6Key -> "6"
KB.Number7Key -> "7"
KB.Number8Key -> "8"
KB.Number9Key -> "9"
KB.SpaceKey -> " "
KB.MinusKey -> "-"
_ -> ""
Nothing fancy, but it seems like that doesn't exist anywhere in helm unfortunatly.
The reason I went to elaborate on this is perhaps a bit more specific to those of us in Euroland, where we type weird multi-key series combinations for typing text.
é requires for instance two keypresses.
I figured you wanted full blown text-entry, which is a different sdl2 module with no current helm support :(
Hey! I just submitted a pull request that might solve this issue, I pretty much ended up adding a subscription to SDL.Event.TextInputEvent. Here's the pull request