Skip to content

slint::Keys Class

class Keys;
C++
#include <slint.h>
C++

A Keys is created by the @keys(…) macro in Slint and defines which key event(s) activate a KeyBinding.

slint::Keys::Keys()=default

Returns an empty keys instance, which never matches any key event.

slint::Keys::Keys(const Keys &)=default

Copy constructor.

slint::Keys::Keys(Keys &&)=default

Move constructor.

slint::Keys & slint::Keys::operator=(const Keys &)=default

Copy assignment operator.

slint::Keys & slint::Keys::operator=(Keys &&)=default

Move assignment operator.

SharedString slint::Keys::to_string() const

Returns a string that looks native on the current platform.

For example, the shortcut created with @keys(Meta + Control + A) will be converted like this:

  • macOS: ⌃⌘A
  • Windows: Win+Ctrl+A
  • Linux: Super+Ctrl+A

Note that this functions output is best-effort and may be adjusted/improved at any time, do not rely on this output to be stable!

static std::optional< Keys > slint::Keys::from_parts(std::span< const std::string_view > parts)

Create a Keys from a span of string parts, e.g. {"Control", "Shift?", "Z"}.

Each element is either a modifier (Control, Shift, Alt, Meta, Shift?, Alt?) or a key name from the Key namespace (case-sensitive). If not found, it is treated as a string literal (must be a single lowercase grapheme cluster).

Returns std::nullopt on parse failure.

static std::optional< Keys > slint::Keys::from_parts(std::initializer_list< std::string_view > parts)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool operator==(const Keys &a, const Keys &b)

Equality operator, returns true if the two Keys instances are equal, i.e. they match the same key events.

bool operator!=(const Keys &a, const Keys &b)

Inequality operator, returns true if the two Keys instances are not equal, i.e. they match different key events.


© 2026 SixtyFPS GmbH