Scenic.Driver.KeyMap behaviour (Scenic v0.11.0-beta.0) View Source

Behaviour and support functions for mapping physical keys to characters.

This module is meant to be implemented elsewhere and provided to a driver in order to localize key presses into the correct characters.

The :scenic_driver_local driver comes with a USEnglish key map, which it uses by default. Look at that one as an example on how to make a custom key mapping.

Link to this section Summary

Callbacks

Translate a key to a codepoint, which is really just a string.

Functions

Is any alt key pressed?

Is the caps lock enabled?

Is any ctrl key pressed?

Is any meta key pressed? This is usually the command button.

Generate the list of pressed modifier keys

Is the num lock enabled?

Is the scroll lock enabled?

Is the current set of keys shifted?

Link to this section Types

Specs

keys() :: %{required(atom()) => integer()}

Specs

mod_keys() :: [
  :meta | :alt | :ctrl | :shift | :caps_lock | :num_lock | :scroll_lock
]

Link to this section Callbacks

Link to this callback

map_key(key, value, keys, state)

View Source

Specs

map_key(key :: atom(), value :: integer(), keys :: keys(), state :: any()) ::
  {:ok, nil, state :: any()}
  | {:ok, codepoint :: String.t(), state :: any()}
  | {:error, msg :: String.t(), state :: any()}

Translate a key to a codepoint, which is really just a string.

The first time this is called, state is nil. After that you can return any state that makes sense and it will be passed back on the next call.

If the mapping is successful, i.e. the key press results in a valid character, Then this function should return { :ok, codepoint, state }. The returned codepoint will be sent on to the ViewPort as a codepoint input event.

If the key press does not map to a string (this is common), then the function should return { :ok, nil, state }. This will not result in a codepoint input being sent to the ViewPort.

If the data makes no sense at all, then you can return { :error, error_msg, state }. This will not send a codepoint input, but will log the error message, which should be a string.

Link to this section Functions

Specs

alt?(keys :: keys()) :: boolean()

Is any alt key pressed?

Specs

caps_lock?(keys :: keys()) :: boolean()

Is the caps lock enabled?

Returns true if any shift key or the caps lock is pressed or active.

Specs

ctrl?(keys :: keys()) :: boolean()

Is any ctrl key pressed?

Specs

meta?(keys :: keys()) :: boolean()

Is any meta key pressed? This is usually the command button.

Specs

mods(keys :: keys()) :: mod_keys()

Generate the list of pressed modifier keys

Specs

num_lock?(keys :: keys()) :: boolean()

Is the num lock enabled?

Returns true if num lock is pressed or active.

Specs

scroll_lock?(keys :: keys()) :: boolean()

Is the scroll lock enabled?

Returns true if scroll lock is pressed or active.

Specs

shift?(keys :: keys()) :: boolean()

Is the current set of keys shifted?

Returns true if any shift key or the caps lock is pressed or active.