Mouse gestures and keyboard shortcuts with KHotKeys

A Game of Signs

Kalle Gerwien

Mouse gestures and keyboard shortcuts add speed and simplicity to PC operations. Mouse gestures used to be the domain of Opera and Mozilla users, but KHotKeys now brings them to Konqueror for users of KDE 3.2 or newer. You can even launch non-KDE programs with KHotKeys. <@65_VA>By Kalle Gerwien

KDE is an extremely flexible system. The context menus that drop down when users press the right mouse button are just as extensible as the K menu or the quick start icons. And hiding in the depths of the KDE control center is another interesting program that allows more flexible use of KDE: KHotKeys. With KHotKeys, the user can assign keyboard combina- tions to applications. You can even use mouse gestures to control Konqueror (see Box 1).

The Author

Kalle Gerwien has been using PCs since the mid-80s and started using Linux in 1997. In 2001, Kalle founded the Linux User Group in his home town, Alfeld, Germany. In his free time, Kalle enjoys reading Science Fiction and even dabbles in writing his own SF stories.

To launch KHotKeys, press [Alt-F2] and enter khotkeys, or open the Control Center and open the Regional & Accessibility section. When you launch KHotKeys, a warning message appears to inform you that changes can be dangerous. This article gives you an intro- duction to some simple but effective settings within the KHotKeys application. It always helps to be careful, but you will have few worries about these changes, even if you are a newcomer to KHotkeys. Once you become accustomed to KHotkeys, you will have your own ideas for hot keys and gestures that will increase the efficiency of your desktop.

Mouse Gestures

The program window is divided into two panels. The left panel has a few examples and a sample of Konqueror mouse gestures. The right panel contains the settings for individual actions, which are distributed over a number of tabs. By default, KDE enables KHotKeys shortcuts, and Konqueror understands mouse gestures.

Box 1: Mouse Gestures

Opera Software introduced mouse gestures for the Opera Internet browser. Opera was looking for a solution that would allow users to perform the most common browser actions, such as Back, Forwards, or Reload, without clicking through the menus with the mouse. The result was the introduction of mouse gestures, which have now been adopted by the developers of Mozilla and Konqueror. Because Konqueror is also a file manager, mouse gestures can also be applied to navigating local directories.

Mouse gestures are amazingly simple and become very natural after a short learning curve. You press the center mouse button, draw the gesture with the mouse, and release the mouse button. For example, for Browser back, you draw a line from right to left (see Figure 2). The gesture is interpreted by Konqueror and results in the desired action.

Figure 1: KHotKeys won't interpret mouse gestures if Disable KhotKeys daemon is checked.

If the mouse gestures do not work with your distribution, check the KDE Control Center welcome screen to see if you really have KDE version 3.2 or newer. Then open Global shortcuts in the right-hand panel of Hhotkeys and remove the checkmark in Disable KHotKeys daemon (Figure 1) if necessary. Confirm by clicking on Apply and then change to the Gestures Settings tab. Remove the checkmark for Disable mouse gestures globally, and confirm this setting by clicking on Apply.

Gestures can be individually enabled or disabled. Clicking on the plus sign to the left of Konqueror Gestures in the left-hand panel reveals a list of common gestures you can enable or disable as required. To disable a gesture, click on a gesture in the list and then check the Disable box in the right-hand panel.

The right-hand panel has comments for existing gestures. A comment describes the movement associated with the gesture. However, you can edit the comments if you are unhappy with them. Save your changes by clicking on Apply, and move on to trying out mouse gestures in Konqueror.

Creating Your Own Gestures

KHotKeys allows you to replace existing gestures or add your own gestures. KHotKeys has three possible gestures for every action. Select the required gesture in the Actions panel, and then click on the Gestures tab in the right-hand panel. The panel shows you three fields for three possible gestures, although typically only the first field is filled out.

Figure 2: Common mouse gestures.

If you click on the Edit button for the first free field, KHotKeys opens a new window. You can then draw your new gesture. Make sure you hold down the left mouse button when drawing the gesture, as the center button is reserved for executing gestures. To ensure that your gesture is unique, you are required to draw it twice. If the two attempts are too dissimilar, the program refuses to accept the gesture and asks you to repeat the procedure. After drawing all three gestures to KHotKey's satisfaction, you can click OK to store the gestures. The gesture will then appear in the second window with a unique gesture ID.

New Functions

If you need to program a Konqueror function but cannot find an example to base it on, select Konqueror Gestures and then click on New Action. This creates a new entry with that name. In the right-hand panel, type a descriptive name for the action in Action name. Select the action type; in our example this is Gesture -> Keyboard input (simple). This tells KHotKeys to convert the gesture you have drawn into a keyboard shortcut. For example, you could specify that your gesture is interpreted as [Ctrl]+[U] to display the source code of an HTML document. It makes sense to say what the gesture looks like as part of the comment.

Now change to the Gestures tab, click Edit, and draw the new gesture. After completing this procedure, click on the Keyboard input settings tab. In the Keyboard input box, specify the keys you want to emulate. Check Konqueror for the keyboard shortcuts. The View Document Source item is located in the Konqueror View menu. You need to type the keyboard shortcut shown for this item in the Keyboard input box. In this case the correct entry is Ctrl+U.

Finish programming the new gesture by clicking Apply. The gesture is now enabled and can be used in Konqueror. You can follow the same procedure to add mouse gestures for all the functions you need. Avoid over-extravagant gestures; the more difficult a gesture is to draw, the longer you need to run a function.

Using Keyboard Shortcuts to Launch Programs

As the name suggests, KHotKeys not only supports mouse gesture programming, but it can also use keyboard shortcuts to launch programs or type text strings in an editor. It makes sense to set up a separate action group for this. To do so, select General Settings and then click on New Group. Type a name for the group in the General tab. Now select the newly created group and click on New Action. We want the new action to use a hot key to launch the Kmail program.

Launch Kmail is a good descriptive name. If you use a different mail program, you will want to choose a name to match. As the action type, select Keyboard shortcut -> Command/URL simple. Now click on the Keyboard shortcut tab; you should see a button labeled None. Click the button with your mouse and enter a keyboard shortcut of your own choice, for example [Ctrl]+[K]. If your choice of a hot key is already in use, KHotKeys will warn you. If not, the program simply accepts your entry and displays the entry in a list. Now move to the Command/URL Settings tab, and type the program you want KHotKeys to launch. For Kmail, this is kmail. To launch Kmail, you could have selected K-Menu Entry (simple) instead. This type accesses entries in the K-Menu.

Figure 3: Draw the mouse gesture three times in this box.

Table 1: Control Keys
FunctionCommand
Cursor upup
Cursor downdown
Cursor leftleft
Cursor rightright
Space space
Shiftshift
AltAlt
Enterreturn
ColonShift+;

With Kind Regards

Keyboard Shortcut -> Keyboard Input (simple) is an interesting action type. It allows you to simulate key presses. Let's take the sentence, With kind regards, Joe Public as an example; this is a typical complimentary closing for a letter in a word processor, mail program, news reader, or text editor. KHotKeys gives you the ability to to enter this sentence automatically, no matter what application you are using.

Figure 4: Separate each key press with a colon.

First create a new entry in the keyboard shortcut group by clicking on New Action. You can call the entry wkr. Select Keyboard Shortcut -> Keyboard Input (simple) as the action type; type Writes "With kind regards" plus name as the comment. Now switch to the Keyboard shortcut tab and choose a hot key, for example [Ctrl]+[Y]. Then move to Keyboard input settings and type all the keys that you would need to press, if you were to write the complimentary close. Make sure you separate the individual key presses with colons (:). The sentence we want to enter, With kind regards, Joe Public would look like this in the entry box:

Shift+W:i:t:h:space:k:i:n:dU
:space:r:e:g:a:r:d:s:,:spaceU
:return:Shift+J:o:e:U
space:Shift+P:u:b:l:i:c:

You need to add the Shift+ keyword for capital letters; Table 1 has more information on control keys.

Menu Control

In this example, you have learned how to simulate key presses and use them to write a simple block of text. It is just as easy to simulate menu access in programs. Some program features are hidden away in submenus, and this can be annoying if you need them often. For example, to access the Konqueror View / View mode / Multicolumn view entry, you would press [Alt+A] / [Cursor right] / [Cursor down] / [Cursor down] / [Enter]. You can let KHotKeys simulate these keys to access a multicolumn view via a mouse gesture or a more simple keyboard shortcut.

To do this, first create another Keyboard shortcut -> Keyboard input (simple) entry, and assign a keyboard shortcut and a descriptive name to the entry. As the keyboard input, type alt+a:right:down:down:return. This allows you to navigate menus, even if the functions are not accessible via a simple key press.

Figure 5: Window details.

More Action Types

The General action type allows you to combine gestures and keyboard shortcuts at will. For example, you could use a mouse gesture to launch a program, or an existing hot key to point to a hot key you defined yourself. To do so, first create a new entry, and then click on New in the Trigger tab to specify the kind of trigger you want: a shortcut, a gesture, or a window. Then specify what you want to have happen in the Actions tab. You can choose between Command/URL, K-Menu Entry, DCOP Call, Keyboard input, and Activate Window. The Conditions tab allows you to specify when this action should take place.

Restricting Functions

If you have added many of your own functions, you might notice some undesirable side effects. For example, another program might use your hot key for a completely different menu. In this case, you need to enable the option Send to specific window in the Keyboard input settings tab. Add a descriptive comment, and then select New | Simple Window. In the dialog that follows, you need to specify the program window. Typically, this just means adding the program name as the window title (Konqueror in our example).