Game Engine Forum - Grit Open Source Streaming Game Engine
Site Header
It is currently Fri Nov 17, 2017 7:22 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: keyboards stops working after launch
PostPosted: Fri Mar 27, 2015 12:25 pm 
Offline
Newbie
User avatar

Joined: Thu Jul 11, 2013 1:04 pm
Posts: 41
Location: France
Hey guys Its been a long time :hehe: ,
So I'm running the latest build of the game engine on Ubuntu 14.10 and as the title says the keyboard stops working after a short time Is it because of my keyboard setup?
Anyway the only thing I'm able to do is Alt-F4 :facepalm: .


Last edited by Paer76 on Mon Mar 30, 2015 11:14 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: keyboards stops working after launch
PostPosted: Sun Mar 29, 2015 11:45 am 
Offline
Supreme Tyrant of All
Supreme Tyrant of All
User avatar

Joined: Sat Mar 27, 2010 1:13 pm
Posts: 769
It works for me, can anyone else see if they get this? Paer can you check you're using latest svn?


Top
 Profile  
 
 Post subject: Re: keyboards stops working after launch
PostPosted: Sun Mar 29, 2015 11:46 am 
Offline
Supreme Tyrant of All
Supreme Tyrant of All
User avatar

Joined: Sat Mar 27, 2010 1:13 pm
Posts: 769
technicaardvark also reported it


Top
 Profile  
 
 Post subject: Re: keyboards stops working after launch
PostPosted: Sun Mar 29, 2015 2:06 pm 
Offline
Newbie

Joined: Sat Mar 28, 2015 3:18 pm
Posts: 2
Location: Australia
Spark, if I can help test anything or whatever, just give me a yell


Top
 Profile  
 
 Post subject: Re: Keyboards stops working after launch
PostPosted: Mon Mar 30, 2015 11:14 am 
Offline
Newbie
User avatar

Joined: Thu Jul 11, 2013 1:04 pm
Posts: 41
Location: France
I downloaded the latest revision using SVN checkout... And still nothing.
I tried changine the kayboard settings by disabeling iBus in language settings (this worked for Urban terror). But nothing worked either. :/


Top
 Profile  
 
 Post subject: Re: keyboards stops working after launch
PostPosted: Thu Oct 05, 2017 12:36 pm 
Offline
Newbie

Joined: Wed Oct 04, 2017 10:54 pm
Posts: 1
I have the same problem.
After a bit of debugging I found out that after some time the XServer seems to send KeyRelease events followed by KeyPressed events even if the key was released for several seconds in between.
This confuses the code that filters the autorepeat events.
I have no idea where the release events are coming from.
However, the following patch seem to fix it for me.
I also reduced the number of places where add_key(r, last_event, -1); is called as the code was really hard to understand.
Code:
diff --git a/engine/linux/keyboard_x11.cpp b/engine/linux/keyboard_x11.cpp
index 91e7071..9fd7ec1 100644
--- a/engine/linux/keyboard_x11.cpp
+++ b/engine/linux/keyboard_x11.cpp
@@ -202,10 +202,7 @@ Keyboard::Presses KeyboardX11::getPresses (void)
     XEvent event;

     //Poll x11 for events
-
-    bool last_was_release = false;
-    KeySym last_key = 0;
-    XEvent last_event;
+    bool pressed = false;

     while (XPending(display) > 0) {

@@ -215,46 +212,46 @@ Keyboard::Presses KeyboardX11::getPresses (void)

             case FocusIn: {
                 focussed = true;
-                last_was_release = false;
             } break;

             case FocusOut: {
                 focussed = false;
-                last_was_release = false;
             } break;

             case KeyRelease: {
-                if (last_was_release) {
-                    add_key(r, last_event, -1);
+                bool keyHeldDown = false;
+                // if autorepeat is enabled for the XServer, the XServer sends release and press events
+                // even when the key was not released in between
+                // the following code converts such sequences to a key held engine event
+                // the release event is sometimes sent before the press event, therefore the conversion is only done when a
+                // a key is still pressed
+                if (pressed && XEventsQueued(display, QueuedAfterReading))
+                {
+                     XEvent nev;
+                     XPeekEvent(display, &nev);
+
+                     if (nev.type == KeyPress && nev.xkey.time == event.xkey.time &&
+                         nev.xkey.keycode == event.xkey.keycode)
+                     {
+                         XNextEvent(display, &event);
+                         add_key(r, event, 0);
+                         keyHeldDown = true;
+                     }
+                }
+                if (!keyHeldDown)
+                {
+                    add_key(r, event, -1);
+                    pressed = false;
                 }
-                KeySym key = XLookupKeysym(&event.xkey, 0);
-                last_key = key;
-                last_event = event;
-                last_was_release = true;
             } break;

             case KeyPress: {
-                KeySym key = XLookupKeysym(&event.xkey, 0);
-                if (last_was_release) {
-                    if (last_key!=key) {
-                        // different key, add both
-                        add_key(r, last_event, -1);
-                        add_key(r, event, 1);
-                    } else {
-                        add_key(r, event, 0);
-                    }
-                } else {
-                    add_key(r, event, 1);
-                }
-                last_was_release = false;
+                add_key(r, event, 1);
+                pressed = true;
             } break;

         }
     }

-    if (last_was_release) {
-        add_key(r, last_event, -1);
-    }
-
     return r;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Localized by MaĆ«l Soucaze © 2010 phpBB.fr