# KeyboardDevice

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

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

```rust
struct KeyboardDevice
```

Represents the keyboard: turns raw key and text input into routed
events on the focused element, and is the source of truth about which
element has keyboard focus.

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

## Members

- [`new`](#function-new)
- [`instance`](#function-instance)
- [`input_manager`](#function-input_manager)
- [`focus_manager`](#function-focus_manager)
- [`property_changed`](#function-property_changed)
- [`focused_element`](#function-focused_element)
- [`set_focused_element`](#function-set_focused_element)
- [`set_focused_element_with`](#function-set_focused_element_with)

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

### new

```rust
fn new() -> Rc<KeyboardDevice>
```

Creates a keyboard device.

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

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

### instance

```rust
fn instance() -> Option<Rc<KeyboardDevice>>
```

The keyboard device registered with the locator (as
`dyn IKeyboardDevice`), if it is a `KeyboardDevice`.

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

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

### input_manager

```rust
fn input_manager(self: &Self) -> Option<Rc<dyn IInputManager>>
```

The input manager registered with the locator.

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

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

### focus_manager

```rust
fn focus_manager(self: &Self) -> Option<Rc<dyn IFocusManager>>
```

The focus manager registered with the locator.

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

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

### property_changed

```rust
fn property_changed(self: &Self, handler: impl Fn(&str) -> () + 'static) -> Subscription
```

Raised with the name of a property of the device that changed
(`"FocusedElement"`). Dropping the returned guard removes the
handler; `Subscription::detach` keeps it for the life of the
device.

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

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

### focused_element

```rust
fn focused_element(self: &Self) -> Option<Ref<InputElement>>
```

The element that has keyboard focus.

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

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

### set_focused_element

```rust
fn set_focused_element(self: &Self, element: Option<&Ref<InputElement>>, method: NavigationMethod, key_modifiers: KeyModifiers)
```

Moves keyboard focus to an element (or clears it); the change can be
cancelled or redirected by `LosingFocus`/`GettingFocus` handlers.

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

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

### set_focused_element_with

```rust
fn set_focused_element_with(self: &Self, element: Option<&Ref<InputElement>>, method: NavigationMethod, key_modifiers: KeyModifiers, is_focus_change_cancellable: bool)
```

Moves keyboard focus to an element (or clears it).

`is_focus_change_cancellable` tells whether `LosingFocus` and
`GettingFocus` handlers may cancel or redirect the change.

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

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`
- [`IInputDevice`](/docs/0.5.0/api/ferroui-base/input/trait-iinputdevice/)
- [`IKeyboardDevice`](/docs/0.5.0/api/ferroui-base/input/trait-ikeyboarddevice/)

## Availability

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