2023-06-25 17:18:50 -05:00
|
|
|
-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
-- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2023-06-25 17:49:06 -05:00
|
|
|
--
|
|
|
|
-- SPDX-License-Identifier: MPL-2.0
|
2023-06-25 17:18:50 -05:00
|
|
|
|
2023-07-21 21:02:02 -05:00
|
|
|
---@class InputModule
|
|
|
|
local input_module = {
|
2023-06-21 17:36:51 -05:00
|
|
|
keys = require("keys"),
|
|
|
|
}
|
2023-06-15 12:42:34 -05:00
|
|
|
|
2023-07-02 10:26:07 -05:00
|
|
|
---Set a keybind. If called with an already existing keybind, it gets replaced.
|
2023-07-11 11:59:38 -05:00
|
|
|
---
|
2023-07-18 15:12:23 -05:00
|
|
|
---### Example
|
2023-07-11 11:59:38 -05:00
|
|
|
---
|
|
|
|
---```lua
|
2023-07-21 21:02:02 -05:00
|
|
|
----- Set `Super + Return` to open Alacritty
|
2023-07-11 11:59:38 -05:00
|
|
|
---input.keybind({ "Super" }, input.keys.Return, function()
|
|
|
|
--- process.spawn("Alacritty")
|
|
|
|
---end)
|
|
|
|
---```
|
2023-07-02 10:26:07 -05:00
|
|
|
---@param key Keys The key for the keybind.
|
|
|
|
---@param modifiers (Modifier)[] Which modifiers need to be pressed for the keybind to trigger.
|
2023-07-11 11:59:38 -05:00
|
|
|
---@param action fun() What to do.
|
2023-07-21 21:02:02 -05:00
|
|
|
function input_module.keybind(modifiers, key, action)
|
2023-06-15 12:42:34 -05:00
|
|
|
table.insert(CallbackTable, action)
|
|
|
|
SendMsg({
|
|
|
|
SetKeybind = {
|
|
|
|
modifiers = modifiers,
|
|
|
|
key = key,
|
|
|
|
callback_id = #CallbackTable,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2023-07-21 21:02:02 -05:00
|
|
|
return input_module
|