View Source AFK.State (afk v0.3.2)
A GenServer process representing the current state of the keyboard.
The process can effectively be thought of as a realtime stream manipulator. It
receives key press and key release events (through press_key/2
and
release_key/2
respectively) and transforms them into an outgoing event
stream of HID reports.
The process will send message to the given :event_receiver
of the form
{:hid_report, hid_report}
.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Presses a key.
Releases a key being pressed.
Starts the state GenServer.
Link to this section Types
@type args() :: [ event_receiver: pid(), keymap: AFK.Keymap.t(), hid_report_mod: atom() ]
@type t() :: %AFK.State{ event_receiver: pid(), hid_report_mod: atom(), indexed_keys: %{required(non_neg_integer()) => {atom(), AFK.Keycode.Key.t()}}, keymap: AFK.State.Keymap.t(), keys: %{required(atom()) => AFK.Keycode.t()}, last_hid_report: nil | binary(), locked_keys: [{atom(), AFK.Keycode.t()}], modifiers: [{atom(), AFK.Keycode.Modifier.t()}], pending_lock?: boolean() }
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec press_key(server :: GenServer.server(), key :: atom()) :: :ok
Presses a key.
The given key must not already be being pressed, otherwise the server will crash.
@spec release_key(server :: GenServer.server(), key :: atom()) :: :ok
Releases a key being pressed.
The given key must be being pressed, otherwise the server will crash.
@spec start_link(args(), opts :: GenServer.options()) :: GenServer.on_start()
Starts the state GenServer.
The three required arguments (in the form of a keyword list) are:
:event_receiver
- A PID to send the HID reports to.:keymap
- The keymap to use (seeAFK.Keymap
for details).:hid_report_mod
- A module that implements theAFK.HIDReport
behaviour.