1

Is it possible to define bash scripts for all keys on keyboard so that by pressing any key the bash script for that key will be run?

The scripts may do anything, for instance they may save the key code in an (undo list) file, or any thing else.

In KDE, if a key can be set as a (Qt) hotkey there's a simple solution for it, but for example A cannot be a hotkey and it seems impossible to urge it to run any scripts.

1

Mapping keys to run commands

You can create shortcut key combinations that will launch commands, I've successfully been using XBindKeys on GNOME 3.8.4 for this very purpose.

My use has been modest but I like to create keyboard shortcuts for Nautilus to launch with certain directories opened.

Example

You'll need to first make sure the packages xbindkeys is installed.

Then you'll need to run the following command, one time only, to create a template xbindkeys configuration file.

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

With the file created you can open it in a text editor and add a rule like this:

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

With the above change made we need to kill xbindkeys if it's already running and then restart it.

$ killall xbindkeys
$ xbindkeys

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

References

  • seems nice, for me xbindkeys --defaults > /home/[user_name]/.xbindkeysrc works. But a bad thing is that xnidkeys steals the keyboard message instead of just monitoring it so it seems I have to resend it using xdotool. but xdotool is not working as fast as needed and sometimes does not work. – nano - merge me Mar 28 '14 at 12:48
  • it seems even xdotool cannot bypss xbindkeys. – nano - merge me Mar 28 '14 at 13:38

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.