{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

KeyInjectionScopeKt

public final class KeyInjectionScopeKt


Summary

Public methods

static final boolean

Verifies whether either of the alt keys are down.

static final boolean

Verifies whether either of the control keys are down.

static final boolean

Verifies whether the function key is down.

static final boolean

Verifies whether either of the meta keys are down.

static final boolean

Verifies whether either of the shift keys are down.

static final void
pressKey(
    @NonNull KeyInjectionScope receiver,
    @NonNull Key key,
    long pressDurationMillis
)

Holds down the given key for the given pressDurationMillis by sending a key down event, advancing the event time and sending a key up event.

static final void
withKeyDown(
    @NonNull KeyInjectionScope receiver,
    @NonNull Key key,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, whilst holding down the given key.

static final void
withKeyToggled(
    @NonNull KeyInjectionScope receiver,
    @NonNull Key key,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, in between presses to the given key.

static final void
withKeysDown(
    @NonNull KeyInjectionScope receiver,
    @NonNull List<@NonNull Key> keys,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, whilst holding down the each of the given keys.

static final void
withKeysToggled(
    @NonNull KeyInjectionScope receiver,
    @NonNull List<@NonNull Key> keys,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, in between presses to the given keys.

Public methods

isAltDown

public static final boolean isAltDown(@NonNull KeyInjectionScope receiver)

Verifies whether either of the alt keys are down.

Returns
boolean

true if an alt key is currently down, false otherwise.

isCtrlDown

public static final boolean isCtrlDown(@NonNull KeyInjectionScope receiver)

Verifies whether either of the control keys are down.

Returns
boolean

true if a control key is currently down, false otherwise.

isFnDown

public static final boolean isFnDown(@NonNull KeyInjectionScope receiver)

Verifies whether the function key is down.

Returns
boolean

true if the function key is currently down, false otherwise.

isMetaDown

public static final boolean isMetaDown(@NonNull KeyInjectionScope receiver)

Verifies whether either of the meta keys are down.

Returns
boolean

true if a meta key is currently down, false otherwise.

isShiftDown

public static final boolean isShiftDown(@NonNull KeyInjectionScope receiver)

Verifies whether either of the shift keys are down.

Returns
boolean

true if a shift key is currently down, false otherwise.

pressKey

public static final void pressKey(
    @NonNull KeyInjectionScope receiver,
    @NonNull Key key,
    long pressDurationMillis
)

Holds down the given key for the given pressDurationMillis by sending a key down event, advancing the event time and sending a key up event.

If the given key is already down, an IllegalStateException will be thrown.

Parameters
@NonNull Key key

The key to be pressed down.

long pressDurationMillis

Duration of press in milliseconds.

withKeyDown

public static final void withKeyDown(
    @NonNull KeyInjectionScope receiver,
    @NonNull Key key,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, whilst holding down the given key. This key must not be used within the block.

If the given key is already down, an IllegalStateException will be thrown.

Parameters
@NonNull Key key

The key to be held down during injection of the block.

@ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block

Sequence of KeyInjectionScope methods to be injected with the given key down.

withKeyToggled

public static final void withKeyToggled(
    @NonNull KeyInjectionScope receiver,
    @NonNull Key key,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, in between presses to the given key. This key can also be used within the block, as long as it is not down at the end of the block.

If the given key is already down, an IllegalStateException will be thrown.

Parameters
@NonNull Key key

The key to be toggled around the injection of the block.

@ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block

Sequence of KeyInjectionScope methods to be injected with the given key down.

withKeysDown

public static final void withKeysDown(
    @NonNull KeyInjectionScope receiver,
    @NonNull List<@NonNull Key> keys,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, whilst holding down the each of the given keys. Each of the keys will be pressed down and released simultaneously. These keys must not be used within the block.

If any of the given keys are already down, an IllegalStateException will be thrown.

Parameters
@NonNull List<@NonNull Key> keys

List of keys to be held down during injection of the block.

@ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block

Sequence of KeyInjectionScope methods to be injected with the given keys down.

withKeysToggled

public static final void withKeysToggled(
    @NonNull KeyInjectionScope receiver,
    @NonNull List<@NonNull Key> keys,
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Executes the keyboard sequence specified in the given block, in between presses to the given keys. Each of the keys will be toggled simultaneously.These keys can also be used within the block, as long as they are not down at the end of the block.

If any of the given keys are already down, an IllegalStateException will be thrown.

Parameters
@NonNull List<@NonNull Key> keys

The keys to be toggled around the injection of the block.

@ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block

Sequence of KeyInjectionScope methods to be injected with the given keys down.