FreeBSD Desktop – Part 9 – Key Components – Keyboard/Mouse Shortcuts

In the Part 9 of the FreeBSD Desktop series I would like to describe key components of self made custom desktop environment such as:

  • Window Manager
  • Status Bar
  • Task Bar
  • Wallpaper Handling
  • Application Launcher
  • Keyboard/Mouse Shortcuts
  • Locking Solution
  • Blue Light Spectrum Suppress

Today we will focus on the sixth part – the Keyboard/Mouse Shortcuts. In the next series each of these components configuration would also be described along with eventual needed scripts.

You may also check earlier/other articles of the FreeBSD Desktop series:

Keyboard/Mouse Shortcuts

While most window managers and desktop environments offer some kind of shortcuts or tools to define your own ones its often quite complicated to force them to do exactly what you want. For example – while Openbox supports creating keyboard and mouse shortcuts it always require modifier key like [ALT], [CTRL] or [SUPER] for example. It will also not allow you to create mouse shortcuts like using only the left button of the mouse wheel (not to confuse with regular left mouse button). Or to add some function or script to keys like [Scroll Lock] or [Pause Break] without any other modifiers.

Fortunately there are tools that can and work well together to achieve almost anything you can imagine. While earlier in the series I made knockouts of solutions – or choosing the best one from several potential candidates in this part its different. I use ALL of these tools and there will be no knockout, they all provide some ‘missing bits’ to the Openbox or probably most of other window managers.

These tools are:

  • xev
  • xmodmap
  • xbindkeys
  • xdotool

Β 

Xev

The xev is used to ‘read’ what has keyboard key has been pressed or which mouse button was used. While it may sound stupid for most of the keys it does not for ‘special’ ones like Volume Up and Volume Down ‘dedicated’ buttons on many laptops or [Page Up] and [Page Down] keys which are named Prior and Next respectively.

keyboard-xev.jpg

Xmodmap

This tool is used to assign or rename keys to make something different, for example Lenovo ThinkPad laptops have two special keys – lets call them Forward and Backward – near the Arrows keys. They work a lot better as [Page Up] and [Page Down] keys so with xmodmap its possible to map them that way.

Other popular use case are laptop Volume Up and Volume Down buttons, or Volume Mute button. While checked with xev they often has only some keycode attached while you may map them into XF86AudioLowerVolume, XF86AudioRaiseVolume and XF86AudioMute respectively so that X11 will take care of the rest, they will ‘start work’ in most applications thanks to that mapping. Additional scripting is not needed here.

Example modifier map shown by xmodmap tool.

% xmodmap -pm  
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 (0x6d)
mod1        Alt_L (0x40),  Meta_L (0x9c)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x73),  Super_R (0x74),  Super_L (0x7f),  Hyper_L (0x80)
mod5        Mode_switch (0x8),  ISO_Level3_Shift (0x7c)

The xmodmap will load and map our keys and then will exit, files like ~/.xinitrc or ~/.xsession are good places for such startup keyboard setup.

Xbindkeys

While most window managers – including Openbox – support configuring keyboard shortcuts it is not perfect and has some limitations, like requiring modifier key like [ALT], [CTRL] or [SUPER] to be used in every shortcut for example.

This is where xbindkeys steps in. While xev will do for most cases it will fail you in more advanced scenarios. For example when You would like to attach Volume Up and Volume Down actions to your mouse Left Wheel Button and Right Wheel Button keys. I will probably not be able to express how useful mapping it is. Even when you laptop screen is locked you will be able to turn the volume down or up.

Similarly like xev the xbindkeys comes with its own window to catch events.

keyboard-xbindkeys.jpg

Here are these bindings.

% xbindkeys -s 
"mixer pcm 100; mixer vol +5"
    m:0x0 + b:9   (mouse)
"mixer pcm 100; mixer vol -5"
    m:0x0 + b:8   (mouse)
(...)

The xbindkeys will run as a daemon in the background, files like ~/.xinitrc or ~/.xsession are usual places to start it when our X11 environment starts.

The xbindkeys tool also comes with its own ‘key identifier’ as xev does. Use it with -k/--key argument to identify one key pressed or -mk/--multikey argument to identify multi key pressed respectively.

% xbindkeys -k
Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"(Scheme function)"
    m:0x0 + c:99
    Prior
% 

Xdotool

Sometimes you want to ‘fake’ that some keys were pressed – but without pressing them – without touching the keyboard. While some applications offer some settings to be changed by an argument to their main binary name – like for example DeaDBeeF media player allows you to type deadbeef --next to skip to next song – many applications don’t provide such ‘API’. This is where xdotool comes handy – it can generate any keyboard shortcut and send it to and application in X11 environment. Great tool for scripting and automating ‘work’ on the desktop and also for situations where nothing else works.

An example of such ‘useful’ shortcut may be emulating of [Z] (the [Shift]+[z] combination) key press on mupdf PDF viewer to “Zoom page to fit either to width or height of window.” after opening new PDF document.

Summary

Each of these tools plays some role in keyboard and mouse shortcuts on the X11 desktop. Together they are able to execute any solution you can imagine.

EOF
Advertisements

16 thoughts on “FreeBSD Desktop – Part 9 – Key Components – Keyboard/Mouse Shortcuts

  1. Pingback: FreeBSD Desktop – Part 10 – Key Components – Locking Solution | vermaden

  2. Pingback: FreeBSD Desktop – Part 11 – Key Components – Blue Light Spectrum Suppress | vermaden

  3. Pingback: FreeBSD Desktop – Part 12 – Configuration – Openbox | vermaden

  4. Pingback: FreeBSD desktop (9) | 0ddn1x: tricks with *nix

  5. Pingback: FreeBSD Desktop – Part 13 – Configuration – Dzen2 | vermaden

  6. Pingback: FreeBSD Desktop – Part 14 – Configuration – Tint2 | vermaden

  7. Pingback: FreeBSD Desktop – Part 7 – Key Components – Wallpaper Handling | vermaden

  8. Pingback: FreeBSD Desktop – Part 8 – Key Components – Application Launcher | vermaden

  9. Pingback: FreeBSD Desktop – Part 6 – Key Components – Task Bar | vermaden

  10. Pingback: FreeBSD Desktop – Part 4 – Key Components – Window Manager | vermaden

  11. Pingback: FreeBSD Desktop – Part 15 – Configuration – Fonts & Frameworks | vermaden

  12. Pingback: FreeBSD Desktop – Part 1 – Simplified Boot | vermaden

  13. Pingback: FreeBSD Desktop – Part 2 – Install | vermaden

  14. Pingback: FreeBSD Desktop – Part 3 – X11 Window System | vermaden

  15. Pingback: FreeBSD Desktop – Part 5 – Key Components – Status Bar | vermaden

  16. Pingback: FreeBSD Desktop – Part 16 – Configuration – Pause Any Application | vermaden

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s