maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   SDL apps do not accept Fn key combos on N810 (https://talk.maemo.org/showthread.php?t=15501)

ArnimS 2008-01-22 03:03

SDL apps do not accept Fn key combos on N810
 
My tested SDL apps do not accept Fn key combos on N810

This pretty much cripples dosbox and any game requiring numeric input. Have I overlooked something?

If anyone has a clue how to fix, please post here. If/when I find a solution i'll do the same.

Cheers.

------------------------
edit; incorrect. some sdl apps do accept fn key - gemrb works - when it accepts keyboard input at all.

tobiasj 2009-03-10 15:03

Re: SDL apps do not accept Fn key combos on N810
 
Did you ever figure out why some do and some do not?

One I am trying to port now needs the number keys and does not accept fn keys.

If there is something simple I can do to make it work with the fn key I would rather that than say remap the responses from numbers to q w e r t y and try to remember that q = 1 and w = 2 and such...


Thanks!

-John

fanoush 2009-03-10 17:35

Re: SDL apps do not accept Fn key combos on N810
 
You need to call SDL_EnableUNICODE(1) at runtime. Both keys (fn+key) need to be pressed though.

tobiasj 2009-03-10 19:47

Re: SDL apps do not accept Fn key combos on N810
 
Quote:

Originally Posted by fanoush (Post 270485)
You need to call SDL_EnableUNICODE(1) at runtime. Both keys (fn+key) need to be pressed though.

Thanks for the info and the link, looks easy enough but my near complete ignorance of programming in c or C++ comes out now and I have to ask, how, no, where, ok wait, so this At Runtime part is whats getting me. I have tried inserting that into the code a few different places, and the places I think it should go either are not correct or something more than this call is needed because it still doesn't like the fn + [key] combinations though all normal keypresses still work properly.

Is there some example code I can peek though that uses this call to give me an idea where it should be put? My own thought was right here...

Code:

    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
                        SDL_DEFAULT_REPEAT_INTERVAL);
    SDL_EnableUNICODE(1);

but if that is correct, then it isn't enough to make it work.

Thanks again

-John "Strugglin' through it just because it's fun" Tobias

fanoush 2009-03-10 20:54

Re: SDL apps do not accept Fn key combos on N810
 
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)

fanoush 2009-03-10 21:22

Re: SDL apps do not accept Fn key combos on N810
 
It is a bit confusing but it makes sense. SDL is too low level. Since you really press fn and t keys you always get keycodes for fn and t. The enable unicode part enables additional calls inside SDL to translate those raw keys according to current keyboard mapping. it is same like shift + a, you get keycodes for shift and a and this translates into upppercase A

tobiasj 2009-03-11 02:24

Re: SDL apps do not accept Fn key combos on N810
 
That does make sense and in looking at the code it is:

Code:

switch (event.key.keysym.sym) {
      case SDLK_ESCAPE:
              key_esc_pressed = 1;
              break;
      case SDLK_LSHIFT:
              key_shift_pressed = 1;
              break;

etc etc...

so, it isnt, of course, checking unicode. That means a bit more tweaking in order to get it working. Thanks for all the information you explained it perfectly. Course while testing this I also came to the conclusion that the mouse isnt working either. I mean, there is a pointer, and it moves to where you click, however it doesnt 'read' the click and do anything with it. I am going to leave that until I get everything else working because you CAN play the game completely without using the mouse if you remember all the shortcut keys (t = talk, a = attack etc.) So if I can get all the keys working then the mouse is far less important. (well except for N800 users..) but I will fix that eventually (well I hope I will, this crash course on SDL has been enlightening. to say the least.)

Thanks again,

-John

tobiasj 2009-03-11 12:40

Re: SDL apps do not accept Fn key combos on N810
 
Quote:

Originally Posted by fanoush (Post 270550)
It is a bit confusing but it makes sense. SDL is too low level. Since you really press fn and t keys you always get keycodes for fn and t. The enable unicode part enables additional calls inside SDL to translate those raw keys according to current keyboard mapping. it is same like shift + a, you get keycodes for shift and a and this translates into upppercase A

That was the ticket, I made the change to keysym.unicode from keysym.sym and it now accepts the number keys.

I can not thank you enough for your patient instruction and help.



Thanks,

-John

tobiasj 2009-03-15 17:01

Re: SDL apps do not accept Fn key combos on N810
 
fanoush,

I have this working pretty good, however I think I need to change something else. I think, while I am catching the fn+ keys properly, I am now loosing normal keys in some instances. is there a check I need to preform or a different way to identify normal keys (the arrow keys for example up, down left right) while using keysym.unicode instead of keysym.sym? When in the gui now (where I am actually using the unicode) I can use fn+ but I can not use the arrow keys to select a different toon for leader. While it isnt a huge deal, you can use the keyboard shortcut L for this, I would rather have it working correctly you know? Anyway I didnt change anything else, just added unicode on keysym.

Thanks,

-John

fanoush 2009-03-15 18:03

Re: SDL apps do not accept Fn key combos on N810
 
you may try to fallback to use keysym.sym if keysym.unicode value is zero

tobiasj 2009-03-15 19:12

Re: SDL apps do not accept Fn key combos on N810
 
Quote:

Originally Posted by fanoush (Post 271865)
you may try to fallback to use keysym.sym if keysym.unicode value is zero

You are right again, I put this:

Code:

                if (!event.key.keysym.unicode < 0x80 && !event.key.keysym.unicode > 0 ){
                        lotr_keybuffer[lotr_keybufferpos++] =
                        event.key.keysym.sym;
                }


right after and if it wasnt a valid unicode code I diable unicode.

Now you can select the leader using the arrow keys like you are supposed to be able to..

Thanks again,

-John

tobiasj 2009-03-15 21:03

Re: SDL apps do not accept Fn key combos on N810
 
hmmm strange artifact now, if you press any directional arrow to move the toon more than about 3 steps without changing directions or letting off the key and pressing it again it suddenly sends you to the left and no matter what button you press you keep going left until you press left and release it.

I am going to remove the code I just added and see if it goes away. if not then I dont know what caused it. It wasnt doing it yesterday...


-John

Edit: Yes, this code is what is breaking it. so that isnt (obviously) the best way to handle it. It seems to break on the repeated keys. I have to study how repeated keys are handled in SDL and look for a better way to do this.

Edit 2: if I simply do not increment lotr_keybufferpos by removing the ++ everything goes back to normal as if the entire line was not there. no leader select but you can walk without suddenly deciding you really meant to go left... Wonder what the keyboard buffer should be set to. I think it is 16 in the code..

tobiasj 2009-03-16 15:37

Re: SDL apps do not accept Fn key combos on N810
 
Ignore the last few messages please. Thats what I get for trying to code in the middle of the night.

when I diffused the logic bomb that was my code and made it actually make sense it worked SO much better.

It is now functioning properly and as it should have all along.



-John


All times are GMT. The time now is 15:18.

vBulletin® Version 3.8.8