# Setting up Hotkeys

Canonical page: https://www.adaptabletools.com/docs/dev-guide-tutorial-hotkeys

- This page shows how to use Hotkeys in AdapTable

You can define actions to run in response to a given set of keystrokes.

This can be accomplished in 2 ways:

- through a third party library (like Mousetrap)
- by listening to the native `keydown` event

**Example: Hot Keys**

Using Hot Keys in AdapTable

- In this demo we have set 4 Hot Keys — 2 using Mousetrap (a 3rd party library which is not shipped with AdapTable) and 2 using the native `keydown` event
- Each key combination calls a different method on the Adaptable API:
  - `alt+shift+s` — opens the Format Column Settings Panel (Mousetrap)
  - `alt+shift+c` — opens the Calculated Column Settings Panel (Mousetrap)
  - `meta+shift+l` — opens the Layout Settings Panel (`keydown`)
  - `meta+shift+s` — opens floating Quick Search (`keydown`)
### Expand to see the key bindings

```
// Define 2 Hotkeys using mousetrap - a 3rd party library (which is not shipped with AdapTable)
Mousetrap.bind('alt+shift+s', () =>
  adaptableApi.formatColumnApi.openFormatColumnSettingsPanel()
);
Mousetrap.bind('alt+shift+c', () =>
  adaptableApi.calculatedColumnApi.openCalculatedColumnSettingsPanel()
);
// Define 2 hotkeys using NO dependency - just the native 'keydown' event
document.addEventListener('keydown', event => {
  const {key, shiftKey, metaKey} = event;
  // metaKey is 'command key' on Mac and 'windows key' on PC
  if (key === 'l' && metaKey && shiftKey) {
    event.preventDefault();
    adaptableApi.layoutApi.openLayoutSettingsPanel();
  }
  if (key === 's' && metaKey && shiftKey) {
    event.preventDefault();
    adaptableApi.quickSearchApi.showFloatingQuickSearch();
  }
```

- Try the different HotKey combinations or fork the project to add some of your own

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template] + mousetrap
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'HotKeys',
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';
import Mousetrap from 'mousetrap';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  // Define 2 Hotkeys using mousetrap - a 3rd party library (which is not shipped with AdapTable))
  Mousetrap.bind('alt+shift+s', () =>
    adaptableApi.formatColumnApi.openFormatColumnSettingsPanel()
  );
  Mousetrap.bind('alt+shift+c', () =>
    adaptableApi.calculatedColumnApi.openCalculatedColumnSettingsPanel()
  );

  // Define 2 hotkeys using NO dependency - just the native 'keydown' event
  document.addEventListener('keydown', event => {
    const {key, shiftKey, metaKey} = event;

    // metaKey is 'command key' on Mac and 'windows key' on PC
    if (key === 'l' && metaKey && shiftKey) {
      event.preventDefault();
      adaptableApi.layoutApi.openLayoutSettingsPanel();
    }
    if (key === 's' && metaKey && shiftKey) {
      event.preventDefault();
      adaptableApi.quickSearchApi.showFloatingQuickSearch();
    }
  });
};
```
