Linux+Swtiching desktops=>CTRL release not registered

This subforum contains all the issues which we already resolved.
Post Reply
ben04
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Mar 25, 2016 6:04 pm
Contact:

Linux+Swtiching desktops=>CTRL release not registered

Post by ben04 »

Hi,

I regularly have my game open on one virtual desktop and my music player open on another. I switch between the desktops using some keyboard shortcuts to change the music that is currently played. After coming back to factorio sometimes believes that the CTRL is being pressed while it isn't.

My shortcuts are configured to CTRL+ALT+Arrow Keys. I run Linux Xubuntu 14.04.4 LTS with Gnome and Xserver.

Exact steps to reproduce:

1. Start factorio
2. Go into fullscreen mode
3. Start some game
4. Walk to tree and chop is down by holding the right mouse button.
5. Switch virtual desktop away from factorio using CTRL+ALT+Right
6. Switch virtual desktop back towards factorio using CTRL+ALT+Left
7. Release first the CTRL key, release then the ALT key
8. Walk to next tree. Holding the right mouse button no longer chops trees because factorio thinks that the CTRL key has never been released.

Fix: Hit the CTRL key a second time while being on the factorio virtual desktop.

The bug does not occur if the ALT key is released before the CTRL key.

This problem happens in fullscreen and window mode.

This is either a bug where Allegro does not generate the ALLEGRO_EVENT_KEY_UP for the CTRL key or a bug in factorio where it does not process the corresponding event correctly.

Anyway, the bug is unproblematic once you realized that you just have to hit the CTRL key to fix it. However, I needed some time to realize this and restarted my game quite often before I figured it out. Restarting the game is annoying. ;)
Last edited by ben04 on Sat Nov 05, 2016 11:05 am, edited 1 time in total.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13223
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Linux+Swtiching desktops=>CTRL release not registered

Post by Rseding91 »

Ahh the classic "control up event doesn't get sent to the application because the application is no longer in focus after switching off it" issue.

I don't think I know 1 piece of software that handles that perfectly :P
If you want to get ahold of me I'm almost always on Discord.

ben04
Burner Inserter
Burner Inserter
Posts: 7
Joined: Fri Mar 25, 2016 6:04 pm
Contact:

Re: Linux+Swtiching desktops=>CTRL release not registered

Post by ben04 »

I think the easiest "fix" is to pool the keyboard state every 500ms or so in addition to handling the key press and release events. The CTRL key state would still be broken for 500ms but I doubt that a user would notice. If the key synchronization is fast enough, one could also go down to 100ms or so. Then definitely nobody will notice. This should be a very robust solution with respect to non-generated key events on all platforms.

Here is some code to illustrate what I have in mind:

Code: Select all

// globals
bool pressed_keys[ALLEGRO_KEY_MAX]; // I assume that you have something like this in your code base
double last_timepoint_when_keyboard_was_syncronized = 0.0;

// at the end of the event loop
double now = al_get_time();
if(now - last_timepoint_when_keyboard_was_syncronized >= 0.5){
        last_timepoint_when_keyboard_was_syncronized = now;
        ALLEGRO_KEYBOARD_STATE keyboard_state;
        al_get_keyboard_state(&keyboard_state);
        for(int i=0; i<ALLEGRO_KEY_MAX; ++i){
                if(pressed_keys[i] != al_key_down(&keyboard_state, i)){
                        if(pressed_keys[i]){
                                // handle key up event for keycode i
                        } else {
                                // handle key down event for keycode i
                        }
                }
        }
}

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Linux+Swtiching desktops=>CTRL release not registered

Post by kovarex »

I made a small change, that on display found and drawing resume events, the keyboard state is reset.

Post Reply

Return to “Resolved Problems and Bugs”