Jump to content
  • Advertisement
Sign in to follow this  
storage

SDL input and international keyboards?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to get international characters to work with SDL. The closest I've come is to convert event.key.keysym.unicode, which is Uint16 to char, and it worked semi-well, but the international characters are wrong, a character does show up, but it's not the right one. I used Drew_Benton's code, and just printed the char of the Uint16, which displayed most characters correct, but not all (most of them characters like Å, Ä, Ö), and I know this is not the proper way of doing this, but it was one of the few things I could think of, maybe because I'm tired :). I've been searching these forums, the SDL mailing list, I've read this and other stuff on that site aswell, but nothing has been able to display my international characters (like å, ä, ö etc). So if there is an easy way (or any way at all, really) to display international characters or properly convert the unicode number to a character, please, feel free to help me out, and thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
You have brought up a good point that I never anticipated being a problem with that code [smile]. Here is something from the SDL_Keyboard.h file:


/*
- The 'unicode' translated character is only available when character
translation is enabled by the SDL_EnableUNICODE() API. If non-zero,
this is a UNICODE character corresponding to the keypress. If the
high 9 bits of the character are 0, then this maps to the equivalent
ASCII character:
char ch;
if ( (keysym.unicode & 0xFF80) == 0 ) {
ch = keysym.unicode & 0x7F;
} else {
An international character..
}
*/








So I am not sure how you could go about printing out the international keys, but to handle them, you would have to make this change I believe:

if ( event.type == SDL_KEYDOWN ) // keydown
{
if ( (event.key.keysym.unicode & 0xFF80) == 0 )
{
printf( "%c\n", event.key.keysym.unicode & 0x7F );
keydown_list[ event.key.keysym.unicode & 0x7F ] = 1;
donotrelease_list.push_back( event.key.keysym.unicode & 0x7F );
}
else
{
//An international character, see if this makes the right character display
printf( "%c\n", event.key.keysym.unicode );

}

// If you want to store any of this as well...
if( event.key.keysym.unicode )
{
//printf( "UNI: %i\n", event.key.keysym.unicode );
//printf( "SYM: %i\n", event.key.keysym.sym );
//printf( "MOD: %i\n\n", event.key.keysym.mod );
}
}







So I guess you can play around with it a bit. I would be glad to help you out some more if possible, but I do not have an international keyboard to try this one. Let me know. I could do some more searching as well to resolve this issue.

- Drew

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
You have brought up a good point that I never anticipated being a problem with that code [smile]. Here is something from the SDL_Keyboard.h file:

*** Source Snippet Removed ***

So I am not sure how you could go about printing out the international keys, but to handle them, you would have to make this change I believe:
*** Source Snippet Removed ***

So I guess you can play around with it a bit. I would be glad to help you out some more if possible, but I do not have an international keyboard to try this one. Let me know. I could do some more searching as well to resolve this issue.

- Drew


Thanks for your fast answer and for your help! :)

This:

else
{
//An international character, see if this makes the right character display
printf( "%c\n", event.key.keysym.unicode );

}



Displays the same thing as when I tried converting the unicode number to char (your code does this too, I think). Almost every character on my keyboard works, except the international characters, and some special characters like ´ ` ½ § etc.

And the only thing I can think of at the moment (still tired, need to sleep :)), is to manually replace every character that appears incorrect with the right one, for example
Õ -> å
õ -> ä
÷ -> ö
┼ -> Å
─ -> Ä
Í -> Ö


So if there is a better way than to manually convert many, many characters, feel free to help! :)

And thanks again Drew_Benton

Share this post


Link to post
Share on other sites
No problem! Now let's see. I did some looking and I think the problem is that the size of the characters is larger then what I have. Give this a try:

vector <Uint32> keydown_list;
vector <Uint32> donotrelease_list;

I think all that is really needed is 16, but better safe than sorry [wink]. See if that works in the original code.

- Drew

New forums!!! [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
No problem! Now let's see. I did some looking and I think the problem is that the size of the characters is larger then what I have. Give this a try:

vector <Uint32> keydown_list;
vector <Uint32> donotrelease_list;

I think all that is really needed is 16, but better safe than sorry [wink]. See if that works in the original code.

- Drew

New forums!!! [grin]


Thanks again!

But your code doesn't change anything, even though I tried :), since the code for printing the unicode stuff never touches the vectors.

This is what I currently use to view the character, and some information about it (your code, but changed %i to %c at UNI to display the character instead of the number):

if( event.key.keysym.unicode )
{
printf( "UNI: %c\n", event.key.keysym.unicode );
printf( "SYM: %i\n", event.key.keysym.sym );
printf( "MOD: %i\n\n", event.key.keysym.mod );
}






If I'm doing something wrong (very probable), tell me :)

Thanks again!

Share this post


Link to post
Share on other sites
Ok I *think* I got it now - printf does not display unicode, try using this:

wprintf( "UNI: %c\n", (Uint32)event.key.keysym.unicode );


Please work [lol]. See if that does it. Here's the MSDN link refering to printf and wprintf.

- Drew

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Ok I *think* I got it now - printf does not display unicode, try using this:

wprintf( "UNI: %c\n", (Uint32)event.key.keysym.unicode );


Please work [lol]. See if that does it. Here's the MSDN link refering to printf and wprintf.

- Drew


Nope, no change >:(

wprintf( L"UNI: %c\n", (Uint32)event.key.keysym.unicode );

Didn't atleast, I've never really used wprintf, so I don't know if you can change the 'L' (bold in code) for something else.

Thanks once again!

Share this post


Link to post
Share on other sites
Well here's one more suggestion. I found this page and it shows some stuff in Unicode.

Try using:

printf( "UNI: %lc\n", (Uint32)event.key.keysym.unicode );

If that does not work see if setting the local on that link will fix it as well.

Share this post


Link to post
Share on other sites
I hate to say this but, I think it has been working all the time, except that it can't display it in the console properly, because I just tried it in an SDL project I was working on earlier, and it prints international characters like a charm!

Image Hosted by ImageShack.us
Using SDL_TTF.

Thanks ALOT Drew! You're my hero! :)

Edit: Font is a little messed up but I think you can see that it works :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!