# Custom Shortcuts

## Introduction

The Custom Shortcuts &systemsettings; module allows you to configure custom keyboard shortcuts and mouse gestures. You can use them to control applications, run specific commands, and more.

## Managing Shortcuts and Groups

### Adding Groups

The module allows to you to sort related shortcuts into Groups. For instance, if you have some shortcuts that relate to your music player, you could create a group for them called `Music Player`.

To add a new group, click on the Edit button below the left pane and select the New Group option.

### Adding Shortcuts

To add a new shortcut, click on the Edit button below the left pane and select the New option.

The first menu that appears allows you to select the type of trigger. The following options are available:

Global Shortcut

- These are standard keyboard shortcuts that will be recognized anywhere, as long as a &kde; &plasma; Workspace is running.

Window Action

- Window Actions are triggers that occur when something happens to a particular window, like when it appears, gains focus, or is closed.

Mouse Gesture Action

- A mouse gesture action is triggered when a particular movement of the mouse (or touchpad or touchscreen) is performed.

Once you've selected the type of trigger, another submenu appears that allows you to select an action type. The following types are available:

Command/&URL;

- This action will launch a command or open a &URL; when the shortcut is triggered.

&DBus; Command

- This action will call a &DBus; method in a running application or system daemon. For more information on &DBus;, see the &DBus; Introduction on &kde; TechBase.

Send Keyboard Input

- This action will send keyboard input to the currently running application, just as if you had typed it in yourself.

Once you've selected the action type, you can then edit the shortcut to your liking. See shortcuts for more information.

### Deleting Shortcuts and Groups

To delete a shortcut or group, select it, then click on the Edit button below the left pane, and select the Delete option.

### Exporting Groups

You can export a group, so you can save the shortcuts contained within and use them on another computer or maintain a backup.

To export a group, select the group to be exported, then click on the Edit button below the left pane and select the Export Group... option, which opens a new window that lets you define some options about the exported group. The following options are available:

Export Actions

- This allows you to select the state the shortcuts will be in when they are imported later. Select Actual State to maintain their current state, Enabled to ensure they are all enabled, or Disabled to ensure they are all disabled.

Id

- Here you may enter text to identify the group. If the group is included by default, this text may be filled in by default.

Allow Merging

- This defines what happens if the group already exists on the system the exported group is imported to. When enabled, any new actions will be added to the group on the target system, while actions that have the same name but a different configuration will updated with the configuration from the imported file. When disabled, the module will refuse to import the file.

Filename

- Here you may enter the filename you wish to export the shortcut to. You may also select the button to the right of the text box to open the File dialog and select a file from there.

  Exported files use the extension `.khotkeys` by default.

Exporting a Group The Export Group dialog.

Exporting a group of shortcuts.

### Importing Groups

To import a group, click the Edit button below the left pane and select Import.... A file selection dialog opens that permits you to locate a file previously created using the Export function.

## Modifying Groups

In the left section of the window, the default shortcuts are categorized into groups. These groups can be expanded by clicking the arrow beside them to reveal the shortcuts.

When you click on a group, you are presented with two tabs to configure the group itself. The Comment allows you to store notes about the group, and are not actually used by the system for anything. The Conditions tab allows you to restrict which windows a group of shortcuts works with.

The Comment Tab The Comment tab in a group.

Modifying a group's comment.

Conditions are displayed in a tree, the top level of which is And. All conditions beneath And must be satisfied for shortcuts in the group to be triggered.

You may add additional groups of conditions by clicking the New drop down box to the right of the tree of conditions. Types of groups include the aforementioned And, Or, in which only one member of the group must be satisfied, or Not, in which the inverse of all members will trigger the shortcuts in the group.

To add a window definition to the list, press the New button. You may select Active Window... if you want the shortcut to be triggered only if the specified window currently has focus, or you may select Existing Window... if you want the shortcut to be triggered as long as that window is open , regardless of whether or not you are using it. Selecting either of these options opens a window where you can edit the window definitions.

Click the Edit... button to edit an existing set of window definitions. A window opens with the window definition editor. For more information, see windows.

To remove a window definition from the conditions list, click the Delete button.

## Modifying Shortcuts

In the left section of the window, the default shortcuts are categorized into groups. These groups can be expanded by clicking the arrow beside them to reveal the shortcuts.

By default the groups KMenuEdit, Konqueror Gestures and Examples are installed. Applications can provide additional shortcuts, ⪚ &spectacle; adds a group Screenshots. This group, when expanded, reveals several shortcut configurations like Start Screenshot Tool which, when selected, reveals section on the right side, with three tabs:

### The Comment Tab

The Comment tab allows you to describe how to use the shortcut, what it does, or anything else you might want to include.

### The Trigger Tab

The Trigger tab contains the trigger configuration, which depends on the type of trigger specified:

Global Shortcut

- To modify a keyboard shortcut, click on the button that contains a wrench, and then enter the desired keyboard shortcut. To erase the shortcut, click on the button with the icon to the right of the change shortcut button.

  Modifying a Keyboard Trigger The Trigger tab for a keyboard shortcut.

  Modifying a trigger for a keyboard shortcut.

Window Action

- Window actions contain several options:

  Trigger When

- This configures the particular window action that must occur for the shortcut to be triggered. The following options are available:

  - Window appears - Triggered when a window is opened.

  - Window disappears - Triggered when a window is closed.

  - Window gets focus - Triggered when you switch to a window.

  - Window loses focus - Triggered when you switch away from a window.

Window

- This is where you define the actual window or windows the trigger applies to. For more information, see windows

Mouse Gesture

- A mouse gesture can be changed by clicking the Edit button below the area that displays the mouse gesture, which will open a window. Hold down the &LMB; and draw the desired mouse gesture in the area provided. The gesture will be saved when you release the &LMB;.

  Modifying a Mouse Gesture Trigger The Trigger tab for a mouse gesture shortcut.

  Modifying a trigger for a mouse gesture.

### The Action Tab

The Action tab is where you configure the action that will be performed when the shortcut is triggered. There are several types of actions that have different configuration options:

Command/&URL;

- When using a Command or &URL; is a trigger, a text box is provided where you may enter the command to run or &URL; to open when the shortcut is triggered. You may also click the Browse button to the right of the text box to open a file selection dialog in which you can select a file on your local or a remote system.

  Modifying a Command Action The Action tab for a command.

  Modifying a command action.

&DBus; Command

- Modifying a &DBus; Action The Action tab for a &DBus; command.

  Modifying a &DBus; action.

  The following options are provided that allow you to specify a &DBus; method to be performed:

  Remote application

- The service name of the remote application the method is to be performed on, for instance `org.kde.spectacle` if you wanted to perform it on the &spectacle; screenshots utility.

Remote object

- The path to the remote object the method is to be performed on, for instance `/` for screenshot actions using &spectacle; or `/Document/1`, if you wanted to perform it on the first document opened in &kate;.

Function

- The name of the &DBus; method to be called, for instance `Fullscreen` if you wanted to take a fullscreen screenshot or `print` if you wanted to print the document.

Arguments

- Enter additional arguments for the &DBus; method to be called.

Call

- Use this button to verify that the action works as expected.

Launch D-Bus Browser

- Launch the application QDBusViewer so browse the &DBus; methods and arguments for a running application.

For more information on &DBus;, see the &DBus; Introduction on &kde; TechBase.

Send Keyboard Input

- At the top of the Action tab, there is a large text entry where you may enter the keystrokes you wish to be sent when the shortcut is triggered.

  Most keys contain a single character, and to enter them here you just enter that character. For instance, to type an A, just enter `A`. Some keys have longer names, and you can also use those names. For instance, to press the &Alt; key, simply enter `Alt`.

  Individual keystrokes should be separated by a colon (`:`). For instance, to type foo, enter `F:O:O`.

  Keys that need to pressed at the same time should be separated by a plus sign. For instance, to press &Ctrl;C, enter `Ctrl+C`.

  Remember, you must enter keystrokes here exactly as you would on a keyboard. To capitalize letters, you must enter the &Shift; key. For instance, to type Hello, enter `Shift+H:E:L:L:O`.

  This also applies to special characters. For instance, to type the at-sign on the U.S. English keyboard layout, enter `Shift+2`.

  The action that is performed is dependent on the currently selected keyboard layout. If you change keyboard layouts and trigger a shortcut, it may have undesired consequences.

  Beneath the keystroke entry text box, you may select which window the keystrokes will be directed to. You may choose from the following options:

  - Active window - The window that is currently open.

  - Specific window - The window that you describe using the form below. For more information on describing windows, see windows.

  - Action window - When using the Window Actions trigger type, enter the keystrokes in the window that triggered the shortcut.

  Modifying a Keyboard Input Action The Action tab for keyboard input.

  Modifying the keyboard input action for a shortcut.

## Defining Windows

Several areas of the module allow you to define a list of windows. They all use the same interface, which contains the following options:

Comment

- This is merely an informational text box you can use to explain what the trigger applies to or save other useful information. It is not actually used by the system for anything.

Window List

- Beneath the Comment box on the left is the list of all window definitions currently present in the trigger. Simply click on one to perform an operation on it.

Edit...

- Press this button to modify the currently selected window definition. A new window is opened that allows you to edit it. This window contains the following options:

  Window Data

- This is where you describe the window the trigger should apply to.

  At the top, there is a Comment field, which is informational just like the one in the main Trigger tab.

  Three window characteristics are available:

  - Window title - The title that appears at the top of the window.

  - Window class - Usually the name of the application.

  - Window role - Usually the name of the &Qt; class that makes up the window.

  Each window characteristic provides a drop-down box, and a text box below it. Enter the value you wish to test windows for in the text box. From the drop-down box, select which kind of test you wish to apply. You can use Is to require an exact match, Contains to require that the text entered be somewhere inside the full value, or Matches Regular Expression to use a regular expression to define the match. You may also perform the inverse of all these operations. Select Is Not Important if you do not wish for that particular characteristic to be examined.

  The easiest way to fill in this information is to open the desired window, then click the Autodetect button at the bottom of this section, and finally click on the desired trigger window. All three window characteristics will be populated with the information from that window, and you can then adjust the settings as necessary.

Window Types

- This lets you restrict the match to a particular type of window. The following options are available:

  - Normal - A regular application window.

  - Desktop - The main desktop is actually a special window all its own.

  - Dialog - A small window that is part of a normal application, such as a message box or a configuration screen.

  - Dock - A small window that can be attached or detached from a main application window.

New...

- Create a new window definition. This opens the edit dialog described above.

Duplicate...

- This creates a new window definition with the exact same specifications as the currently selected window definition. It will open the edit dialog described above so you may make further changes.

Delete

- Removes the currently selected window definition.

## Settings

When you first enter the module, or when you click the Settings button below the left pane, there will be several configuration options in the right pane:

Start the Input Actions daemon on login

- This configures whether or not to activate the background application that monitors for keyboard shortcuts and triggers configured actions. It is enabled by default.

Gestures

- Select this check box to enable mouse gestures.

  There are two options specific to mouse gestures:

  Timeout

- This specifies the maximum time interval during which the mouse gesture will be monitored and recognized by the system, in milliseconds.

Mouse Button

- This specifies the mouse button to be used for mouse gestures. Usually, `1` is the &LMB;, `2` is the &RMB;, and `3` is the middle or wheel button. If your mouse has more buttons, you can also use those instead.

  Button 1 is unavailable, so mouse gestures do not interfere with the normal operation of your system.

Settings The Settings screen.

Editing Custom Shortcuts settings.

## Credits and License

Special thanks to Google Code-In 2011 participant Subhashish Pradhan for writing much of this article.

&underFDL; &underGPL;