Sometimes, when I use synergy between my machines when one is using full-screen VirtualBox guest I get stuck with some weird key modifiers turned on. If they exist on my keyboard (like Shift_L) I can just tap it and their status is reset and I can continue typing in small letters. But some of them are not mapped to my keyboard at all (like ISO_Level3_Shift), so I have no means of turning them off at all!

How to reset them? Right now, all I can do is to reboot the computer, but it's rather embarrassing solution.

All I want is some program that can artificially "tap" all possible keyboard modifiers, so their status would be reset. Can it be done?

I use Mint 14 (a clone of Ubuntu 12.10 Quantal).

4 Answers 4


If you have xdotool installed, you could just simply use

xdotool keyup ISO_Level3_Shift

Which sends a key release (for ISO_Level3_Shift, of course) event to the X server.

But you wanted a program to release all modifier keys. One could use xdotool to achieve that easily, if not for that I have no idea what modifier keysyms are defined. One possible method of finding them is to parse keysymdef.h:

grep '^#define' /usr/include/X11/keysymdef.h | sed -r 's/^#define XK_(\S*?).*$/\1/;' | grep -E '_(L|R|Level.*)$'

Which returns some keysyms that surely are modifiers. Unfortunately, I can't find any precise definition of a modifier key right now, so I don't know whether that's a complete list.

Appending | xargs xdotool keyup to the above pipeline will release all those keys. On my system, it executes the following command:

xdotool keyup Shift_L Shift_R Control_L Control_R Meta_L Meta_R Alt_L Alt_R Super_L Super_R Hyper_L Hyper_R ISO_Level2_Latch ISO_Level3_Shift ISO_Level3_Latch ISO_Level3_Lock ISO_Level5_Shift ISO_Level5_Latch ISO_Level5_Lock
  • 1
    Great! I also found that unassigned keys could be unstuck via the keycode, e.g. xdotool keyup 204. May 7, 2015 at 0:13
  • 1
    @Adam Spiers clued me in. The keyup code for my case was an xmodmap code, e.g. 204, and using keysymdef.h didn't help. To see the xmodmap key codes, try: DISAPLAY=:1 xmodmap -pk | grep -iP 'alt|meta|super|hyper'. You'll need to change the display number to your broken VNC display number.
    – srking
    Nov 18, 2015 at 22:17
  • I think you meant DISPLAY=:1 in the above comment. Nov 19, 2015 at 9:47
  • 1
    xdotool supports a --clearmodifiers option for key/keydown/keyup – maybe it didn't when this answer was written? I expect that xdotool keyup --clearmodifiers space would work. (xdotool keyup requires a key to be specified; “space” is arbitrary.) May 18, 2017 at 17:30

I discovered that for my system, the posted solution involving xdotool often didn't cover the key that was stuck, and running setxkbmap didn't seem to accomplish anything on my system.

The solution that I discovered, which has so far worked without fail, is to use x11vnc. Specifically, I use the following the command:

x11vnc -deny_all -clear_keys -timeout 1

-clear_keys is the key part, here. It instructs x11vnc to clear all pressed keys when it exits. -timeout 1 tells x11vnc to quit after 1 second without connections, and -deny_all makes sure no one can connect during that window.

Sometimes the key that gets stuck prevents any meaningful interaction with the desktop, in which case I'll execute the following through ssh:

env DISPLAY=:0 XAUTHORITY=/home/[username]/.Xauthority x11vnc -deny_all -clear_keys -timeout 1
  • thank you thank you. nothing worked but your solution did. May 27, 2020 at 2:00

I use "setxkbmap" with no arguments. It seems to reset the keyboard. I have a "shortcut" in my panel that I can use with a mouse for when the keyboard is completely inoperable.


The x11vnc answer is ingenious, but if installing x11vnc just for clearing modifiers seems like overkill, here's a Bash solution that uses xmodmap -pm's output to issue a keyup to all known modifiers. The conversion from hex to decimal keycode relies on Bash's arithmetic expansion.

for KEYCODE in $(xmodmap -pm | grep -Pio '(?<=\b0x)[0-9a-f]+\b'); do

    echo -e "xdotool keyup $((16#$KEYCODE))\n" >&2
    xdotool keyup $((16#$KEYCODE))


If you're running it from a keyboard shortcut, adding sleep 1 at the beginning (to allow time for physical keys to be released) would be well-advised. The echo to stderr isn't necessary, of course; I just like to be able to check my ~/.xsession-errors file for output like this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .