Results 1 to 5 of 5

Thread: X11 KeySyms and KeyCodes

  1. #1
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45

    X11 KeySyms and KeyCodes

    For the past few days, I've been working on an X11 layer to replace SDL in my future applications. All has been nice sailing up until now where I've arrived on stranger tides

    Ok, jokes aside, I have this:

    Code:
    PMEvent.LastKeyDown := XKeySymToKeyCode(Display, XLookupKeySym(@event.xkey, 0));
    and
    Code:
    PMEvent.LastKeyDown := Display, XLookupKeySym(@event.xkey, 0);
    Now although both appear to work - they do not work the way they should. The first implementation results in the following behaviour:
    q=24, w=25, e=26 and so on for each row of keys on the keyboard
    The second implementation returns the 'correct' values and can be reliably fed from Ord() and into char() however pressing up, esc etc results in values over 65,000!

    Has anyone come up with a solution to this - or at least can find a way of getting these to match the 'correct' sdl and readkey() keycodes?
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #2
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Code:
    vKey:=XKeycodeToKeysym(Event.xkey.display,Event.xkey.keycode,0);
    this returns a Integer value which is mapped to the table in keysym unit. so for the up key = XK_Up = $FF52; { Move up, up arrow }
    you will have to use this table to convert them to something else.

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Oh boy, I feared as much

    Looks like I have some constants to type out. Well thanks for clearing that up there carver.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4
    I'm using scancodes everywhere and here is my old solution...
    Code:
    function xkey_to_scancode( XKey, KeyCode : Integer ) : Byte;
    begin
      case XKey of
        XK_Pause:        Result := K_PAUSE;
    
        XK_Up:           Result := K_UP;
        XK_Down:         Result := K_DOWN;
        XK_Left:         Result := K_LEFT;
        XK_Right:        Result := K_RIGHT;
    
        XK_Insert:       Result := K_INSERT;
        XK_Delete:       Result := K_DELETE;
        XK_Home:         Result := K_HOME;
        XK_End:          Result := K_END;
        XK_Page_Up:      Result := K_PAGEUP;
        XK_Page_Down:    Result := K_PAGEDOWN;
    
        XK_Control_R:    Result := K_CTRL_R;
        XK_Alt_R:        Result := K_ALT_R;
        XK_Super_L:      Result := K_SUPER_L;
        XK_Super_R:      Result := K_SUPER_R;
        XK_Menu:         Result := K_APP_MENU;
    
        XK_KP_Divide:    Result := K_KP_DIV;
      else
        Result := ( KeyCode - 8 ) and $FF;
      end;
    end;
    
    // Somewhere in code
    xkey_to_scancode( XLookupKeysym( @event.xkey, 0 ), event.xkey.keycode );
    Last edited by Andru; 29-08-2011 at 07:29 PM.

  5. #5
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Not a bad snippet there. After further study I did find that if made a simple console application and wrote out the Ord(Readkey()) I could get it to match the X11 keysyms as scancodes or whatever.... So I guess I will have to make do with 'non-sdl compatible' code

    Not a big deal - just me being picky.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL