Keyboard Shortcuts in Openbox
2013-04-24
Using keyboard shortcuts is perhaps the easiest way to make yourself more productive with your computer. For any OS or any desktop environment, it is beneficial to know how to quickly accomplish tasks without using your mouse. Many keyboard shortcuts can allow you to get things done much faster than hunting through menus or using window controls with your mouse.
Openbox keyboard shortcuts are very easy to create and use. Shortcuts are defined in a file called rc.xml in openbox. This file can be located at either /etc/xdg/openbox or ~/.config/openbox. The second option is readable and writable by a normal user and overrides the first option, so that's where I keep my openbox keyboard shortcuts.
The keyboard section, where you can define shortcuts, in the default rc.xml looks like this:
<keyboard> <chainQuitKey>C-g</chainQuitKey> <!-- Keybindings for desktop switching --> <keybind key="C-A-Left"> <action name="GoToDesktop"><to>left</to><wrap>no</wrap></action> </keybind> <keybind key="C-A-Right"> <action name="GoToDesktop"><to>right</to><wrap>no</wrap></action> </keybind> <keybind key="C-A-Up"> <action name="GoToDesktop"><to>up</to><wrap>no</wrap></action> </keybind> <keybind key="C-A-Down"> <action name="GoToDesktop"><to>down</to><wrap>no</wrap></action> </keybind> <keybind key="S-A-Left"> <action name="SendToDesktop"><to>left</to><wrap>no</wrap></action> </keybind> <keybind key="S-A-Right"> <action name="SendToDesktop"><to>right</to><wrap>no</wrap></action> </keybind> <keybind key="S-A-Up"> <action name="SendToDesktop"><to>up</to><wrap>no</wrap></action> </keybind> <keybind key="S-A-Down"> <action name="SendToDesktop"><to>down</to><wrap>no</wrap></action> </keybind> <keybind key="W-F1"> <action name="GoToDesktop"><to>1</to></action> </keybind> <keybind key="W-F2"> <action name="GoToDesktop"><to>2</to></action> </keybind> <keybind key="W-F3"> <action name="GoToDesktop"><to>3</to></action> </keybind> <keybind key="W-F4"> <action name="GoToDesktop"><to>4</to></action> </keybind> <keybind key="W-d"> <action name="ToggleShowDesktop"/> </keybind> <!-- Keybindings for windows --> <keybind key="A-F4"> <action name="Close"/> </keybind> <keybind key="A-Escape"> <action name="Lower"/> <action name="FocusToBottom"/> <action name="Unfocus"/> </keybind> <keybind key="A-space"> <action name="ShowMenu"><menu>client-menu</menu></action> </keybind> <!-- Take a screenshot of the current window with gnome-screenshot when Alt+Print are pressed --> <keybind key="A-Print"> <action name="Execute"><command>gnome-screenshot -w</command></action> </keybind> <!-- Keybindings for window switching --> <keybind key="A-Tab"> <action name="NextWindow"> <finalactions> <action name="Focus"/> <action name="Raise"/> <action name="Unshade"/> </finalactions> </action> </keybind> <keybind key="A-S-Tab"> <action name="PreviousWindow"> <finalactions> <action name="Focus"/> <action name="Raise"/> <action name="Unshade"/> </finalactions> </action> </keybind> <keybind key="C-A-Tab"> <action name="NextWindow"> <panels>yes</panels><desktop>yes</desktop> <finalactions> <action name="Focus"/> <action name="Raise"/> <action name="Unshade"/> </finalactions> </action> </keybind> <!-- Keybindings for window switching with the arrow keys --> <keybind key="W-S-Right"> <action name="DirectionalCycleWindows"> <direction>right</direction> </action> </keybind> <keybind key="W-S-Left"> <action name="DirectionalCycleWindows"> <direction>left</direction> </action> </keybind> <keybind key="W-S-Up"> <action name="DirectionalCycleWindows"> <direction>up</direction> </action> </keybind> <keybind key="W-S-Down"> <action name="DirectionalCycleWindows"> <direction>down</direction> </action> </keybind> <!-- Keybindings for running applications --> <keybind key="W-e"> <action name="Execute"> <startupnotify> <enabled>true</enabled> <name>Konqueror</name> </startupnotify> <command>kfmclient openProfile filemanagement</command> </action> </keybind> <!-- Launch gnome-screenshot when Print is pressed --> <keybind key="Print"> <action name="Execute"><command>gnome-screenshot</command></action> </keybind> </keyboard>
It's surrounded by
<keyboard>and
</keyboard>and each keyboard shortcut, or keybinding is surrounded by
<keybind>and
</keybind>
To define a new shortcut, like one for opening your web browser, you could add this:
<!-- Keybinding for your web browser --> <keybind key="W-w"> <action name="Execute"> <startupnotify> <enabled>true</enabled> <name>Chromium</name> </startupnotify> <command>chromium-browser</command> </action> </keybind>
The
<keybind key="W-w">part defines the shortcut. The first key is the modifier key, which can be any of the following:
- W = Windows or meta key
- C = control key
- A = alt key
- S = Shift
The second part is any normal key. So in my example holding the meta key and pressing the "w" key will launch Chromium. You can also combine modifier keys, doing something like
W-S-tThis would issue a command for holding the meta key, the shift, and then pressing "t".
Once you update your rc.xml file, you will need to issue
openbox --restartin a terminal or log out and log back in.