Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros #30

Open
amclain opened this issue Jul 1, 2020 · 0 comments
Open

Macros #30

amclain opened this issue Jul 1, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@amclain
Copy link
Member

amclain commented Jul 1, 2020

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.)

@doughsay doughsay added the enhancement New feature or request label Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants