[imgui] Как сделать выбор клавиши как в биндере

qdIbp

Автор темы
Автор темы
Проверенный
1,388
1,146
Версия MoonLoader
.026-beta
Как сделать выбор клавиши как в биндере, чтобы потом можно было взаимодействовать с этой клавишой
 
Решение
Из скрипта вырезал. Протестируй.
Lua:
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

local tLastKeys = {}

local path = getGameDirectory()..'\\moonloader\\config\\hotkey.json'

local config = {
    hot_key = {v = {VK_C}},
}

-- Load json
if not doesFileExist(path) then
    local f = io.open(path, 'w+')
    f:write(encodeJson(config)):close()
else
    local f = io.open(path, "r")
    a = f:read("*a")
    config = decodeJson(a)
    f:close()
end

-- Main
bind = rkeys.registerHotKey(config.hot_key.v, true, function()
    -- Тут действие на HotKey. Принцип как у sampRegisterChatCommand вроде.
end)

-- OnDrawFrame
if imgui.HotKey("##1", config.hot_key, tLastKeys, 100) then
    rkeys.changeHotKey(bind...

Dmitriy Makarov

25.05.2021
Проверенный
2,481
1,113
Из скрипта вырезал. Протестируй.
Lua:
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

local tLastKeys = {}

local path = getGameDirectory()..'\\moonloader\\config\\hotkey.json'

local config = {
    hot_key = {v = {VK_C}},
}

-- Load json
if not doesFileExist(path) then
    local f = io.open(path, 'w+')
    f:write(encodeJson(config)):close()
else
    local f = io.open(path, "r")
    a = f:read("*a")
    config = decodeJson(a)
    f:close()
end

-- Main
bind = rkeys.registerHotKey(config.hot_key.v, true, function()
    -- Тут действие на HotKey. Принцип как у sampRegisterChatCommand вроде.
end)

-- OnDrawFrame
if imgui.HotKey("##1", config.hot_key, tLastKeys, 100) then
    rkeys.changeHotKey(bind, config.hot_key.v)
    JSONSave()
end

-- Save JSON
function JSONSave()
    if doesFileExist(path) then
        local f = io.open(path, 'w+')
        if f then
            f:write(encodeJson(config)):close()
        end
    end
end
Lua:
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey

local tLastKeys = {}

hot_key = {v = {VK_C}}

-- Main
bind = rkeys.registerHotKey(hot_key.v, true, function()
    -- Тут действие на HotKey. Принцип как у sampRegisterChatCommand вроде.
end)

-- OnDrawFrame
if imgui.HotKey("##1", hot_key, tLastKeys, 100) then
    rkeys.changeHotKey(bind, hot_key.v)
end
 
  • Нравится
Реакции: YarikVL и qdIbp