Skip to content

Macros #30

Open
Open
@amclain

Description

We would like to support macros, which turn one key event or key sequence into another. For example, Ctrl + Shift+ H causes the key sequence for Hello world to be typed. One way to implement this would be to listen for the desired input sequence, and output an AFK event when it is detected. This AFK event could then be handled by the application to decide what should happen next. The app could use AFK HID helpers to generate the sequence of events for Hello world. If this API were to be built on the right layers and abstractions, an application developer may be able to code this scenario like the following.

Set up a listener for the key sequence:

@spec AFK.Macro.new(event_name :: atom, key_sequence :: [Key.t]) :: Macro.t

macro = AFK.Macro.new(
  :type_hello_world,
  [AFK.Key.ctrl, AFK.Key.shift, AFK.Key.h]
)

AFK.register(macro)

Handle the AFK event when a macro is triggered:

@spec handle_afk_event(event_name :: atom, params :: map, state :: any) ::
  {:noreply, state}
def handle_afk_event(:type_hello_world, _params, state) do
  AFK.USB.key_sequence_from_string("Hello world")
  |> Enum.each(fn hid_report ->
    AFK.USB.send_hid_report(state.hid_device, hid_report)
  end)

  {:noreply, state}
end

(This is pseudo code and the concept is open to modification.)

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions