How to capture `super` key pressed event in a gtk application on ubuntu?

We are developing an application that requires the program to capture the super key event on Ubuntu. However, there doesn’t seem to be a way to do it. Whenever the super key is pressed, it opens up the activity center on ubuntu and zooms out of the current application. If I run the “xev” in the terminal, the super key is also not captured. Only the zoom-in and zoom-out are recorded. Since I am no expert on keyboard problems on ubuntu, we really need some extra help from the gnome community.

Some extra info:

libgtk-3.0:amd64 version: 3.24.20-0ubuntu1.1
OS version: Ubuntu 20.04

Run xmodmap -pm in the terminal returns:

xmodmap: up to 4 keys per modifier, (keycodes in parentheses):

shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Alt_R (0x6c), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)

And my /etc/default/keyboard is



  • GNOME reserves the use of the Super key for use in system shortcuts. Super should therefore not be used by apps. Additional legacy system shortcuts should also be avoided by apps.

Refer Keyboard - GNOME Human Interface Guidelines documentation

Do you need to capture a key with the code(s) of Super key, or a hardware key, that is located at the position where Super key is typically located?

If the latter is true, and you are allowed to change settings of the computer, where the application runs, you can try to remap this hardware key to something else and then capture that new key code (e.g. Super_L/Left Win → F14):

xmodmap -e "keysym Super_L = F14"

Hi, thanks to anyone who answered my question. We found a way to do it that suits our needs. We have created a keyboard interceptor class that can consistently intercept all modifiers and disable the original system effect of keys like super. The basic idea is to grab the keyboard from the window manager level(x11/wayland) and then create and send a custom key event back to the gtk event queue in another thread. By doing this, You can disable any system-level shortcuts/key(like super key) while running your app, and you can still get those keys as gtk events.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.