Hello,

While porting my program to Linux, I encountered the following error.
If the keyboard layout is English (USA) then KeyboardEventHandler
works fine. But if it's something else, Russian for example,
ea.getKey() always returns zero. (Except system keys F1 - F12 and
digits)

It's the case for Kubuntu 9.04 and SUSE 11.1 (KDE)
In WindowsXP and Vista everything works fine.

The usage of KeyboardEventHandler:

bool KeyboardEventHandler::handle(
const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
{
   switch(ea.getEventType())
   {
       case(osgGA::GUIEventAdapter::KEYDOWN ):
       {
           int _key = ea.getKey();
           std::cout << "key= " << _key << std::endl;



.............


I think I've found the reason of keyboard layout problem in Linux.

Executing the debug process, I "found" where the key code had been
lost. The problem was in GraphicsWindowX11::adaptKey function, to be
more precise in the following:

"
if (remappedKey & 0xff00)
{
    // special keyboard character
    keySymbol = remappedKey;
}
else
{
    // normal ascii key
    keySymbol = keybuf[0];
}
"

if we replace/remove that conditional branch, i.e. use only that:
"
{
     // special keyboard character
     keySymbol = remappedKey;
}
"
everything works fine :)

I couldn't understand the aim of developers, what is that "else" for, anyway?

"
else
 {
     // normal ascii key
     keySymbol = keybuf[0];
 }
"
if remappedKey holds the right value anyway (not only for special
keyboard character)


Could we send this into OpenSceneGraph Submissions?


my GraphicsWindowX11::adaptKey:

void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol)
{
   Display* display = _eventDisplay;

   unsigned char keybuf[32];
   XLookupString( &keyevent, (char *)keybuf, sizeof(keybuf), NULL, NULL );

   KeySym ks = XKeycodeToKeysym( display, keyevent.keycode, 0 );
   //osg::notify(osg::INFO)<<"+KeySym ks = "<< ks <<  std::endl;
   int remappedKey = remapX11Key(ks);
   //osg::notify(osg::INFO)<<"+int remappedKey = "<< remappedKey <<  std::endl;
   //if (true)  //remappedKey & 0xff00
   //{
       // special keyboard character
       keySymbol = remappedKey;
   //}
   /*
   else
   {
       //NOT OK
       // normal ascii key
       keySymbol = keybuf[0];
   }
   */
   //osg::notify(osg::INFO)<<"+keySymbol = "<< keySymbol <<  std::endl;
}


-- 
Maxim Gammer
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to