<!-- https://abap2ui5.github.io/docs/cookbook/browser_interaction/keyboard_shortcuts -->

# Keyboard Shortcuts

The `keyboard_shortcut` frontend event binds a key combination to a **named backend event** — the declarative equivalent of a `sap.ui.core.CommandExecution` shortcut, which needs a controller method and therefore has no place in a controller-less abap2UI5 app. The binding is pure data: the key combination and the name of the backend event it fires.

## Registering a Shortcut

`t_arg` is positional — the key combination and the backend event name:

```abap
CLASS z2ui5_cl_sample_shortcut DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS z2ui5_cl_sample_shortcut IMPLEMENTATION.
  METHOD z2ui5_if_app~main.

    IF client->check_on_navigated( ).

      client->follow_up_action( val   = client->cs_event-keyboard_shortcut
                                t_arg = VALUE #( ( `Ctrl+S` )
                                                 ( `SAVE` ) ) ).

      client->follow_up_action( val   = client->cs_event-keyboard_shortcut
                                t_arg = VALUE #( ( `Ctrl+D` )
                                                 ( `DELETE` ) ) ).

      DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
          )->ele( n = `View` ns = `mvc`
              )->a( n = `xmlns`     v = `sap.m`
              )->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`

              )->ele( `Page`
                  )->a( n = `title` v = `Keyboard Shortcuts`

                  )->tag( `Text`
                      )->a( n = `text` v = `Press Ctrl+S or Ctrl+D` ).

      client->view_display( view->stringify( ) ).

    ELSEIF client->check_on_event( `SAVE` ).
      client->message_toast_display( `Saved via Ctrl+S` ).

    ELSEIF client->check_on_event( `DELETE` ).
      client->message_toast_display( `Deleted via Ctrl+D` ).

    ENDIF.

  ENDMETHOD.
ENDCLASS.
```

Pressing the combination fires the backend event exactly like a button press would — and the browser default for the combination is suppressed.

## Behavior

- **Spelling** follows the UI5 convention: `Ctrl+S`, `Ctrl+Shift+D`, `F2`. Common aliases are normalized (`Cmd`/`Command` → `Meta`, `Control` → `Ctrl`, `Esc` → `Escape`, `Return` → `Enter`, …), so registration and keypress match for any spelling.
- **One registration per combination.** Registering the same combination again rebinds it — no need to unregister first.
- **Unregister** a combination by sending it with an empty event name:

```abap
client->follow_up_action( val   = client->cs_event-keyboard_shortcut
                          t_arg = VALUE #( ( `Ctrl+S` )
                                           ( `` ) ) ).
```

- **Lifetime:** the registry lives in the frontend and survives every roundtrip until the app is left. Navigating to another app starts from an empty set.

The same registration also works without a backend roundtrip: write the `follow_up_action( )` call where its result is consumed, as a view attribute, with the identical `t_arg` — see [the two positions](/cookbook/event_navigation/frontend#the-two-positions).

::: tip
See demo app 471 in the [samples repository](https://github.com/abap2UI5/samples) for a complete example.
:::

For controlling the *soft keyboard* on mobile devices, see [Soft Keyboard](/cookbook/browser_interaction/soft_keyboard).

<!-- samples:start (generated by scripts/link-samples.mjs — do not edit) -->

## Working Samples

Complete apps from the [sample catalog](https://github.com/abap2UI5/samples/blob/main/SAMPLES.md)
that use what this page describes. Each is a single class — pull the repository with
[abapGit](https://abapgit.org) and start it with `?app_start=<class>`.

| Sample | Class |
|---|---|
| Keyboard Shortcuts, Ctrl+S (A) | [`Z2UI5_CL_SMP_APP_471`](https://github.com/abap2UI5/samples/blob/main/src/01/z2ui5_cl_smp_app_471.clas.abap) |

<!-- samples:end -->
