keyboard input problems in XNA (dealbreaker)

Monkey Targets Forums/XNA/keyboard input problems in XNA (dealbreaker)

Rushino(Posted 2013) [#1]
Hi guys, i currently have a rather big problem which could make me abandon the xna target (which i don't want to obviously because i will be stuck on html 5 target) i try to get specials keyboard to work in xna. Right now i can only capture A-Z a-z and 0-9 with GetChar () which is quite of lame because my users might (or will probably) want to use others characters which invole pressing SHIFT+2 to get @ (that is an example).However the XNA target input system is quite lame. I can't even have the SHIFT key. Do anyone experienced such a thing or have a solution to this? Is there others ways to get special chars such / " & , # - ?? Such by bypassing XNA input system.


skid(Posted 2013) [#2]
After testing bananas/mak/keyboardtest on xna target it seems that GetChar is not only ignoring many chars as you note, but also reporting each keyhit twice.

The solution is of course to post bug report so this can be fixed asap.


Rushino(Posted 2013) [#3]
I posted it in bug report. Thanks for confirming. Hopefully this get fixed because i don't want to be restricted to html 5. I wanted a standalone executable too.


Rushino(Posted 2013) [#4]
Found a little hack for now but its not very good. At least it work. It support only US layout. Please note this code is not refactored at all. I just added an example on how to bypass the problem.

[monkeycode]
#IF TARGET = "xna"

Local isShift:Bool

If KeyDown(KEY_SHIFT)
isShift = True
Else
isShift = False
End If

If KeyHit(KEY_1) And isShift
Before = Before + "!"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_2) And isShift
Before = Before + "@"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_3) And isShift
Before = Before + "#"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_4) And isShift
Before = Before + "$"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_5) And isShift
Before = Before + "%"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_6) And isShift
Before = Before + "?"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_7) And isShift
Before = Before + "&"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_8) And isShift
Before = Before + "*"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_9) And isShift
Before = Before + "("
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_0) And isShift
Before = Before + ")"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_MINUS)
Before = Before + "-"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_COMMA)
Before = Before + ","
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_PERIOD)
Before = Before + "."
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_OPENBRACKET)
Before = Before + "{"
N.Cursor = N.Cursor + 1
Else If KeyHit(KEY_CLOSEBRACKET)
Before = Before + "}"
N.Cursor = N.Cursor + 1
End If
... and so on ...
#ENDIF
[/monkeycode]