Game.Window.TextInput event is a lifesaver that I am shocked isn't discussed more

Not a query here, I just want to express my exasperation that when I first started using MonoGame/XNA, none of the tutorials pointed me towards polling keyboard text input via the Game.Window.TextInput event.

If you search for “MonoGame/XNA Keyboard Input” you will find dozens of solutions where people are relying on KeyboardStates and setting up dictionary lookups from the Keys enum to respective chars and conditional logic to allow their users to write text into their game window while accounting for things like shift presses, backspace etc., which were still imperfect because I’m fairly sure that doesn’t account for regional keyboards (not all keyboards represent “+” with “Shift+=”, I think).

I was doing the same thing, until I came across a few mentions of this event, and the e.Character argument will return a char, accounting for shift presses, capslock, and even hold-down multipress with only a single line of code?! Why don’t more tutorials include this functionality! Judging by my google results, hundreds of people are building homebrew solutions for something that is apparently already built-in. :smiley:

Anyway, no real conclusion here, I guess I just wanted to raise awareness that this feature exists. Maybe this is something people are more aware of if they’d previously worked with Windows Forms, because I believe this is based off of functionality that exists there?

3 Likes

Cross Platform? Or specific to Windows?

According to this, it’s supported on Windows DirectX, Windows OpenGL and Linux platforms.

The reason I didn’t use it was cross platform support. I know if could just do #If WINDOWS but Iv had stuff like that bite me in the backside before. Now wherever possible I make everything multiplatform. Now my editors will run on any platform if I even have the need, and I don’t have to cut them out of my release anymore as it’s all 100% compatale.