# Keyboard Shortcuts

DsPdf is a Document Solutions product that offers a rich library to read, create, modify, and save PDF files without using any external tool.

## Content

The following table lists the keyboard shortcuts supported in DsPdfViewer that will help in performing a variety of supported operations more efficiently and make the DsPdfViewer components more accessible:

| **Shortcut Key** | **Key Code** | **Action** | **Action Description** |
| ------------ | -------- | ------ | ------------------ |
| Ctrl + "Numpad +" | 107 | zoomin | Zoom in. |
| Ctrl + "+" | 187 | zoomin | Zoom in. |
| Ctrl + "Numpad -" | 109 | zoomout | Zoom out. |
| Ctrl + "-" | 189 | zoomout | Zoom out. |
| Ctrl + 0 | 48 | zoom\_pagesize | Zoom to 100%. |
| Ctrl + 9 | 57 | zoom\_clientsize | Zoom to page width. |
| Ctrl + A | 65 | select\_all | Select all text. |
| R | 82 | rotate | Rotate clockwise. |
| Shift + R | 82 | rotate | Rotate counterclockwise. |
| H | 72 | pan | Enable the pan tool. |
| S | 83 | selection | Enable the text selection tool. |
| Spacebar | 32 | holdToPan | Press and hold the Spacebar to temporarily enable the pan. |
| Ctrl + O | 79 | open | Open file from the local system. |
| Ctrl + F | 70 | search | Open the search panel. |
| Ctrl + P | 80 | print | Print document. |
| Left Arrow | 37 | move\_caret\_left | Move the caret (text cursor) left. |
| Up Arrow | 38 | move\_caret\_up | Move the caret up. |
| Down Arrow | 40 | move\_caret\_down | Move the caret down. |
| Right Arrow | 39 | move\_caret\_right | Move the caret right. |
| Home | 36 | move\_caret\_sequence\_start | Move the caret to the start of the sequence. |
| Ctrl + Home | 36 | move\_caret\_document\_start | Move the caret to the start of the document. |
| End | 35 | move\_caret\_sequence\_end | Move the caret to the end of the sequence. |
| Ctrl + End | 35 | move\_caret\_document\_end | Move the caret to the end of the document. |
| Ctrl + Enter | 13 | confirm-ok | Confirm changes. |
| ESC | 27 | confirm-cancel | Cancel changes |
| Page Up | 33 | scrollUp | Scroll up. |
| Page Down | 34 | scrollDown | Scroll down. |

## Customize Keyboard Shortcuts

DsPdfViewer also supports redefining, disabling, overriding, and removing the default keyboard shortcuts, as well as binding the default keyboard shortcuts to other keys and creating custom keyboard shortcuts via API using **shortcuts** option of ViewerOptions class.

### Bind Keyboard Shortcuts

DsPdfViewer supports binding any tool to any keyboard shortcut key. The following are the available built-in tools accessible through keyboard shortcut keys:

| **Keyboard Shortcut Tools** |  |
| :---------------------: | :---: |
| zoomin | move\_caret\_left |
| zoomout | move\_caret\_up |
| zoom\_pagesize | move\_caret\_down |
| zoom\_clientsize | move\_caret\_right |
| select\_all | move\_caret\_sequence\_start |
| rotate | move\_caret\_document\_start |
| pan | move\_caret\_sequence\_end |
| selection | move\_caret\_document\_end |
| holdToPan | confirm-ok |
| open | confirm-cancel |
| search | scrollUp |
| print | scrollDown |

Refer to the following example code to bind the holdToPan action to “P” key:

```javascript
// Bind the "P" shortcut to the holdToPan action and leave the Ctrl+P shortcut for the "print" action.
viewer.options.shortcuts["P"] = [{ ctrl: true, tool: "print" }, { tool: "holdToPan" }];
```

### Disable Keyboard Shortcuts

Refer to the following example code to disable holdToPan keyboard shortcut:

```javascript
/* Initialize DsPdfViewer and
 set the function(event) for both keys to null. */
var viewer = new DsPdfViewer("#viewer", {

    shortcuts: {

        "Z": {
ctrl: true,
            tool: function(event) { }
},
        "Y": {
ctrl: true,
            tool: function(event) { }
}
    }
});

// Disable holdToPan shortcut.
viewer.options.shortcuts["32"] = () => { };
```

### Remove Default Keyboard Shortcuts

Refer to the following example code to remove all default keyboard shortcuts:

```javascript
// Initialize DsPdfViewer and set the shortcuts to null.
var viewer = new DsPdfViewer("#root");
viewer.options.shortcuts = { };
```

### Override Keyboard Shortcuts

Refer to the following example code to override Ctrl + “Numpad +“ keyboard shortcut:

```javascript
/* Initialize DsPdfViewer and
 set the function(event) to zoom the PDF page to 10%. */
var viewer = new DsPdfViewer("#root", { 
  shortcuts: {
    107: {
ctrl: true,
      tool: function(event) {
        DsPdfViewer.findControl("#root").zoomValue += 10;
          event.preventDefault();
    }
}
  }
});
```

### Create Custom Keyboard Shortcuts

Refer to the following example code to create a custom keyboard shortcut:

```javascript
/* Create a custom keyboard shortcut to
 alert the user that Ctrl+Alt+E is pressed. */
viewer.options.shortcuts["E"] = {
ctrl: true,
  alt: true,
  tool: function(e) { alert("Ctrl+Alt+E pressed."); }
};
```