Module dkb.keybindings

Module to set keybindings This module is the base of dkb.

You can use it by itself or together with the other modules to produce very readable and self-documented files of lua code that set-up the keybindings. See the examples below for the recommended usage.

Functions

Bindings:bind (mods, key, action, options) Bind mod+key to an action.
Bindings:bindmod (mods, action) Returns a function that binds a key with a specific mod to a default action.

Returned functions

Binding:bindmod:return (key, action, arguments, options) Function returned by Bindings:bindmod


Functions

Methods
Bindings:bind (mods, key, action, options)
Bind mod+key to an action. It is recommended to use Bindings:bindmod instead.

Parameters:

  • mods string String containing the necessary modifier. Same as supported by hs.hotkey.
  • key string String representing the key to be mapped. See hs.keycodes.map.
  • action func Function to be executed when the keybinding is pressed.
  • options table

    Table containing the possible options. Defaults to function called on press if an empty table is passed. Each option can accept a bool or func. If bool is provied and true, action will be invoked. If func is provided, it will be invoked instead. Possible options are:

    • pressed: defaults to true

    • released: defaults to false

    • hold_repeat: defaults to false

See also:

Bindings:bindmod (mods, action)
Returns a function that binds a key with a specific mod to a default action. The action can receive parameters or can be replaced with a provided one. This allows for aliasing modifier combinations, making them easily identificable through the code.

Parameters:

  • mods string String containing the necessary modifier. Same as supported by hs.hotkey.
  • action func Default function to be called if none are provided

Returns:

    func Function be used to declare bindings with the provided mods and default_function documented in Binding:bindmod:return.

See also:

Usage:

    mod1 = keybindings:bindmod("⌃⌘", yabai.cmd)
    
    mod1("l", "window --focus east") --> Will execute yabai.cmd with provied argument
    mod1("p", print, "key p pressed") --> Will print "key p pressed" when pressing ⌃⌘+p

Returned functions

Binding:bindmod:return (key, action, arguments, options)
Function returned by Bindings:bindmod

Parameters:

  • key string String representing the key to be mapped. See hs.keycodes.map.
  • action func[opt] If provided as second argument, the provided function will be called instead of the default_function.
  • arguments string[opt] Each separate string will be passed in order as arguments to either the default function or to action if provided as second param.
  • options table[opt] if last argument is a table, it will be interepreted as options same as Bindings:bind.

See also:

generated by LDoc 1.5.0 Last updated 2023-10-31 00:05:48