[mimgui] HotKey

EX4MPLYCH

Участник
Автор темы
42
6
Версия MoonLoader
.026-beta
Взял отсюда хоткейи. По началу работало нормально, мог биндить сочетание клавиш. А теперь лишь одну клавишу дает сохранить. В чем проблема?

У меня сохранения идет в первом варианте в json
Во втором в ini
Lua:
local newFrame = imgui.OnFrame(
    function() return renderWindow[0] and not isPauseMenuActive() end,
    function(player)
        imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(700, 700))
        imgui.Begin("###12345", renderWindow, (imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoScrollbar))
            
            imgui.SetCursorPos(imgui.ImVec2(430, 15))
            imgui.HotKey("Кнопка биндов", tbinder[PickedTab].binds[defaultbind].key, 'v', "Свободно", string.find(tbinder[PickedTab].binds[defaultbind].key.v, '+') and 150)
            imgui.SameLine()
            imgui.HotKey("Кнопка активаций", info.Info, 'Key', "Свободно", string.find(info.Info.Key, '+') and 100 or 75)
            
        imgui.End()
)


function getDownKeys()
      local curkeys = ''
      local bool = false
      for k, v in pairs(vkeys) do
        if isKeyDown(v) and (v == VK_MENU or v == VK_CONTROL or v == VK_SHIFT or v == VK_LMENU or v == VK_RMENU or v == VK_RCONTROL or v == VK_LCONTROL or v == VK_LSHIFT) then
          if v ~= VK_MENU and v ~= VK_CONTROL and v ~= VK_SHIFT then
            curkeys = v
          end
        end
      end
      for k, v in pairs(vkeys) do
        if isKeyDown(v) and (v ~= VK_MENU and v ~= VK_CONTROL and v ~= VK_SHIFT and v ~= VK_LMENU and v ~= VK_RMENU and v ~= VK_RCONTROL and v ~= VK_LCONTROL and v ~= VK_LSHIFT) then
          if string.len(tostring(curkeys)) == 0 then
            curkeys = v
            return curkeys,true
          else
            curkeys = curkeys .. ' ' .. v
            return curkeys,true
          end
          bool = false
        end
      end
      return curkeys, bool
end
 
function imgui.GetKeysName(keys)
      if type(keys) ~= 'table' then
          return false
      else
          local tKeysName = {}
          for k = 1, #keys do
          tKeysName[k] = vkeys.id_to_name(tonumber(keys[k]))
          end
          return tKeysName
      end
end
function string.split(inputstr, sep)
      if sep == nil then
        sep = '%s'
      end
      local t={} ; i=1
      for str in string.gmatch(inputstr, '([^'..sep..']+)') do
        t[i] = str
        i = i + 1
      end
      return t
end
function isKeysDown(keylist, pressed)
      if keylist == nil then return end
      keylist = (string.find(keylist, '.+ %p .+') and {keylist:match('(.+) %p .+'), keylist:match('.+ %p (.+)')} or {keylist})
      local tKeys = keylist
      if pressed == nil then
        pressed = false
      end
      if tKeys[1] == nil then
        return false
      end
      local bool = false
      local key = #tKeys < 2 and tKeys[1] or tKeys[2]
      local modified = tKeys[1]
      if #tKeys < 2 then
        if wasKeyPressed(vkeys.name_to_id(key, true)) and not pressed then
          bool = true
        elseif isKeyDown(vkeys.name_to_id(key, true)) and pressed then
          bool = true
        end
      else
        if isKeyDown(vkeys.name_to_id(modified,true)) and not wasKeyReleased(vkeys.name_to_id(modified, true)) then
          if wasKeyPressed(vkeys.name_to_id(key, true)) and not pressed then
            bool = true
          elseif isKeyDown(vkeys.name_to_id(key, true)) and pressed then
            bool = true
          end
        end
      end
      if nextLockKey == keylist then
        if pressed and not wasKeyReleased(vkeys.name_to_id(key, true)) then
          bool = false
        else
          bool = false
          nextLockKey = ''
        end
      end
      return bool
end
function imgui.HotKey(name, path, pointer, defaultKey, width)
      local width = width or 90
      local cancel = isKeyDown(0x08)
      local tKeys, saveKeys = string.split(getDownKeys(), ' '),select(2,getDownKeys())
      local name = tostring(name)
      local keys, bool = path[pointer] or defaultKey, false
 
      local sKeys = keys
      for i=0,2 do
          if imgui.IsMouseClicked(i) then
              tKeys = {i==2 and 4 or i+1}
              saveKeys = true
          end
      end
 
      if tHotKeyData.edit ~= nil and tostring(tHotKeyData.edit) == name then
          if not cancel then
              if not saveKeys then
                  if #tKeys == 0 then
                      sKeys = (math.ceil(imgui.GetTime()) % 2 == 0) and '______' or ' '
                  else
                      sKeys = table.concat(imgui.GetKeysName(tKeys), ' + ')
                  end
              else
                  path[pointer] = table.concat(imgui.GetKeysName(tKeys), ' + ')
                  tHotKeyData.edit = nil
                  tHotKeyData.lasted = os.clock()
                 infocfg.save(info, "MedicInfo")
              end
          else
              path[pointer] = defaultKey
              tHotKeyData.edit = nil
              tHotKeyData.lasted = os.clock()
              infocfg.save(info, "MedicInfo")
          end
      end
      imgui.PushStyleColor(imgui.Col.Button, imgui.GetStyle().Colors[imgui.Col.FrameBg])
      imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
      imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.GetStyle().Colors[imgui.Col.FrameBgActive])
      if imgui.Button((sKeys ~= '' and u8(sKeys) or u8'Empty') .. '## '..name, imgui.ImVec2(width, 0)) then
          tHotKeyData.edit = name
      end
      imgui.PopStyleColor(3)
      return bool
end

function imgui.ButtonWithSettings(text, settings, size)
      imgui.PushStyleVarFloat(imgui.StyleVar.FrameRounding, settings.rounding or imgui.GetStyle().FrameRounding)
      imgui.PushStyleColor(imgui.Col.Button, settings.color or imgui.GetStyle().Colors[imgui.Col.Button])
      imgui.PushStyleColor(imgui.Col.ButtonHovered, settings.color_hovered or imgui.GetStyle().Colors[imgui.Col.ButtonHovered])
      imgui.PushStyleColor(imgui.Col.ButtonActive, settings.color_active or imgui.GetStyle().Colors[imgui.Col.ButtonActive])
      imgui.PushStyleColor(imgui.Col.Text, settings.color_text or imgui.GetStyle().Colors[imgui.Col.Text])
      local click = imgui.Button(text, size)
      imgui.PopStyleColor(4)
      imgui.PopStyleVar()
      return click
end