skip to Main Content

I am developing a linux application that uses the xtest extension to replay key presses taken by the x11 record extension. While testing the replaying of inputs, if I exit early it sometimes leaves The Virtual Core XTEST keyboard with keys that are still pressed. Please see the outputs below:

# DISPLAY=:0 xinput --list
â¡ Virtual core pointer                         id=2    [master pointer  (3)]
â   â³ Virtual core XTEST pointer               id=4    [slave  pointer  (2)]
â   â³ Mouse0                                   id=6    [slave  pointer  (2)]
â   â³ elographics                              id=8    [slave  pointer  (2)]
⣠Virtual core keyboard                        id=3    [master keyboard (2)]
    â³ Virtual core XTEST keyboard              id=5    [slave  keyboard (3)]
    â³ Keyboard0                                id=7    [slave  keyboard (3)]
# DISPLAY=:0 xinput --query-state 5 | grep down
        key[55]=down
        key[103]=down

I need a command to reset those keys and unfortunately xdotool is not an option on the platform I work on (Centos 6.10) which strictly can only use tools from the repositories.

I have tried using

setxkbmap

This does not reset the key states though. I would be very grateful if anyone knows a decent alternative to xdotool to do this.

Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    I found and answer using code at least, rather than a given utility. In my Object destructor (I'm working with c++) I have made a loop that passes a key release signal to the test keyboard like so:

    xcb_setup_t const *xcbSetup = xcb_get_setup(this->xcbConnection);
    
    
    for(size_t keyCode = xcbSetup->min_keycode; 
        keyCode <= xcbSetup->max_keycode; 
        keyCode++) {
    
        xcb_test_fake_input(this->xcbConnection,
                            XCB_KEY_RELEASE, keyCode,
                            XCB_CURRENT_TIME, XCB_NONE,
                            0, 0, 0);
     }
    
     xcb_flush(this->xcbConnection);
    

    The above assumes you have an open connection, I was reluctant to do it at first to avoid mayhem but because it's all key releases it doesn't cause any problems. Make sure to use the setup min and max codes or you will generate a bad value error.


  2. I had this same problem with Barrier (formerly Synergy). I know you said you don’t want to use xdotool, but for the benefit of anyone else stumbling across this from Google, this is how you can do it:

    $ xinput --query-state 5 | grep down
        key[133]=down
        key[134]=down
        key[135]=down
        key[206]=down
        key[207]=down
    
    $ xdotool keyup 133 134 135 206 207
    

    If xdotool isn’t available, you could always try it from another machine if your X permissions are fairly loose:

    machineA$ DISPLAY=machineB:0 xdotool ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search