View Single Post
Posts: 2,152 | Thanked: 1,490 times | Joined on Jan 2006 @ Czech Republic
#5
sorry for confusion, what i meant is that it is method call not some compile time value to #define. The gotcha is probably that you are reading keycodes from keysym.sym field, the translated value is in keysym.unicode field.

here is some random example
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL.h>


void PrintModifiers( SDLMod mod );
    /* Print all information about a key event */
    void PrintKeyInfo( SDL_KeyboardEvent *key ){
        /* Is it a release or a press? */
        if( key->type == SDL_KEYUP )
            printf( "Release:- " );
        else
            printf( "Press:- " );

        /* Print the hardware scancode first */
        printf( "Scancode: 0x%02X", key->keysym.scancode );
        /* Print the name of the key */
        printf( ", Name: %s", SDL_GetKeyName( key->keysym.sym ) );
        /* We want to print the unicode info, but we need to make */
        /* sure its a press event first (remember, release events */
        /* don't have unicode info                                */
        if( key->type == SDL_KEYDOWN ){
            printf("\nkeysym %04X %c\n",key->keysym.sym,key->keysym.sym);
            /* If the Unicode value is less than 0x80 then the    */
            /* unicode value can be used to get a printable       */
            /* representation of the key, using (char)unicode.    */
            printf(", Unicode: " );
            if( key->keysym.unicode < 0x80 && key->keysym.unicode > 0 ){
                printf( "%c (0x%04X)", (char)key->keysym.unicode,
                        key->keysym.unicode );
            }
            else{
                printf( "? (0x%04X)", key->keysym.unicode );
            }
        }
        printf( "\n" );
        /* Print modifier info */
        PrintModifiers( key->keysym.mod );
    }

    /* Print modifier info */
    void PrintModifiers( SDLMod mod ){
        printf( "Modifers: " );

        /* If there are none then say so and return */
        if( mod == KMOD_NONE ){
            printf( "None\n" );
            return;
        }

        /* Check for the presence of each SDLMod value */
        /* This looks messy, but there really isn't    */
        /* a clearer way.                              */
        if( mod & KMOD_NUM ) printf( "NUMLOCK " );
        if( mod & KMOD_CAPS ) printf( "CAPSLOCK " );
        if( mod & KMOD_LCTRL ) printf( "LCTRL " );
       if( mod & KMOD_RCTRL ) printf( "RCTRL " );
        if( mod & KMOD_RSHIFT ) printf( "RSHIFT " );
        if( mod & KMOD_LSHIFT ) printf( "LSHIFT " );
        if( mod & KMOD_RALT ) printf( "RALT " );
        if( mod & KMOD_LALT ) printf( "LALT " );
        if( mod & KMOD_CTRL ) printf( "CTRL " );
        if( mod & KMOD_SHIFT ) printf( "SHIFT " );
        if( mod & KMOD_ALT ) printf( "ALT " );
        printf( "\n" );
    }

/* The screen surface */
SDL_Surface *screen = NULL;
SDL_Surface *fb=NULL;

//Uint32 white,black;
int black=0;
int fullscreen=0;
SDL_Rect rect;


int
main (int argc, char *argv[])
{
    char *msg;
    int done=0;
    SDL_Event event;

    /* Initialize SDL */
    if (SDL_Init (SDL_INIT_VIDEO) < 0){
        exit (1);
    }
    atexit (SDL_Quit);
    /* Set 640x480 16-bits video mode */
    screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        printf ("Couldn't set 640x480x16 video mode: %s\n",
          SDL_GetError ());
        exit (2);
    }
    SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);

    SDL_EnableUNICODE(1);
    /* Check for events */
    while (!done){
        if (SDL_PollEvent (&event)){
            switch (event.type)
            {
                case SDL_KEYDOWN:
                        switch (event.key.keysym.sym){
                        case SDLK_F6:
                                if (SDL_WM_ToggleFullScreen(screen)) fullscreen=!fullscreen;
                                break;
                        case SDLK_q:
                                done=1;
                                break;
                        }
                case SDL_KEYUP:
                PrintKeyInfo( &event.key );
                break;
            case SDL_QUIT:
                done=1;
                break;
            default:
                break;
            }
        }
    }

    exit(0);
when pressing fn+t (=5) it prints
Press:- Scancode: 0x1C, Name: t
keysym 0074 t
, Unicode: 5 (0x0035)
__________________
Newbies click here before posting. Thanks.

If you really need to PM me with troubleshooting question please consider posting it to the forum instead. It is OK to PM me a link to such post then. Thank you.
 

The Following User Says Thank You to fanoush For This Useful Post: