# KeyGesture

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/input/struct-keygesture/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct KeyGesture
```

Defines a keyboard input combination.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L10)

## Members

- [`new`](#function-new)
- [`from_key`](#function-from_key)
- [`key`](#function-key)
- [`key_modifiers`](#function-key_modifiers)
- [`parse`](#function-parse)
- [`matches`](#function-matches)
- [`to_platform_string`](#function-to_platform_string)
- [`to_string_format`](#function-to_string_format)
- [`format_with`](#function-format_with)

<a id="function-new"></a>

### new

```rust
const fn new(key: Key, modifiers: KeyModifiers) -> Self
```

Creates a gesture for a key with modifiers.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L17)

<a id="function-from_key"></a>

### from_key

```rust
const fn from_key(key: Key) -> Self
```

Creates a gesture for a key without modifiers.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L22)

<a id="function-key"></a>

### key

```rust
const fn key(self: &Self) -> Key
```

The key of the gesture.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L28)

<a id="function-key_modifiers"></a>

### key_modifiers

```rust
const fn key_modifiers(self: &Self) -> KeyModifiers
```

The modifier keys of the gesture.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L34)

<a id="function-parse"></a>

### parse

```rust
fn parse(gesture: &str) -> Result<KeyGesture, ParseKeyModifiersError>
```

Parses a gesture such as `Ctrl+Shift+A`.

Parts are separated by `+`. The last part that names a key decides
the key (`+`, `-`, `.` and `,` name the corresponding OEM keys);
every other part must be a modifier: `Ctrl`/`Control`, `Shift`,
`Alt`, `Meta`/`Cmd`/`Win`/`⌘`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L44)

<a id="function-matches"></a>

### matches

```rust
fn matches(self: &Self, key_event: Option<&KeyEventArgs>) -> bool
```

Whether a key event matches the gesture: same modifiers and the
same key, where the numpad operation keys match their regular
counterparts.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L77)

<a id="function-to_platform_string"></a>

### to_platform_string

```rust
fn to_platform_string(self: &Self, format_provider: Option<Rc<KeyGestureFormatInfo>>) -> String
```

Formats the gesture with the platform's names for keys and
modifiers (the `p` format): the given format info, or the one
registered with the locator, or the invariant one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L130)

<a id="function-to_string_format"></a>

### to_string_format

```rust
fn to_string_format(self: &Self, format: Option<&str>, format_provider: Option<Rc<KeyGestureFormatInfo>>) -> Result<String, FormatError>
```

Returns the gesture as a string formatted according to the format string and the
format provider.

The format is `None`, an empty string or `"g"` for the invariant format, or `"p"`
for the platform specific format: the given format info, or the one registered with
the locator, or the invariant one.

Fails with a `FormatError` if the format string is anything else.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L142)

<a id="function-format_with"></a>

### format_with

```rust
fn format_with(self: &Self, format_info: &KeyGestureFormatInfo) -> String
```

Formats the gesture with the given format info.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/input/key_gesture.rs#L157)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Eq`
- `Hash`
- `FromStr`
- `Display`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
