Over the course of time I've often had to deal with Keyboard input - be it using XNA's abstractions or by directly P/Invoking GetKeyState.
But I've often found myself dealing with a different problem: having to transform that input into a string. And I've often lazily 'solved' it by enumerating through the standard ASCII keys and converting them to either letter or number since their KeyCodes directly translate to their ASCII counterparts.
However, I don't quite know how to handle symbols, such as periods, commas, colons, or any other special character that may or may not be on my keyboard. A while ago I found a way to handle modifiers (shift, ctrl+alt) too via P/Invoking VkKeyState and ToAscii (ex. to turn 1 into ! when shift is held), which also works with different keyboard layouts. Still, that leaves the problem that the ASCII code for a period (46) isn't the KeyCode for the period key on my keyboard (190).
And all this leads me to a question: Is the path of pain the only choice I've got? Winforms, games and even console applications handle text input flawlessly, so there is probably some API - be it managed or unmanaged - that I am not aware of and I should be using instead. Any clue would be appreciated.
Side note: My searches through the web often found threads from people (sometimes on this very forum) who wrapped XNA's input handling (KeyboardStates precisely), but not only that's what I've been doing for all this time, it also seems like a bad and heavily hardcoded way of doing things.
Edited by KappaG3, 01 July 2013 - 02:36 PM.