1

Since =~ 2 years, it seems like we can't use the Super key (aka windows key) to run some keyboard shortcuts.

I try with kde, gnome, xfce4, none works totally.

By example, I have a keyboard shortcut to type the date like if I typed it assigned via Super+a, when I hit this keys, nothing happens.

The command line is bash -c 'xvkbd -xsendevent -text $(date +%Y%m%d)' configured correctly in xfce4 preferences.

I currently use archlinux x86_64, with kernel 4.15.1-2-ARCH.

Anyone knows what's wrong ? Where ? Is there a fix ? A workaround ?

1

The key shortcut used is not the issue

You can check that the keyboard shortcut is being successfully set by replacing your bash … command with xterm (or some other graphical application). If a window appears, your shortcut is correctly set. The issue is instead almost certainly the desired command:

bash -c 'xvkbd -xsendevent -text $(date +%Y%m%d)'

In my experience, the use of XSendEvent is unreliable.1 That might instead be the source of your issue. Using xdotool one can select between XTEST and XSendEvent, and the former generally works for me. Your xvkbd may have similar options.

When sending key-sequences, you need to clear the current modifiers in order to ensure you are sending the sequence you want (e.g. test and not Super+t, Super+e, etc.)

Further, xdotool at least has a strange behavior where if it sends events too soon, they disappear.2 This may in fact be the X server dropping events, or it may be something entirely different. In any case, you can get around this (at least in xdotool) with a delay:

xdotool sleep 0.125 type --clearmodifiers 'string to type'

The type subcommand has a --delay option in case the initial delay is not sufficient to prevent dropping events.

In summary

I would use:

bash -c 'xdotool sleep 0.125 type --clearmodifiers --delay 125 "$(date +%Y%m%d)"'

to replicate your intended behavior, though the values used for sleep and --delay may need adjustment, depending on your setup.

Another possible option

If you don't mind clobbering your clipboard, a better approach might be to send the default shortcut for paste selection:

bash -c 'printf "%s" "$(date +%Y%m%d)" | tee >(xsel -bi) | xsel -i; xdotool sleep 0.125 key --clearmodifiers shift+Insert'

This uses xsel to put the desired text into both the CLIPBOARD and PRIMARY selections (as ShiftInsert is not consistent in which one it uses). It then synthesizes the key sequence to paste this selection. As this requires only two synthesized keypresses, it is less likely to drop events than the other method.


1 From xdotool(1):

SENDEVENT NOTES

If you are trying to send key input to a specific window, and it does not appear to be working, then it's likely your application is ignoring the events xdotool is generating. This is fairly common.

Sending keystrokes to a specific window uses a different API than simply typing to the active window. If you specify 'xdotool type --window 12345 hello' xdotool will generate key events and send them directly to window 12345. However, X11 servers will set a special flag on all events generated in this way (see XEvent.xany.send_event in X11's manual). Many programs observe this flag and reject these events.

It is important to note that for key and mouse events, we only use XSendEvent when a specific window is targeted. Otherwise, we use XTEST.

Some programs can be configured to accept events even if they are generated by xdotool. Seek the documentation of your application for help.

Specific application notes (from the author's testing):

  • Firefox 3 seems to ignore all input when it does not have focus.
  • xterm can be configured while running with ctrl+leftclick, 'Allow SendEvents'
  • gnome-terminal appears to accept generated input by default.

2 I will revisit this answer and expand upon this point if I learn exactly why this is the case.

  • None woks : xdotool type foobar or xvkbd -text foobar with the keyboard shortcut. This just makes some RANDOM xorg bugs – Gilles Quenot Feb 10 '18 at 18:38
  • 1
    And, yes, I can trigger any app from the keyboard shortcut – Gilles Quenot Feb 10 '18 at 18:44
  • If I set 'xdotool type foobar', I have at least 3 keyboards shortcuts ran at the same time configured with another keyboard shortcuts... It's like if I run xdootool or xvkbd, it makes some random keyboard shortcuts – Gilles Quenot Feb 10 '18 at 19:20
  • When I was using kde, I was seeing in terminal some very strange output like if I typed some random keys when I was triggering the combos – Gilles Quenot Feb 10 '18 at 19:29
  • Let us continue this discussion in chat. – Fox Feb 10 '18 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.