20

This xte command, when I run it in a terminal, triggers Expo mode:

xte 'keydown Super_L' 'key S' 'keyup Super_L'

However, when I put this in my .xbindkeysrc file:

"xte 'keydown Super_L' 'key S' 'keyup Super_L'"
  b:11

Nothing happens when I click the button. The following binding makes the letter X appear in my console when I press button 11:

"xte 'key X'"
  b:11

So why doesn't the Expo binding work?


This is the verbose output of xbindkeys -n -v when clicking button 11:

Button press !
e.xbutton.button=11
e.xbutton.state=16
"xte 'keydown Super_L' 'key W' 'keyup Super_L'"
    m:0x0 + b:11   (mouse)
got screen 0 for window 2bb
Start program with fork+exec call
Button release !
e.xbutton.button=11
e.xbutton.state=16

And nothing happens. Does this have anything to do with the way xbindkeys executes the command? (fork+exec call)


Attempt number two.

expo.sh:

#!/usr/bin/env bash
export DISPLAY=:0
xte 'keydown Super_L' 'key S' 'keyup Super_L'

Executing this script from the command line activates Expo. Binding it in xbindkeys:

"sh ~/expo.sh"
  b:11

Clicking mouse button 11:

Button press !
e.xbutton.button=11
e.xbutton.state=16
"sh ~/expo.sh"
    m:0x0 + b:11   (mouse)
got screen 0 for window 2bb
Start program with fork+exec call

Nothing happens!

Hubro
  • 1,283
  • 6
  • 19
  • 34
  • 1
    You are trying to press ? I know xbindkeys + xte can be picky sometimes. – Seth Jul 19 '14 at 15:27
  • @Seth: Correct. Any way to work around the pickyness? – Hubro Jul 19 '14 at 15:28
  • 1
    Try `'keydown Super_L' 'keydown S' 'keyup S' 'keyup Super_L'`. – Seth Jul 19 '14 at 15:30
  • @Seth: Made no difference I'm afraid :( – Hubro Jul 19 '14 at 15:33
  • Did you relaunch xbindkeys after you made the changes? Sometimes that is necessary. You ultimate goal is to open the workspace overview I guess? – Seth Jul 19 '14 at 15:33
  • @Seth: Yes, I'm using `xbindkeys -n -v` and watching the results in the console. The command was executed (supposedly) but nothing happens. My goal is to open Expo, which opens with the keybind `Super+S`. – Hubro Jul 19 '14 at 15:35
  • `b:11 + Release` helps. Tested on Ubuntu 20.04 – Sean_X Oct 29 '20 at 02:32

6 Answers6

19

Another simpler solution: instead of using just "b:11" in the xbindkeys definition, use "b:11 + release". It will wait until you release the button to fire the command.

Example:

"sh ~/expo.sh"
  b:11 + release
user215129
  • 206
  • 2
  • 2
8

This is very weird. It turns out that if my mouse button is still pressed (not yet released) when the Super+W keystroke is simulated, nothing happens. I don't know who to blame for that (perhaps Cinnamon?). I have worked around it though, by adding a short delay to the xte command:

xte 'usleep 100000' 'keydown Super_L' 'key S' 'keyup Super_L'

It now waits 0.1 seconds before simulating Super+S. If I press and hold the mouse button more than 0.1 seconds, nothing happens.

This is a workaround answer. I'd much prefer a proper answer.

Hubro
  • 1,283
  • 6
  • 19
  • 34
  • Hubro, please see the higher rated answer by user215129 and mark it as correct – David Ljung Madison Stellar Feb 09 '16 at 22:52
  • 1
    @DavidLjungMadison No. It isn't even an answer to my question, just a suggestion for a work-around. – Hubro Feb 10 '16 at 08:32
  • 1
    I wonder if you understand the answer. The problem is that you are trying to send the keys while the button is still down. Waiting for the button *release* means it won't send the keys until the button is released, thereby solving your problem. Not a workaround, it's an explanation of the issue and a way to solve it. – David Ljung Madison Stellar Feb 11 '16 at 10:42
  • @DavidLjungMadison I understand perfectly thank you. I explained the problem in my question, as well as a workaround I've been using. His answer is a better workaround, but still a workaround. I still don't know why holding the button down stops Expo from working, and I've found no solution that lets Expo work on click (mouse down.) – Hubro Feb 11 '16 at 10:56
  • 1
    Then you still don't understand. The *issue* is that you are trying to type keys while the button is down, and whatever launches Expo is looking for Super-S, not Btn-2+Super-S. Your fix *is* a workaround because it doesn't solve the problem by guaranteeing that the button is up, and doesn't work in many circumstances. The solution is (as is often the case in dealing with mouse events) to wait for the button release before triggering any commands, this ensures that the button is not mixed with the keystroke. – David Ljung Madison Stellar Feb 12 '16 at 00:36
  • 2
    Can confirm that user215129 answer is indeed not correct and does not answer the question. Doing my own investigation on this problem right now and in my case changing it to release or delay is not an option because I need it to perform action while button is pressed, with different action on release. See: https://askubuntu.com/questions/984054/how-to-bind-additional-mouse-buttons-to-be-modifiers-shift-control – Esuil Dec 11 '17 at 13:08
2

I faced the same problem.

"xte 'key b'"

was working in the console but not in the xbindkeys parameter file. I changed b by his keysym code, using the "xev" command to obtain it :

"xte 'key Ox62'"

It worked for me

1

Try with +Release

"xte 'keydown Super_L' 'key S' 'keyup Super_L'"
b:11 + Release

That may help.

1

Have similar issue while using sxhkcd keymapper. It turns out your actual shortcut keys are detected as still being pressed.

There are some semi-workarounds:

  • look for the release event
  • add sleep 0.2 in front of your command
  • use shortcut with leader-key
  • release your shortcut modifiers in front of your xte sequence

However you cant get realtime actions with that =)

muru
  • 193,181
  • 53
  • 473
  • 722
0

I have seen this problem of the bound key still being pressed (like shift, control, etc) years ago. I made extensive notes about it in my X windows event handling hints and tips file...

https://antofthy.gitlab.io/info/X/event_handling.txt

One solution as give, is give the user time to release the keys

But a another is to send your own keyup events to release the key for the user!

A third solution is to use xdotool and its --clearmodifiers option... For example typing a email address...

xdotool type  --clearmodifiers -delay 0 '[email protected]'

There is one BIG cavat to watch out for... Recursive Macros May sure your macros does not send the sequence for the same macro! If you do you will have the macro repeating over and over!

anthony
  • 324
  • 2
  • 7