PDA

View Full Version : Keyboard entry



cragwolf
16-03-2006, 02:59 AM
When a user presses Shift+4 on my keyboard, he expects to get the '$' character in his favourite editor. The SDL event manager, on the other hand, will return not the ascii value of '$' but rather the ascii value of '4', and the modstate will have KMOD_LSHIFT or'd into it.

Is there a function in SDL or FreePascal or Delphi which takes an ascii value and a boolean (Shift on or off) and returns the ascii value of the shift character? How would I go about writing this function? I hope I don't have to manually construct a large lookup-table which worked something like this:

if ascii-value = byte('5') and SHIFT then result := '%' else result = '5'
if ascii-value = byte('6') and SHIFT then result := '^' else result = '6'
if ascii-value = byte('7') and SHIFT then result := '&' else result = '7'
etc etc

What a pain in the arse! And how do I know that all keyboards have '&' above the '7' key, '^' above the '6' key, and '%' above the '5' key? There must be some easier way of doing this!

cragwolf
16-03-2006, 03:18 AM
To answer my own question and reveal how lazy I am to RTFM, this will do the job:

Char(event^.key.keysym.unicode)

But you have to enable unicode support:

SDL_EnableUNICODE(1)

Simple solutions for simple minds. :)