Исходник ImGui HotKey / Custom by DonHomka

Статус
В этой теме нельзя размещать новые ответы.

AnWu

Известный
Автор темы
Всефорумный модератор
4,777
5,400
Всем привет. Слишком много текста для написания в полезные функции, но вот вам моя модификация над которой я ебался трудился последние сутки.

Что нам нужно?
- Голова, две руки (можно и одну, копировать не сложно)
- Dear ImGui
- MoonLoader v025

Приступим:
Функция получения текущих нажатых клавиш:
Lua:
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 or v == VK_RSHIFT) 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 and v ~= VK_RSHIFT) then
            if tostring(curkeys):len() == 0 then
                curkeys = v
            else
                curkeys = curkeys .. " " .. v
            end
            bool = true
        end
    end
    return curkeys, bool
end

Функция-пара для проерки нажатия клавиши:
Lua:
function isKeysDown(keylist, pressed)
    local tKeys = string.split(keylist, " ")
    if pressed == nil then
        pressed = false
    end
    if tKeys[1] == nil then
        return false
    end
    local bool = false
    local key = #tKeys < 2 and tonumber(tKeys[1]) or tonumber(tKeys[2])
    local modified = tonumber(tKeys[1])
    if #tKeys < 2 then
        if not isKeyDown(VK_RMENU) and not isKeyDown(VK_LMENU) and not isKeyDown(VK_LSHIFT) and not isKeyDown(VK_RSHIFT) and not isKeyDown(VK_LCONTROL) and not isKeyDown(VK_RCONTROL) then
            if wasKeyPressed(key) and not pressed then
                bool = true
            elseif isKeyDown(key) and pressed then
                bool = true
            end
        end
    else
        if isKeyDown(modified) and not wasKeyReleased(modified) then
            if wasKeyPressed(key) and not pressed then
                bool = true
            elseif isKeyDown(key) and pressed then
                bool = true
            end
        end
    end
    if nextLockKey == keylist then
        if pressed and not wasKeyReleased(key) then
            bool = false
--            nextLockKey = ""
        else
            bool = false
            nextLockKey = ""
        end
    end
    return bool
end

string.split
Lua:
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

Сама функция Hotkey():
Lua:
local editHotkey = nil
function imgui.Hotkey(name, keyBuf, width)
    local name = tostring(name)
    local keys, endkey = getDownKeys()
    local keysName = ""
    local ImVec2 = imgui.ImVec2
    local bool = false
    if editHotkey == name then
        if keys == VK_BACK then
            keyBuf.v = ''
            editHotkey = nil
            nextLockKey = keys
            editKeys = 0
        else
            local tNames = string.split(keys, " ")
            local keylist = ""
            for _, v in ipairs(tNames) do
                local key = tostring(vkeys.id_to_name(tonumber(v)))
                if tostring(keylist):len() == 0 then
                    keylist = key
                else
                    keylist = keylist .. " + " .. key
                end
            end
            keysName = keylist
            if endkey then
                bool = true
                keyBuf.v = keys
                editHotkey = nil
                nextLockKey = keys
                editKeys = 0
            end
        end
    else
        local tNames = string.split(keyBuf.v, " ")
        for _, v in ipairs(tNames) do
            local key = tostring(vkeys.id_to_name(tonumber(v)))
            if tostring(keysName):len() == 0 then
                keysName = key
            else
                keysName = keysName .. " + " .. key
            end
        end
    end
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    imgui.PushStyleColor(imgui.Col.Button, colors[clr.FrameBg])
    imgui.PushStyleColor(imgui.Col.ButtonActive, colors[clr.FrameBg])
    imgui.PushStyleColor(imgui.Col.ButtonHovered, colors[clr.FrameBg])
    imgui.PushStyleVar(imgui.StyleVar.ButtonTextAlign, ImVec2(0.04, 0.5))
    imgui.Button(u8((tostring(keysName):len() > 0 or editHotkey == name) and keysName or "Нет"), ImVec2(width, 20))
    imgui.PopStyleVar()
    imgui.PopStyleColor(3)
    if imgui.IsItemHovered() and imgui.IsItemClicked() and editHotkey == nil then
        editHotkey = name
        editKeys = 100
    end
    if name:len() > 0 then
        imgui.SameLine()
        imgui.Text(name)
    end
    return bool
end

Событие onWindowMessage():
Lua:
function onWindowMessage(msg, wparam, lparam)
    if(msg == 0x100 or msg == 0x101) then
        if (wparam == VK_ESCAPE or wparam == VK_RETURN or wparam == VK_TAB or wparam == VK_F6 or wparam == VK_F7 or wparam == VK_F8 or wparam == VK_T or wparam == VK_OEM_3) and msg == 0x100 and editKeys > 0 then
            consumeWindowMessage(true, true)
            editHotkey = nil
       end
    end
end

Теперь код
Lua:
-- Создаем буффер для клавиши.
-- Перед onDrawFrame()
-- keyAdminMenu - переменная для "бинда" клавиши.
-- hotKeyAdminMenu - буффер для imgui.Hotkey()
local hotKeyAdminMenu = imgui.ImBuffer(keyAdminMenu, 256)

-- В onDrawFrame()
-- В уже созданном окне (внутри Begin())
imgui.AlignTextToFramePadding()
if imgui.Hotkey(u8"Панель администратора", hotKeyAdminMenu, 80) then
      nextLockKey = hotKeyAdminMenu.v
      keyAdminMenu = hotKeyAdminMenu.v
 end
-- nextLockKey - чтобы во время изменения клавиши не сраотал другой хоткей

-- Идём в main()


if not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive() and isPlayerPlaying(playerHandle) and editKeys == 0 then
        
   if isKeysDown(keyAdminmenu) then
           sampSendChat("/amenu")
     end
end

Получаем что-то такое:
sa-mp-680.png


PS: Если что-то не работает пишите, возможно что-то упустил
PPS: Буду дорабатывать совместно с моим модом!
 
Последнее редактирование:

vbg

Известный
41
17
что может быть не так? Скрипт крашит.

Lua:
local SE = require 'lib.samp.events'
local memory = require 'memory'
local imgui = require 'imgui'
local bitex = require 'bitex'
local vkeys = require 'vkeys'
local GK = require 'game.keys'
local winmsg = require 'windows.message'
local encoding = require 'encoding'
local hotKeyAdminMenu = imgui.ImBuffer(keyAdminMenu, 256)
encoding.default = 'cp1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
function imgui.OnDrawFrame()
  if main_window_state.v then
    imgui.SetNextWindowSize(imgui.ImVec2(150, 200), imgui.Cond.FirstUseEver)

    imgui.Begin('My window', main_window_state)

            imgui.AlignTextToFramePadding()
            if imgui.Hotkey(u8"Панель администратора", hotKeyAdminMenu, 80) then
      nextLockKey = hotKeyAdminMenu.v
      keyAdminMenu = hotKeyAdminMenu.v
end
    end
    imgui.End()
  end

function main()
  while true do
    wait(0)
    if wasKeyPressed(key.VK_X) then
        main_window_state.v = not main_window_state.v
    end
    imgui.Process = main_window_state.v
  end
    if not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive() and isPlayerPlaying(playerHandle) and editKeys == 0 then

   if isKeysDown(keyAdminmenu) then
           sampAddChatMessage("/amenu")
     end
end
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 or v == VK_RSHIFT) 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 and v ~= VK_RSHIFT) then
            if tostring(curkeys):len() == 0 then
                curkeys = v
            else
                curkeys = curkeys .. " " .. v
            end
            bool = true
        end
    end
    return curkeys, bool
end

function isKeysDown(keylist, pressed)
    local tKeys = string.split(keylist, " ")
    if pressed == nil then
        pressed = false
    end
    if tKeys[1] == nil then
        return false
    end
    local bool = false
    local key = #tKeys < 2 and tonumber(tKeys[1]) or tonumber(tKeys[2])
    local modified = tonumber(tKeys[1])
    if #tKeys < 2 then
        if not isKeyDown(VK_RMENU) and not isKeyDown(VK_LMENU) and not isKeyDown(VK_LSHIFT) and not isKeyDown(VK_RSHIFT) and not isKeyDown(VK_LCONTROL) and not isKeyDown(VK_RCONTROL) then
            if wasKeyPressed(key) and not pressed then
                bool = true
            elseif isKeyDown(key) and pressed then
                bool = true
            end
        end
    else
        if isKeyDown(modified) and not wasKeyReleased(modified) then
            if wasKeyPressed(key) and not pressed then
                bool = true
            elseif isKeyDown(key) and pressed then
                bool = true
            end
        end
    end
    if nextLockKey == keylist then
        if pressed and not wasKeyReleased(key) then
            bool = false
--            nextLockKey = ""
        else
            bool = false
            nextLockKey = ""
        end
    end
    return bool
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

local editHotkey = nil
function imgui.Hotkey(name, keyBuf, width)
    local name = tostring(name)
    local keys, endkey = getDownKeys()
    local keysName = ""
    local ImVec2 = imgui.ImVec2
    local bool = false
    if editHotkey == name then
        if keys == VK_BACK then
            keyBuf.v = ''
            editHotkey = nil
            nextLockKey = keys
            editKeys = 0
        else
            local tNames = string.split(keys, " ")
            local keylist = ""
            for _, v in ipairs(tNames) do
                local key = tostring(vkeys.id_to_name(tonumber(v)))
                if tostring(keylist):len() == 0 then
                    keylist = key
                else
                    keylist = keylist .. " + " .. key
                end
            end
            keysName = keylist
            if endkey then
                bool = true
                keyBuf.v = keys
                editHotkey = nil
                nextLockKey = keys
                editKeys = 0
            end
        end
    else
        local tNames = string.split(keyBuf.v, " ")
        for _, v in ipairs(tNames) do
            local key = tostring(vkeys.id_to_name(tonumber(v)))
            if tostring(keysName):len() == 0 then
                keysName = key
            else
                keysName = keysName .. " + " .. key
            end
        end
    end
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    imgui.PushStyleColor(imgui.Col.Button, colors[clr.FrameBg])
    imgui.PushStyleColor(imgui.Col.ButtonActive, colors[clr.FrameBg])
    imgui.PushStyleColor(imgui.Col.ButtonHovered, colors[clr.FrameBg])
    imgui.PushStyleVar(imgui.StyleVar.ButtonTextAlign, ImVec2(0.04, 0.5))
    imgui.Button(u8((tostring(keysName):len() > 0 or editHotkey == name) and keysName or "Нет"), ImVec2(width, 20))
    imgui.PopStyleVar()
    imgui.PopStyleColor(3)
    if imgui.IsItemHovered() and imgui.IsItemClicked() and editHotkey == nil then
        editHotkey = name
        editKeys = 100
    end
    if name:len() > 0 then
        imgui.SameLine()
        imgui.Text(name)
    end
    return bool
end

function onWindowMessage(msg, wparam, lparam)
    if(msg == 0x100 or msg == 0x101) then
        if (wparam == VK_ESCAPE or wparam == VK_RETURN or wparam == VK_TAB or wparam == VK_F6 or wparam == VK_F7 or wparam == VK_F8 or wparam == VK_T or wparam == VK_OEM_3) and msg == 0x100 and editKeys > 0 then
            consumeWindowMessage(true, true)
            editHotkey = nil
       end
    end
end
 

AnWu

Известный
Автор темы
Всефорумный модератор
4,777
5,400
что может быть не так? Скрипт крашит.

Lua:
local SE = require 'lib.samp.events'
local memory = require 'memory'
local imgui = require 'imgui'
local bitex = require 'bitex'
local vkeys = require 'vkeys'
local GK = require 'game.keys'
local winmsg = require 'windows.message'
local encoding = require 'encoding'
local hotKeyAdminMenu = imgui.ImBuffer(keyAdminMenu, 256)
encoding.default = 'cp1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
function imgui.OnDrawFrame()
  if main_window_state.v then
    imgui.SetNextWindowSize(imgui.ImVec2(150, 200), imgui.Cond.FirstUseEver)

    imgui.Begin('My window', main_window_state)

            imgui.AlignTextToFramePadding()
            if imgui.Hotkey(u8"Панель администратора", hotKeyAdminMenu, 80) then
      nextLockKey = hotKeyAdminMenu.v
      keyAdminMenu = hotKeyAdminMenu.v
end
    end
    imgui.End()
  end

function main()
  while true do
    wait(0)
    if wasKeyPressed(key.VK_X) then
        main_window_state.v = not main_window_state.v
    end
    imgui.Process = main_window_state.v
  end
    if not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive() and isPlayerPlaying(playerHandle) and editKeys == 0 then

   if isKeysDown(keyAdminmenu) then
           sampAddChatMessage("/amenu")
     end
end
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 or v == VK_RSHIFT) 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 and v ~= VK_RSHIFT) then
            if tostring(curkeys):len() == 0 then
                curkeys = v
            else
                curkeys = curkeys .. " " .. v
            end
            bool = true
        end
    end
    return curkeys, bool
end

function isKeysDown(keylist, pressed)
    local tKeys = string.split(keylist, " ")
    if pressed == nil then
        pressed = false
    end
    if tKeys[1] == nil then
        return false
    end
    local bool = false
    local key = #tKeys < 2 and tonumber(tKeys[1]) or tonumber(tKeys[2])
    local modified = tonumber(tKeys[1])
    if #tKeys < 2 then
        if not isKeyDown(VK_RMENU) and not isKeyDown(VK_LMENU) and not isKeyDown(VK_LSHIFT) and not isKeyDown(VK_RSHIFT) and not isKeyDown(VK_LCONTROL) and not isKeyDown(VK_RCONTROL) then
            if wasKeyPressed(key) and not pressed then
                bool = true
            elseif isKeyDown(key) and pressed then
                bool = true
            end
        end
    else
        if isKeyDown(modified) and not wasKeyReleased(modified) then
            if wasKeyPressed(key) and not pressed then
                bool = true
            elseif isKeyDown(key) and pressed then
                bool = true
            end
        end
    end
    if nextLockKey == keylist then
        if pressed and not wasKeyReleased(key) then
            bool = false
--            nextLockKey = ""
        else
            bool = false
            nextLockKey = ""
        end
    end
    return bool
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

local editHotkey = nil
function imgui.Hotkey(name, keyBuf, width)
    local name = tostring(name)
    local keys, endkey = getDownKeys()
    local keysName = ""
    local ImVec2 = imgui.ImVec2
    local bool = false
    if editHotkey == name then
        if keys == VK_BACK then
            keyBuf.v = ''
            editHotkey = nil
            nextLockKey = keys
            editKeys = 0
        else
            local tNames = string.split(keys, " ")
            local keylist = ""
            for _, v in ipairs(tNames) do
                local key = tostring(vkeys.id_to_name(tonumber(v)))
                if tostring(keylist):len() == 0 then
                    keylist = key
                else
                    keylist = keylist .. " + " .. key
                end
            end
            keysName = keylist
            if endkey then
                bool = true
                keyBuf.v = keys
                editHotkey = nil
                nextLockKey = keys
                editKeys = 0
            end
        end
    else
        local tNames = string.split(keyBuf.v, " ")
        for _, v in ipairs(tNames) do
            local key = tostring(vkeys.id_to_name(tonumber(v)))
            if tostring(keysName):len() == 0 then
                keysName = key
            else
                keysName = keysName .. " + " .. key
            end
        end
    end
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    imgui.PushStyleColor(imgui.Col.Button, colors[clr.FrameBg])
    imgui.PushStyleColor(imgui.Col.ButtonActive, colors[clr.FrameBg])
    imgui.PushStyleColor(imgui.Col.ButtonHovered, colors[clr.FrameBg])
    imgui.PushStyleVar(imgui.StyleVar.ButtonTextAlign, ImVec2(0.04, 0.5))
    imgui.Button(u8((tostring(keysName):len() > 0 or editHotkey == name) and keysName or "Нет"), ImVec2(width, 20))
    imgui.PopStyleVar()
    imgui.PopStyleColor(3)
    if imgui.IsItemHovered() and imgui.IsItemClicked() and editHotkey == nil then
        editHotkey = name
        editKeys = 100
    end
    if name:len() > 0 then
        imgui.SameLine()
        imgui.Text(name)
    end
    return bool
end

function onWindowMessage(msg, wparam, lparam)
    if(msg == 0x100 or msg == 0x101) then
        if (wparam == VK_ESCAPE or wparam == VK_RETURN or wparam == VK_TAB or wparam == VK_F6 or wparam == VK_F7 or wparam == VK_F8 or wparam == VK_T or wparam == VK_OEM_3) and msg == 0x100 and editKeys > 0 then
            consumeWindowMessage(true, true)
            editHotkey = nil
       end
    end
end
Баг скрипта. Перед объявлением буффера для кнопки:
Lua:
keyAdminMenu = ""
Позже переделаю в либу
 
  • Нравится
Реакции: vbg

vbg

Известный
41
17
Баг скрипта. Перед объявлением буффера для кнопки:
Lua:
keyAdminMenu = ""
Позже переделаю в либу

Хм... Добавил строку в код но ничего не меняется...
Lua:
local SE = require 'lib.samp.events'

local memory = require 'memory'

local imgui = require 'imgui'

local bitex = require 'bitex'

local vkeys = require 'vkeys'

local GK = require 'game.keys'

local winmsg = require 'windows.message'

local encoding = require 'encoding'

keyAdminMenu = ""

local hotKeyAdminMenu = imgui.ImBuffer(keyAdminMenu, 256)

encoding.default = 'cp1251'

u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function imgui.OnDrawFrame()

  if main_window_state.v then

    imgui.SetNextWindowSize(imgui.ImVec2(150, 200), imgui.Cond.FirstUseEver)



    imgui.Begin('My window', main_window_state)



            imgui.AlignTextToFramePadding()

            if imgui.Hotkey(u8"Панель администратора", hotKeyAdminMenu, 80) then

      nextLockKey = hotKeyAdminMenu.v

      keyAdminMenu = hotKeyAdminMenu.v

end

    end

    imgui.End()

  end



function main()

  while true do

    wait(0)

    if wasKeyPressed(key.VK_X) then

        main_window_state.v = not main_window_state.v

    end

    imgui.Process = main_window_state.v

  end

    if not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive() and isPlayerPlaying(playerHandle) and editKeys == 0 then



   if isKeysDown(keyAdminmenu) then

           sampAddChatMessage("/amenu")

     end

end

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 or v == VK_RSHIFT) 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 and v ~= VK_RSHIFT) then

            if tostring(curkeys):len() == 0 then

                curkeys = v

            else

                curkeys = curkeys .. " " .. v

            end

            bool = true

        end

    end

    return curkeys, bool

end



function isKeysDown(keylist, pressed)

    local tKeys = string.split(keylist, " ")

    if pressed == nil then

        pressed = false

    end

    if tKeys[1] == nil then

        return false

    end

    local bool = false

    local key = #tKeys < 2 and tonumber(tKeys[1]) or tonumber(tKeys[2])

    local modified = tonumber(tKeys[1])

    if #tKeys < 2 then

        if not isKeyDown(VK_RMENU) and not isKeyDown(VK_LMENU) and not isKeyDown(VK_LSHIFT) and not isKeyDown(VK_RSHIFT) and not isKeyDown(VK_LCONTROL) and not isKeyDown(VK_RCONTROL) then

            if wasKeyPressed(key) and not pressed then

                bool = true

            elseif isKeyDown(key) and pressed then

                bool = true

            end

        end

    else

        if isKeyDown(modified) and not wasKeyReleased(modified) then

            if wasKeyPressed(key) and not pressed then

                bool = true

            elseif isKeyDown(key) and pressed then

                bool = true

            end

        end

    end

    if nextLockKey == keylist then

        if pressed and not wasKeyReleased(key) then

            bool = false

--            nextLockKey = ""

        else

            bool = false

            nextLockKey = ""

        end

    end

    return bool

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



local editHotkey = nil

function imgui.Hotkey(name, keyBuf, width)

    local name = tostring(name)

    local keys, endkey = getDownKeys()

    local keysName = ""

    local ImVec2 = imgui.ImVec2

    local bool = false

    if editHotkey == name then

        if keys == VK_BACK then

            keyBuf.v = ''

            editHotkey = nil

            nextLockKey = keys

            editKeys = 0

        else

            local tNames = string.split(keys, " ")

            local keylist = ""

            for _, v in ipairs(tNames) do

                local key = tostring(vkeys.id_to_name(tonumber(v)))

                if tostring(keylist):len() == 0 then

                    keylist = key

                else

                    keylist = keylist .. " + " .. key

                end

            end

            keysName = keylist

            if endkey then

                bool = true

                keyBuf.v = keys

                editHotkey = nil

                nextLockKey = keys

                editKeys = 0

            end

        end

    else

        local tNames = string.split(keyBuf.v, " ")

        for _, v in ipairs(tNames) do

            local key = tostring(vkeys.id_to_name(tonumber(v)))

            if tostring(keysName):len() == 0 then

                keysName = key

            else

                keysName = keysName .. " + " .. key

            end

        end

    end

    local style = imgui.GetStyle()

    local colors = style.Colors

    local clr = imgui.Col

    imgui.PushStyleColor(imgui.Col.Button, colors[clr.FrameBg])

    imgui.PushStyleColor(imgui.Col.ButtonActive, colors[clr.FrameBg])

    imgui.PushStyleColor(imgui.Col.ButtonHovered, colors[clr.FrameBg])

    imgui.PushStyleVar(imgui.StyleVar.ButtonTextAlign, ImVec2(0.04, 0.5))

    imgui.Button(u8((tostring(keysName):len() > 0 or editHotkey == name) and keysName or "Нет"), ImVec2(width, 20))

    imgui.PopStyleVar()

    imgui.PopStyleColor(3)

    if imgui.IsItemHovered() and imgui.IsItemClicked() and editHotkey == nil then

        editHotkey = name

        editKeys = 100

    end

    if name:len() > 0 then

        imgui.SameLine()

        imgui.Text(name)

    end

    return bool

end



function onWindowMessage(msg, wparam, lparam)

    if(msg == 0x100 or msg == 0x101) then

        if (wparam == VK_ESCAPE or wparam == VK_RETURN or wparam == VK_TAB or wparam == VK_F6 or wparam == VK_F7 or wparam == VK_F8 or wparam == VK_T or wparam == VK_OEM_3) and msg == 0x100 and editKeys > 0 then

            consumeWindowMessage(true, true)

            editHotkey = nil

       end

    end

end
 

AnWu

Известный
Автор темы
Всефорумный модератор
4,777
5,400
Хм... Добавил строку в код но ничего не меняется...
Lua:
local SE = require 'lib.samp.events'

local memory = require 'memory'

local imgui = require 'imgui'

local bitex = require 'bitex'

local vkeys = require 'vkeys'

local GK = require 'game.keys'

local winmsg = require 'windows.message'

local encoding = require 'encoding'

keyAdminMenu = ""

local hotKeyAdminMenu = imgui.ImBuffer(keyAdminMenu, 256)

encoding.default = 'cp1251'

u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function imgui.OnDrawFrame()

  if main_window_state.v then

    imgui.SetNextWindowSize(imgui.ImVec2(150, 200), imgui.Cond.FirstUseEver)



    imgui.Begin('My window', main_window_state)



            imgui.AlignTextToFramePadding()

            if imgui.Hotkey(u8"Панель администратора", hotKeyAdminMenu, 80) then

      nextLockKey = hotKeyAdminMenu.v

      keyAdminMenu = hotKeyAdminMenu.v

end

    end

    imgui.End()

  end



function main()

  while true do

    wait(0)

    if wasKeyPressed(key.VK_X) then

        main_window_state.v = not main_window_state.v

    end

    imgui.Process = main_window_state.v

  end

    if not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive() and isPlayerPlaying(playerHandle) and editKeys == 0 then



   if isKeysDown(keyAdminmenu) then

           sampAddChatMessage("/amenu")

     end

end

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 or v == VK_RSHIFT) 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 and v ~= VK_RSHIFT) then

            if tostring(curkeys):len() == 0 then

                curkeys = v

            else

                curkeys = curkeys .. " " .. v

            end

            bool = true

        end

    end

    return curkeys, bool

end



function isKeysDown(keylist, pressed)

    local tKeys = string.split(keylist, " ")

    if pressed == nil then

        pressed = false

    end

    if tKeys[1] == nil then

        return false

    end

    local bool = false

    local key = #tKeys < 2 and tonumber(tKeys[1]) or tonumber(tKeys[2])

    local modified = tonumber(tKeys[1])

    if #tKeys < 2 then

        if not isKeyDown(VK_RMENU) and not isKeyDown(VK_LMENU) and not isKeyDown(VK_LSHIFT) and not isKeyDown(VK_RSHIFT) and not isKeyDown(VK_LCONTROL) and not isKeyDown(VK_RCONTROL) then

            if wasKeyPressed(key) and not pressed then

                bool = true

            elseif isKeyDown(key) and pressed then

                bool = true

            end

        end

    else

        if isKeyDown(modified) and not wasKeyReleased(modified) then

            if wasKeyPressed(key) and not pressed then

                bool = true

            elseif isKeyDown(key) and pressed then

                bool = true

            end

        end

    end

    if nextLockKey == keylist then

        if pressed and not wasKeyReleased(key) then

            bool = false

--            nextLockKey = ""

        else

            bool = false

            nextLockKey = ""

        end

    end

    return bool

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



local editHotkey = nil

function imgui.Hotkey(name, keyBuf, width)

    local name = tostring(name)

    local keys, endkey = getDownKeys()

    local keysName = ""

    local ImVec2 = imgui.ImVec2

    local bool = false

    if editHotkey == name then

        if keys == VK_BACK then

            keyBuf.v = ''

            editHotkey = nil

            nextLockKey = keys

            editKeys = 0

        else

            local tNames = string.split(keys, " ")

            local keylist = ""

            for _, v in ipairs(tNames) do

                local key = tostring(vkeys.id_to_name(tonumber(v)))

                if tostring(keylist):len() == 0 then

                    keylist = key

                else

                    keylist = keylist .. " + " .. key

                end

            end

            keysName = keylist

            if endkey then

                bool = true

                keyBuf.v = keys

                editHotkey = nil

                nextLockKey = keys

                editKeys = 0

            end

        end

    else

        local tNames = string.split(keyBuf.v, " ")

        for _, v in ipairs(tNames) do

            local key = tostring(vkeys.id_to_name(tonumber(v)))

            if tostring(keysName):len() == 0 then

                keysName = key

            else

                keysName = keysName .. " + " .. key

            end

        end

    end

    local style = imgui.GetStyle()

    local colors = style.Colors

    local clr = imgui.Col

    imgui.PushStyleColor(imgui.Col.Button, colors[clr.FrameBg])

    imgui.PushStyleColor(imgui.Col.ButtonActive, colors[clr.FrameBg])

    imgui.PushStyleColor(imgui.Col.ButtonHovered, colors[clr.FrameBg])

    imgui.PushStyleVar(imgui.StyleVar.ButtonTextAlign, ImVec2(0.04, 0.5))

    imgui.Button(u8((tostring(keysName):len() > 0 or editHotkey == name) and keysName or "Нет"), ImVec2(width, 20))

    imgui.PopStyleVar()

    imgui.PopStyleColor(3)

    if imgui.IsItemHovered() and imgui.IsItemClicked() and editHotkey == nil then

        editHotkey = name

        editKeys = 100

    end

    if name:len() > 0 then

        imgui.SameLine()

        imgui.Text(name)

    end

    return bool

end



function onWindowMessage(msg, wparam, lparam)

    if(msg == 0x100 or msg == 0x101) then

        if (wparam == VK_ESCAPE or wparam == VK_RETURN or wparam == VK_TAB or wparam == VK_F6 or wparam == VK_F7 or wparam == VK_F8 or wparam == VK_T or wparam == VK_OEM_3) and msg == 0x100 and editKeys > 0 then

            consumeWindowMessage(true, true)

            editHotkey = nil

       end

    end

end
скрин краша го
 

vbg

Известный
41
17
заметил что скрипт запускается нормально но потом крашится сам.

Код:
[07:47:26.866936] (system)    Session started.
[07:47:26.869438] (debug)    Module handle: 074C0000

MoonLoader v.026.4-beta loaded.
Developers: FYP, hnnssy, EvgeN 1137

Copyright (c) 2016, BlastHack Team
https://www.blast.hk/moonloader/

[07:47:26.869438] (info)    Working directory: C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader
[07:47:26.869938] (debug)    FP Control: 0009001F
[07:47:26.869938] (debug)    Game: GTA SA 1.0.0.0 US
[07:47:26.869938] (system)    Installing pre-game hooks...
[07:47:26.880444] (system)    Hooks installed.
[07:47:28.290224] (debug)    Initializing opcode handler table
[07:47:28.290224] (debug)    package.path = C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\lib\?.lua;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\lib\?\init.lua;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\?.lua;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\?\init.lua;.\?.lua;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\lib\?.luac;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\lib\?\init.luac;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\?.luac;C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\?\init.luac;.\?.luac
[07:47:28.290224] (debug)    package.cpath = C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\lib\?.dll;
[07:47:28.293226] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\AutoReboot.lua'...
[07:47:28.293727] (debug)    New script: 0C24EDDC
[07:47:28.305733] (system)    ML-AutoReboot: Loaded successfully.
[07:47:28.305733] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\ChatHelper.lua'...
[07:47:28.305733] (debug)    New script: 0D7DFE74
[07:47:28.311737] (system)    ChatHelper: Loaded successfully.
[07:47:28.312237] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\check-moonloader-updates.lua'...
[07:47:28.312237] (debug)    New script: 0D7E07CC
[07:47:28.333752] (system)    Check MoonLoader Updates: Loaded successfully.
[07:47:28.333752] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\clickwarp.lua'...
[07:47:28.333752] (debug)    New script: 0D7E0954
[07:47:28.360767] (system)    Click Warp: Loaded successfully.
[07:47:28.360767] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\deddosouru c-bug (v4) (2).lua'...
[07:47:28.360767] (debug)    New script: 0D96EFB4
[07:47:28.371273] (system)    LEGAL C-BUG: Loaded successfully.
[07:47:28.371273] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\EzTeleport.lua'...
[07:47:28.371273] (debug)    New script: 0D972954
[07:47:28.498346] (system)    EzTeleport: Loaded successfully.
[07:47:28.498346] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\gdezakladka.lua'...
[07:47:28.498346] (debug)    New script: 0D975714
[07:47:28.502849] (system)    gdezakladka.lua: Loaded successfully.
[07:47:28.502849] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\hotkeytest.lua'...
[07:47:28.502849] (debug)    New script: 0D97589C
[07:47:28.556895] (system)    hotkeytest.lua: Loaded successfully.
[07:47:28.556895] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\reload_all.lua'...
[07:47:28.556895] (debug)    New script: 0D98A644
[07:47:28.561898] (system)    ML-ReloadAll: Loaded successfully.
[07:47:28.561898] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\scriptManager.lua'...
[07:47:28.561898] (debug)    New script: 0D98A7CC
[07:47:28.576907] (system)    ScriptManager: Loaded successfully.
[07:47:28.576907] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\SF Integration.lua'...
[07:47:28.576907] (debug)    New script: 0D98A954
[07:47:28.584411] (system)    SF Integration: Loaded successfully.
[07:47:28.584411] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\Skeletal WH (2).lua'...
[07:47:28.584411] (debug)    New script: 0D98AADC
[07:47:28.591415] (system)    Skeletal WallHack: Loaded successfully.
[07:47:28.591415] (system)    Loading script 'C:\Users\vbg\Desktop\[RP] GameWorld - GTA San Andreas\moonloader\TriggerBotByiTz_Weezy.lua'...
[07:47:28.591415] (debug)    New script: 0D98AC64
[07:47:28.597920] (system)    Trigger Bot: Loaded successfully.
[07:47:30.507031] (system)    Installing post-load hooks...
[07:47:30.507532] (system)    Hooks installed.
[07:47:30.594583] (error)    hotkeytest.lua: ...P] GameWorld - GTA San Andreas\moonloader\hotkeytest.lua:32: attempt to index global 'key' (a nil value)
stack traceback:
    ...P] GameWorld - GTA San Andreas\moonloader\hotkeytest.lua: in function <...P] GameWorld - GTA San Andreas\moonloader\hotkeytest.lua:29>
[07:47:30.594583] (error)    hotkeytest.lua: Script died due to an error. (0D97589C)

 

iXiW

Известный
29
16
Найди
Код:
if wasKeyPressed(key.VK_X) then

И замени на:
Код:
if wasKeyPressed(vkeys.VK_X) then

Будет работать.
 
  • Нравится
Реакции: vbg

f0rtrix

Известный
208
15
Привет, у меня тут такая ошибочка, мб что-то не то делаю?
[ML] (script) ML-AutoReboot: Loading "D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua"...
[ML] (system) Loading script 'D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua'...
[ML] (error) Helper: D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua:17: sol: no matching function call takes this number of arguments and the specified types
stack traceback:
[C]: in function 'ImBuffer'
D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua:17: in main chunk
[ML] (error) Government Helper v1.0: Script died due to an error. (15D8234C)
 

AnWu

Известный
Автор темы
Всефорумный модератор
4,777
5,400
Привет, у меня тут такая ошибочка, мб что-то не то делаю?
[ML] (script) ML-AutoReboot: Loading "D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua"...
[ML] (system) Loading script 'D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua'...
[ML] (error) Helper: D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua:17: sol: no matching function call takes this number of arguments and the specified types
stack traceback:
[C]: in function 'ImBuffer'
D:\Games\GTA_San_Andreas-0.2\moonloader\test.lua:17: in main chunk
[ML] (error) Government Helper v1.0: Script died due to an error. (15D8234C)
Тема уже довольна старая. Баги есть. Ошибка говорит что для ImBuffer нужно строковое значение.
Используй imgui.ImBuffer('', 256)
или переменную заверни в tostring().
Фишка этой темы была повыебываться, но надо это в либу превратить, а мне некогда.
 

f0rtrix

Известный
208
15
Понятно, просто хочу свой конструктор собрать, а туда хочу впихнуть Биндер, может есть где-то подобные темы?
 

kamazingg

Известный
12
1
Привет, впилил imgui.hotkey к себе в скрипт, но получается такая проблема:

RSHIFT (и некоторые другие клавиши) можно юзать только в комбинации, можно ли как-то это поправить?
 

AnWu

Известный
Автор темы
Всефорумный модератор
4,777
5,400
Привет, впилил imgui.hotkey к себе в скрипт, но получается такая проблема:

RSHIFT (и некоторые другие клавиши) можно юзать только в комбинации, можно ли как-то это поправить?
нет. будут ложные срабатывания если есть комбинации
 
Статус
В этой теме нельзя размещать новые ответы.