2

xdotool click --clearmodifiers 3 works as right-click in firefox and chromium-browser, but not in all programs such as Thunar file manager and xfce4-terminal. Why is that?

In terminal, if I run the command by entering it there, context menu appears, but if I run the command by keyboard shortcut (set in Xfce's keyboard settings), it does not work.

Anyway, shift + F10 seems to work (though I have to use Fn key in my Macbook keyboard).

jarno
  • 5,317
  • 5
  • 49
  • 77
  • What about just `xdotool click 3`? – DK Bose Jan 13 '19 at 10:20
  • @DKBose same thing – jarno Jan 13 '19 at 10:49
  • 1
    +1 can confirm this. Most likely something to do with Xfce keyboard shortcut. I have since given up and just use the default shortcut `Shift+F10` or `context menu` key. Else `xdotool` always work in command line. –  Jan 13 '19 at 11:30
  • I too can confirm this for Xubuntu 18.04. I made a simple script with just `xdotool click 3` and assigned a shortcut to it. But the same route works just fine in Lubuntu 18.04 and Kubuntu 18.04 for all applications tested. If it's important to you, I suggest also asking at https://forum.xfce.org/. – DK Bose Jan 13 '19 at 12:29
  • 3
    Possible duplicate of [How to create a shortcut that executes an xdotool command to simulate a key press?](https://askubuntu.com/questions/872695/how-to-create-a-shortcut-that-executes-an-xdotool-command-to-simulate-a-key-pres) –  Jan 13 '19 at 17:02
  • @jarno To answer the question "why", see the accepted answer in the linked possible duplicate. –  Jan 13 '19 at 17:04
  • @clearkimura I use `--clearmodifiers`. That should eliminate the effect of simultaneous key presses I think. – jarno Jan 17 '19 at 20:35

1 Answers1

2

xdotool simulates you moving or clicking the mouse, or pressing the keyboard. You trigger the xdotool script with the keyboard, but before you are releasing the key, xdotool already issues the mouse click. For some situations, xdotool may be too fast. The precise reason why it sometimes works, the other time not, is probably only to be found out by experts.

Anyway, try introducing a few ms delay by prepending the xdotool command with a sleep command, e.g.

sleep 0.2 && xdotool click --clearmodifiers 3

would introduce a 200 ms delay before executing the xdotool command.

vanadium
  • 82,909
  • 6
  • 116
  • 186
  • In this case xdotool simulates mouse event. – jarno Jan 13 '19 at 14:22
  • I still do not understand why it does not work without the delay with all applications, but anyway the main thing is that I can make it work now. – jarno Jan 13 '19 at 14:28
  • +1 can confirm this. Related: [This older answer](https://askubuntu.com/a/97784/37165) also suggested a workaround to add delay for making xdotool work properly in Unity/Compiz (cause not known). So not just Xfce issue apparently. –  Jan 13 '19 at 16:53
  • Understand or not: computers are complex systems. Input may not yet be registered if something else is busy, which is why mouse movements and keystrokes are not coming through if not issued on the right moment. I changed my answer because indeed your question is on mouse input. The principle remains, however. – vanadium Jan 13 '19 at 17:23
  • The command seems to corrupt mouse: [Bug](https://bugs.launchpad.net/ubuntu/+source/xfce4-settings/+bug/1812367) – jarno Jan 18 '19 at 09:58
  • Many thanks for this post. Using xdotool to emulate the middle button on an Nvidia Jetson (uses LXDE) required nearly one second delay to get reliable behavior and avoid this erratic bug. This approach to generating the middle button was necessary when using a Microsoft "all in one" keyboard which inhibits 1+3 clicks , preventing "emulate3buttons" with Xorg. – Greg Mar 27 '22 at 02:06