HOOZi文档
Skip to content

input

输入 + keybind formatter。


input.is_active(path) → bool

参数path : string —— 控件 full_path(hotkey 控件)

返回该 hotkey 当前是否处于 active 状态(按 mode 不同:Toggle = 已切到 on / Hold = 正按住 / Always = 永远 true)。


input.format(path, fn)

给 keybind 控件挂动态文字 + 颜色提示,formatter 只在该 hotkey 处于 active 状态(出现在 "active keybinds" 浮窗中)时调用。

参数

  • path : string —— 菜单元素 full_pathPattern B hotkey ID(两种都接受)
  • fn : function(id : string) → string | { text = string, color = {r,g,b,a} }

path 自动解析

传 menu element full_path(自然语义)即可 —— 如果该元素是 KeybindControl 且内部把 keybind 重映射到稳定 ID,会自动跟随到那个稳定 ID。

调用形式解析过程
input.format("settings.display.menu", fn)→ 解析到 hotkey.menu_open
input.format("hotkey.menu_open", fn)→ 直接用
input.format("KbHints.g.alarm", fn)→ 用户自建 KeybindControl 无重映射,用 full_path

fn 返回类型

返回行为
string用主题色显示该文本
table {text, color={r,g,b,a}}自定义文本 + 颜色
其他LOG_ERR + 走默认显示

Owner-scoped:脚本卸载时自动 unregister。


input.unformat(path)

path 解析逻辑与 input.format 相同。


input.clipboard_get() → string

读系统剪贴板。空时返空 string。

input.clipboard_set(text)

写系统剪贴板。

lua
local key = input.clipboard_get()
if key ~= "" then gui.notify:info("已读取: " .. key) end

input.clipboard_set("hello")

不提供 input.is_down(vk) —— 双机架构下 OS 按键 API 读的是程序所在机器而非游戏玩家。查玩家按键走 game.localplayer.* 字段(如 is_zoomingis_grenade)。详见 入门指南


示例

lua
-- formatter #1:纯 string
input.format("KbHints.g.alarm", function(id)
    return alarm_armed and "ARMED" or "OFF"
end)

-- formatter #2:返 {text, color} table
input.format("KbHints.g.stopwatch", function(id)
    local sec = os.clock() - start_t
    return {
        text  = string.format("%.1fs", sec),
        color = { 0.55, 0.85, 1.0, 1.0 },
    }
end)

-- formatter #3:按阈值动态变色
input.format("KbHints.g.counter", function(id)
    local label = string.format("× %d", counter)
    if counter == 0     then return { text = label, color = { 0.6, 0.6, 0.6, 1.0 } } end
    if counter < 10     then return { text = label, color = { 0.3, 1.0, 0.3, 1.0 } } end
    return { text = label, color = { 1.0, 0.45, 0.25, 1.0 } }
end)