Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I need a C code to be executed when some particular keys are pressed in Linux "Desktop" environment.

What are the ways to register for such an event and How?

Should I write ISR for that? I need an exact part of Linux from where I can get this call.

Which part of OS handles stuff like these, Is it part Desktop environment like GNOME or part of some service?

share|improve this question
1  
Do you want to catch the keycodes within a C application or run an executable when keycodes are pressed? –  slm Jun 14 '14 at 17:44
    
@slm run an executable when keycodes are pressed –  Vishwanath gowda k Jun 14 '14 at 17:46
1  
Have a look at xbindkeys –  Stéphane Chazelas Jun 14 '14 at 17:47
    
Search this site for Q&A's with xbindkeys in them. You'll find dozens of examples showing you what you want. If you need something additional from those then I'd rephrase this Q to express the additional criteria. unix.stackexchange.com/search?q=user%3A7453+xdotool –  slm Jun 14 '14 at 17:50

2 Answers 2

I would try and make use of xbindkeys to run a command/script when certain keys are pressed.

To start you can insruct xbindkeys to generate a template config file like so:

$ xbindkeys --defaults > /home/saml/.xbindkeysrc

Then open the resulting config file in any editor and add a line like so:

"nautilus --browser /home/saml/projects/path/to/some/dir"
 Mod4+shift + q

Then kill and restart xbindkeys so that it'll reload the modifications in the config file:

$ killall xbindkeys
$ xbindkeys

Now with this running any time I type Mod+Shift+Q Nautilus will open with the corresponding folder opened.

The above can easily be modified so that any script or command could be run instead of the above. This is just an example to illustrate the approach and to get you started.

References

share|improve this answer

Your desktop environment may have a settings utility to configure keybindings.

Gnome 3 Shell

Go to System Settings > Keyboard > Shortcuts and create a Launcher shortcut[1].

KDE

Go to System Settings[2]> Shortcuts and Gestures > Global Shortcuts[3] and assign a custom keybinding, or

Assign a KDE shortcut to your appliation launcher[4]. You may need a .desktop file for your application to use this.

  1. Unlock Widgets.
  2. Right-click in launcher and click Edit Applications...
  3. Find the app you want to assign a shortcut

Other

Otherwise you can use xbindkeys. Arch Wiki has a xbindkeys tutorial worth reading.

[1] https://wiki.ubuntu.com/Keybindings
[2] http://docs.kde.org/stable/en/kde-workspace/systemsettings/using-kapp.html#starting
[3] http://docs.kde.org/stable/en/kde-workspace/systemsettings/general.html
[4] http://askubuntu.com/questions/90567/quickly-launch-any-app-in-kde-with-a-shortcut

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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