forked from MCJack123/PrimeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyAction.lua
More file actions
20 lines (19 loc) · 815 Bytes
/
Copy pathkeyAction.lua
File metadata and controls
20 lines (19 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local PrimeUI = require "util" -- DO NOT COPY THIS LINE
local expect = require "cc.expect".expect -- DO NOT COPY THIS LINE
-- Start copying below this line. --
--- Adds an action to trigger when a key is pressed.
---@param key key The key to trigger on, from `keys.*`
---@param action function|string A function to call when clicked, or a string to use as a key for a `run` return event
function PrimeUI.keyAction(key, action)
expect(1, key, "number")
expect(2, action, "function", "string")
PrimeUI.addTask(function()
while true do
local _, param1 = os.pullEvent("key") -- wait for key
if param1 == key then
if type(action) == "string" then PrimeUI.resolve("keyAction", action)
else action() end
end
end
end)
end