#### Archived

This topic is now archived and is closed to further replies.

# sdl & keys

This topic is 5379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i''m currently using sdl for input in my current project. everything works fine except one thing: getting the actual pressed char! (i.e. if i press shift+''a'' to get an ''A'' or shift+1 to get ''!'') also it seems to have a problem with german keyboard mapping on windows (''y'' for ''z'' and the like) but _not_ on linux! would be great if anybody could help me... thanks in advance mfg Phreak -- "Input... need input!" - Johnny Five, Short Circuit.

##### Share on other sites
I think SDL_GetKeyName() does that. The man page is pretty vague though on exactly what it does.

I would suggest just creating a table of values that map SDL keysyms to ASCII characters. Have three values in each entry: the keysym itself, one for the lower case (no shift) character, and one for the upper case character. You''d just need to create one entry for each key on the keyboard that generates an ASCII code (you wouldnt need to do half of the keys like the F-keys for the arrow keys).

##### Share on other sites
yea thats quite exactly my current solution but i need this actually for every key and not only shift but also alt and so on (i need it as input for my console) and possibly faster than that.

regarding SDL_GetKeyName():
thats actually not what i need cos it just gives me a strig for the keysym (i.e. "f1" if i press the f1 key, not tested but just a (educated? ) guess from the doc)

mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.

##### Share on other sites
I''m not quite sure what you want. You say you need it as input for your console? Are you talking about like a PS2 or something here?

What I gather you are wanting to do is translate individual key presses into ASCII codes for text entry. The best way to do this is probably to set up a translation table like I said; you shouldn''t need alt and control cases because they don''t modify the resulting character (well, control throws a few weird control characters like the bell and EOF but you probably aren''t concerned with this).

I don''t understand how anything would be faster than this. The translation should just take O(1) time if you set it up right.

##### Share on other sites
Perhaps the Unicode functionality is what you need? You might try searching the SDL mailing list archives.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

##### Share on other sites
console is meant in the ''in-game console'' way (like quake)

of the modifiers is at least alt used (produces things like ''{'' ''['' and so on (at least on german keyboards))

Kylotan:
i''m currently trying that but that requires some rewrites, also what really bugs me is the wrong keytable sdl seems to use on my windows sys but not on my linux sys so i don''t think it will be resolvable by unicode translation
on the other hand i''ve been looking into the unicode functions before and they seem to work too late in the event processing queue to be of any real use for my problem

mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.

##### Share on other sites
heres what i use...

if ( ( event->key.keysym.unicode & 0xFF80 ) == 0 ){	ASCII_char = event->key.keysym.unicode & 0x7F;}else{	ASCII_char = 0;}

- jeremiah

inlovewithGod.com

##### Share on other sites
sometimes i love the sdl doc....

Kylotan:
it was the unicode translation!
thx now also the language stuff works (like a ''y'' for a ''z'' ).

if only the docs were better on this subject...

anyways big thanks to everyone

mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.