jordansissel / xdotool

fake keyboard/mouse input, window management, and more
Other
3.21k stars 318 forks source link

xdotool could not produce some key event. #151

Open nemonein opened 7 years ago

nemonein commented 7 years ago

Hi. I'm using xdotool with xbindkeys, on Ubuntu 16.04. I used the latest version(v3.20160805.1) of xdotool. And I use US Dvorak keyboard. This caused this problem. Using US Qwerty keyboard works fine.

To make the story short, under US Dvorak keyboard, Control_L+v, and Control_L+x do not work. ............................................................

I set .xbindkeysrc like this.

# Ctrl+v (Dvorak Ctrl+k)
"xdotool key --delay 0 --clearmodifiers Control_L+v"
  Release + Control + k

# Ctrl+c (Dvorak Ctrl+j)
"xdotool key --delay 0 --clearmodifiers Control_L+s"  
  Release + Control + j

"xdotool key --delay 0 --clearmodifiers Control_L+s" works fine, however, "xdotool key --delay 0 --clearmodifiers Control_L+v" do not send any signal.

I tested this with xev, and here are the results.

"xdotool key --delay 0 --clearmodifiers Control_L+s"

KeyPress event, serial 140, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113423, (114,-15), root:(1185,37),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 140, synthetic NO, window 0x4200001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 140, synthetic NO, window 0x4200001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 140, synthetic NO, window 0x0,
    keys:  2   0   0   0   32  0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

MappingNotify event, serial 140, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyRelease event, serial 140, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113707, (114,-15), root:(1185,37),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 141, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113711, (114,-15), root:(1185,37),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 141, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113713, (114,-15), root:(1185,37),
    state 0x2014, keycode 39 (keysym 0x73, s), same_screen YES,
    XKeysymToKeycode returns keycode: 47
    XLookupString gives 1 bytes: (13) ""
    XmbLookupString gives 1 bytes: (13) ""
    XFilterEvent returns: False

KeyRelease event, serial 141, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113715, (114,-15), root:(1185,37),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 141, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113716, (114,-15), root:(1185,37),
    state 0x2010, keycode 39 (keysym 0x73, s), same_screen YES,
    XKeysymToKeycode returns keycode: 47
    XLookupString gives 1 bytes: (73) "s"
    XFilterEvent returns: False

KeyPress event, serial 141, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113717, (114,-15), root:(1185,37),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 141, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3113787, (114,-15), root:(1185,37),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

You can see there are KeyPress/Release event for keycode 39('s') between the Control_L press/release events.

However, "xdotool key --delay 0 --clearmodifiers Control_L+v"

KeyPress event, serial 137, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3056783, (136,-19), root:(1207,33),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 137, synthetic NO, window 0x4200001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 137, synthetic NO, window 0x4200001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 137, synthetic NO, window 0x0,
    keys:  0   0   0   0   32  0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

MappingNotify event, serial 137, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyRelease event, serial 137, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3057069, (136,-19), root:(1207,33),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 138, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3057071, (136,-19), root:(1207,33),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 138, synthetic NO, window 0x4200001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 138, synthetic NO, window 0x4200001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 138, synthetic NO, window 0x0,
    keys:  4294967207 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeyPress event, serial 138, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3057077, (136,-19), root:(1207,33),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 138, synthetic NO, window 0x4200001,
    root 0x2a7, subw 0x0, time 3057105, (136,-19), root:(1207,33),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen

There are no key event for the key 'v', between Control_L events.

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

Is there a way to work around this, or can you find what causes this?

nemonein commented 7 years ago

It's been a few months, but no answers. Is there anybody who can help me?

ike9000e commented 7 years ago

Hi. Judging by the message log from xev, looks like the problem mey be with an unwanted focus in-out window events added in between. They're probably added because of how global shortcuts on X11 desktop works. Momentary unfocus of whatever window is currently active. Xbindkeys program does use functions from xlib for that.

If you're sending your keys to the window using two shell commands, one after another, then some keys may get lost when the target window looses focus, for that short period of time. Try adding a delay at the moment Xbindkeys executes shell command, before xdotool begins sending it's keys to the active window: $ xdotool sleep 1.0 key --clearmodifiers Control_L+s

That causes xdotool to wait 1 second, before sending the keys. Which is, of course, unresponsive functionality but if it fixes things, try tweaking it to some lower value. N.b. --delay 0 switch in your original command was unnecessary, as it is for the interval between keystokes, in single command instead.

best.

nemonein commented 7 years ago

@ikk00 Thanks. I tried, but it does not work. I'm not sure, but 'v' and 'x' are not working properly.

xdotool sleep 1 key --clearmodifiers Control_L+v
xdotool sleep 2 key --clearmodifiers Control_L+x