start page | rating of books | rating of authors | reviews | copyrights

Book HomeLinux in a NutshellSearch this book

17.13. Adding Keyboard Shortcuts

The bare-bones system.fvwmrc file that we started with offers little in the way of keyboard shortcuts, or accelerators, for window management functions. But if you're one of those users who prefers to keep her hands on the keyboard and off the mouse as much as possible, within your .fvwm2rc file you can easily define keys to perform a variety of functions.

17.13.1. Keyboard Shortcuts to Navigate the Desktop

The Pager is a great tool for getting around one or more desktops. But many people hate using the mouse. You can configure a bunch of keys to let you move around in various ways.

Add the following lines to your .fvwm2rc file to set up key combinations to scroll one page in any direction on the desktop using Ctrl plus an arrow key. The view scrolls in the direction of the arrow.

Each definition uses the Key variable followed by:

  1. The name of the key

  2. The context (location) in which it must be typed

  3. Any modifying keys (that must also be held down)

  4. The action initiated by the key or key combination

Thus, in the following example, the first definition line says that pressing the left arrow key in any "A" context, while also holding down the Ctrl "C" key will scroll the screen one page to the left on the current desktop:

# Press arrow + Control in any context
# to scroll by one page in the direction of the arrow
Key Left            A	    C	    Scroll -100 0
Key Right           A	    C	    Scroll +100 +0
Key Up              A	    C	    Scroll +0   -100
Key Down            A	    C	    Scroll +0   +100

Table 17-1 summarizes the functionality.

Table 17-1. Key Combinations to Change the Page

Key Combination

Moves View

Control, right arrow key

One page to the right

Control, left arrow key

One page to the left

Control, up arrow key

One page up

Control, down arrow key

One page down

The Scroll variable takes the same parameters as EdgeScroll, which are explained in Section 17.12, "If It's Too Hard (or Easy) to Move the Pointer Between Pages", earlier in this chapter. See the fvwm2 manpage for more information. Note that the key combinations we've defined let you get around a single desktop but won't let you advance to another desktop. We'll deal with that contingency later.

Here's another possible key binding. This one advances the view to every page in the desktop in order and finally wraps back to the first page. You use the Tab key while holding down Control, again in any context. The definition line looks like this:

# Press Tab + Control in any context to scroll 
# by one page with wrap scrolling
Key Tab         A       C       Scroll 100000 0

Table 17-2 summarizes another page-changing combination.

Table 17-2. Another Key Combination to Change the Page

Key Combination

Moves View

Control, Tab

To the next page in the desktop

Since application windows can straddle pages, there may be times when you want the screen to display a screenful other than a page proper. (You might also want to look at windows on two different pages at once.) The following shortcuts scroll the view one-tenth of a page at a time. Instead of Control, these shortcuts use the so-called Meta key. This is a symbolic name -- the actual key that serves the Meta function varies from keyboard to keyboard. In many cases, the key labeled Alt serves as the Meta key. Here are the configuration file definition lines:

## Press arrow + meta key in any context
## to scroll by 1/10 of a page in the direction of arrow
Key Left            A	    M	    Scroll -10 +0
Key Right           A	    M	    Scroll +10 +0
Key Up              A	    M	    Scroll +0   -10
Key Down            A	    M	    Scroll +0   +10

These lines establish the following functionality, outlined in Table 17-3.

Table 17-3. Key Combinations to Scroll the Page by 1/10

Key Combination

Moves View

Meta, left arrow key

One-tenth page to the left

Meta, right arrow key

One-tenth page to the left

Meta, up arrow key

One-tenth page up

Meta, down arrow key

One-tenth page down

If you have more than one desktop, you can also create shortcuts to move between those. The following two shortcuts are intended to let you go back and forth between desktops in a two-desktop environment:

## Press Control + Return in any context 
## to scroll forward by 1 desktop
Key Return         A       C       Desk 1 1 1
## Press Shift + Control + Return in any context 
## to scroll back by 1 desktop
Key Return         A       SC      Desk -1 0 0

Table 17-4 summarizes these shortcuts.

Table 17-4. Key Combinations to Scroll to the Next Desktop

Key Combination

Moves View

Control + Return

One desktop ahead

Shift + Control + Return

One desktop back

The second and third parameters to the Desk variable constrain the paging so that you can't page beyond the first or second desktops. (Hypothetically, you can page outside the view of the Pager!) If you have more than two desktops, you will need to edit these definitions. See the fvwm2 manpage for more about the Desk variable.

17.13.2. Moving the Pointer with Keystrokes

The previous section outlines some keyboard shortcuts you can define to scroll the page view. But you can also define shortcuts to move the position of the pointer on the screen. Admittedly this is for people who are downright mouse haters. But if you're someone who prefers to use the keyboard to the mouse, these shortcuts can come in handy. They employ the CursorMove variable, also described on the fvwm2 manpage.

The keyboard accelerators in the first group move the cursor symbol one-tenth of a screen at a time. The first definition line says that pressing the left arrow key in any "A" context, while also holding down the Shift "S" and Meta "M" keys will move the cursor one-tenth of a page in the direction of the arrow:

## Press Shift + Meta + arrow in any context
## to move the pointer by 1/10 of a page in direction of arrow
Key Left            A	    SM	    CursorMove -10  +0
Key Right           A	    SM	    CursorMove +10  +0
Key Up              A	    SM	    CursorMove +0   -10
Key Down            A	    SM	    CursorMove +0   +10

Table 17-5 summarizes the commands.

Table 17-5. Key Combinations to Move the Pointer by 1/10 of the Page

Key Combination

Moves Pointer

Meta, Shift, left arrow key

One-tenth of a page to the left

Meta, Shift, right arrow key

One-tenth of a page to the right

Meta, Shift, up arrow key

One-tenth of a page up

Meta, Shift, down arrow key

One-tenth of a page down

If you want to have just about as much control moving the pointer with keystrokes as you do moving it by hand, you can specify shortcuts to move it a mere one percent of a page at a time:

## Press Shift + Control + arrow in any context 
## to move the pointer by 1% of a page in direction of arrow
Key Left            A	    SC	    CursorMove -1 0
Key Right           A	    SC	    CursorMove +1 +0
Key Up              A	    SC	    CursorMove +0   -1
Key Down            A	    SC	    CursorMove +0   +1

Table 17-6 summarizes the commands.

Table 17-6. Key Combinations to Move the Pointer by 1 Percent of the Page

Key Combination

Moves Pointer

Shift, Control, left arrow key One percent of a page to the left
Shift, Control, right arrow key One percent of a page to the right
Shift, Control, up arrow key One percent of a page up
Shift, Control, down arrow key One percent of a page down

17.13.3. Keyboard Shortcuts for Menu and Window Manipulation

So far we've limited our keyboard shortcuts to scrolling the view and moving the pointer. But you can create keyboard bindings for any window manager function.

Here are some sample bindings to perform simple window operations and to display a few menus:

# Keyboard accelerators
Key F1          A       M       Iconify
Key F2          A       M       Move
Key F3          A       M       Resize
Key F4          A       M       Popup "RootMenu"
Key F5          A       M       Popup "Misc-Ops"
Key F6          A       M       Popup "Utilities"
Key F7          A       M       Popup "Module-Popup"
Key F10         A       M       Restart fvwm2
Key F12         A       SM      Close

These are just sample bindings; you may want to set up your own keyboard shortcuts to do entirely different things. But these bindings will let us look at some of the possibilities, as well as potential problems.

In our sample definition lines, the first binding specifies that if you press the F1 function key while holding down the Meta "M" key, with the pointer in any "A" context, the focus window will be iconified (or deiconified). Meta+F2 lets you initiate moving the focus window, while Meta+F3 starts a resize operation. (The Meta key is described in the section "Keyboard Shortcuts to Navigate the Desktop," earlier in this chapter.)

Note that if you've adopted the keyboard bindings to move the pointer (as described in the previous section), you can perform the move and resize operations entirely with keystrokes. For example, use Meta+F2 to begin a move, then drag the window outline by moving the pointer symbol using the appropriate keyboard shortcuts, then press the Return key to complete the operation.

In addition, we've set up function keys to pop-up four different menus, the contents of which are also defined in the .fvwm2rc file. Once a menu is popped up, you can use the up and down arrow keys to highlight items on the menu, right and left keys to move down and up through submenus (cascading menus), the Return key to select an item, and Esc to pop down the menu without making a selection.

Because we do a lot of tinkering with fvwm2 customization, we have set up Meta+F10 to restart the window manager. This is much faster than bringing up menus.

We've also created a key combination to close the focus window: Shift+Meta+F12. Certainly it's handy to be able to get rid of a window with a keyboard shortcut, but you don't want it to be too easy or you may do it by mistake. Having an extra modifying key (Shift) and using the very last function key (F12) require you to act deliberately in closing a window using this method.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.