Проблема с rkeys.lua

keinvg4352

Новичок
Автор темы
5
0
Hey guys

I have no idea myself, but I've tried so far that if I want to use Gamefixer and SAMP Squad Binder together, then it doesn't work because of rkeys.lua, apparently they're different

Is there a way to combine them so that both mods work?

Squad Binder:

rkeys squad binder:
--[[
   Author: DonHomka
   [Functions]
      HotKeys:
      # registerHotKey(table keycombo, int activationType, [bool blockInput = false], function callback)
Registers a new hotkey. You can omit the input lock option. Returns the ID of the new hotkey
      # unRegisterHotKey(int id)
Deletes hotkey by ID
      # unRegisterHotKey(table keycombo)
Removes the hotkey by keyboard shortcut. Returns the result of the deletion and the number of hotkeys removed.
      # isHotKeyDefined(ind id)
Checks for the existence of certain key IDs.
      # isHotKeyDefined(table keycombo)
Checks for the existence of a hotkey with a given combination
      # getHotKey(int id)
Returns hotkey data from the tHotKeys table by ID. The first parameter returned is the search result.
      # getHotKey(table keycombo)
Returns hotkey data from the tHotKeys table by key combination. The first parameter returned is the search result.

      Other:
      # isKeyExist(int keyid, [table keylist = tCurKeys])
Checks for the existence of a specific key in the list. By default, a list of currently pressed keys is taken.
      # isKeyComboExist(talbe keycombo, [table keylist = tCurKeys])
Checks for the existence of a key combination in the list
      # getKeyPosition(int keyid, [table keylist = tCurKeys])
Returns the position of the key in the list. If there is no key, it will return nil
      # getExtendedKeys(int keyid, int scancode, int keyex)
Returns an extended version of modifiers or nil
      # getKeys([bool showKeyName = false])
Returns a table of the currently pressed keys. The argument specifies whether the key name should be returned.

      tHotKeys data:
- keys - keys for hotkey
- aType - hotkey type:
1 - triggered by pressing a key
2 - triggers when pressed and as long as the key is held down
3 - triggers when you press the last (!) key in a combo (Alt + Shift + R - will work if you hold the combination and release R)
- isBlock - whether you need to block input for the last(!) combo key. Doesn't work for aType = 3.
- callback - callback function for triggering the key
- id - a unique hotkey identifier (not a position in tHotKeys, but a unique identifier). This ID is used to search for keys.

   E-mail: idonhomka@gmail.com
   VK: http://vk.com/DonHomka
   TeleGramm: http://t.me/iDonHomka
   Discord: DonHomka#2534
]]
local vkeys = require 'vkeys'
local wm = require 'windows.message'
local bitex = require 'bitex'
local ffi = require 'ffi'

local tCurKeys = {}
local tModKeys = { [vkeys. VK_MENU] = true, [vkeys. VK_SHIFT] = true, [vkeys. VK_CONTROL] = true }
local tModKeysList = { vkeys. VK_MENU, vkeys. VK_LMENU, vkeys. VK_RMENU, vkeys. VK_SHIFT, vkeys. VK_RSHIFT, vkeys. VK_LSHIFT, vkeys. VK_CONTROL, vkeys. VK_LCONTROL, vkeys. VK_RCONTROL }
local tMessageTrigger = {
[wm. WM_KEYDOWN] = true,
[wm. WM_SYSKEYDOWN] = true,
[wm. WM_KEYUP] = true,
[wm. WM_SYSKEYUP] = true,
[wm. WM_LBUTTONDOWN] = true,
[wm. WM_LBUTTONDBLCLK] = true,
[wm. WM_LBUTTONUP] = true,
[wm. WM_RBUTTONDOWN] = true,
[wm. WM_RBUTTONDBLCLK] = true,
[wm. WM_RBUTTONUP] = true,
[wm. WM_MBUTTONDOWN] = true,
[wm. WM_MBUTTONDBLCLK] = true,
[wm. WM_MBUTTONUP] = true,
[wm. WM_XBUTTONDOWN] = true,
[wm. WM_XBUTTONDBLCLK] = true,
[wm. WM_XBUTTONUP] = true,
[wm. WM_MOUSEWHEEL] = true
                     }
local tRewriteMouseKeys = {
[wm. WM_LBUTTONDOWN] = vkeys. VK_LBUTTON,
[wm. WM_LBUTTONUP] = vkeys. VK_LBUTTON,
[wm. WM_RBUTTONDOWN] = vkeys. VK_RBUTTON,
[wm. WM_RBUTTONUP] = vkeys. VK_RBUTTON,
[wm. WM_MBUTTONDOWN] = vkeys. VK_MBUTTON,
[wm. WM_MBUTTONUP] = vkeys. VK_MBUTTON,
                        }
local tXButtonMessage = {
[wm. WM_XBUTTONUP] = true,
[wm. WM_XBUTTONDOWN] = true,
[wm. WM_XBUTTONDBLCLK] = true,
                        }
local tXButtonMouseData = {
vkeys. VK_XBUTTON1,
vkeys. VK_XBUTTON2
                        }
local tDownMessages = {
[wm. WM_KEYDOWN] = true,
[wm. WM_SYSKEYDOWN] = true,
[wm. WM_LBUTTONDOWN] = true,
[wm. WM_RBUTTONDOWN] = true,
[wm. WM_MBUTTONDOWN] = true,
[wm. WM_XBUTTONDOWN] = true,
[wm. WM_LBUTTONDBLCLK] = true,
[wm. WM_RBUTTONDBLCLK] = true,
[wm. WM_MBUTTONDBLCLK] = true,
[wm. WM_XBUTTONDBLCLK] = true,
[wm. WM_MOUSEWHEEL] = true
                     }
local tHotKeys = {}
local tActKeys = {}
local hkId = 0
local mod = {}
--- Current version of the module
mod._VERSION = "2.1.1"
--- List of modifier keys, including advanced versions
mod._MODKEYS = tModKeysList
--- Определяет нужно ли блокировать нажатия для окна при нажатии любого зарегистрированного сочетания
mod._LOCKKEYS = false
--- Псевдо-клавиши для WM_MOUSEWHEEL
mod.vkeys = {
   VK_WHEELDOWN = 0x100,
   VK_WHEELUP = 0x101
}
--- Названия псевдо-клавиш
mod.vkeys.names = {
   [mod.vkeys.VK_WHEELDOWN] = "Mouse Wheel Down",
   [mod.vkeys.VK_WHEELUP] = "Mouse Wheel Up",
}

local id_to_name = function(id)
   local name = vkeys.id_to_name(id) or mod.vkeys.names[id]
   return name
end
local HIWORD = function(param)
    return bit.rshift(bit.band(param, 0xffff0000), 16);
end
local splitsigned = function(n) -- СПАСИБО WINAPI.lua и GITHUB и Chat mimgui
    n = tonumber(n)
    local x, y = bit.band(n, 0xffff), bit.rshift(n, 16)
    if x >= 0x8000 then x = x-0xffff end
    if y >= 0x8000 then y = y-0xffff end
    return x, y
end

addEventHandler("onWindowMessage", function (message, wparam, lparam)
   if tMessageTrigger[message] then
      local scancode = bitex.bextract(lparam, 16, 8)
      local keystate = bitex.bextract(lparam, 30, 1)
      local keyex = bitex.bextract(lparam, 24, 1)
      if tXButtonMessage[message] then
         local btn = HIWORD(wparam)
         wparam = tXButtonMouseData[btn]
      elseif message == wm.WM_MOUSEWHEEL then
         local btn, delta = splitsigned(ffi.cast('int32_t', wparam))
         if delta < 0 then
            wparam = mod.vkeys.VK_WHEELDOWN
         elseif delta > 0 then
            wparam = mod.vkeys.VK_WHEELUP
         end
      elseif tRewriteMouseKeys[message] then
         wparam = tRewriteMouseKeys[message]
      end
      local keydown = mod.isKeyExist(wparam)
      if tDownMessages[message] then
         if not keydown and keystate == 0 then
            table.insert(tCurKeys, wparam)
            if tModKeys[wparam] then
               local exKey = mod.getExtendedKeys(wparam, scancode, keyex)
               if exKey then
                  table.insert(tCurKeys, exKey)
               end
            end
         end
         for k, v in ipairs(tHotKeys) do
            if v.aType ~= 3 and (tActKeys[v.id] == nil or v.aType == 2)
               and ((v.aType == 1 and keystate == 0) or v.aType == 2)
               and mod.isKeyComboExist(v.keys)
               and (not mod.isKeysExist(tModKeysList, v.keys) and not mod.isKeysExist(tModKeysList) or mod.isKeysExist(tModKeysList, v.keys))
               and (mod.onHotKey == nil or (mod.onHotKey and mod.onHotKey(v.id, v) ~= false))
            then
               lua_thread.create(function()
                  wait(0)
                  v.callback(v)
               end)
               tActKeys[v.id] = true
            end
            if v.isBlock and (tActKeys[v.id] or v.aType == 2) or (tActKeys[v.id] and not v.isBlock and mod._LOCKKEYS) then
               consumeWindowMessage()
            end
         end
      else
         for k, v in ipairs(tHotKeys) do
            if v.aType == 3 and keystate == 1 and mod.isKeyComboExist(v.keys)
               and (mod.onHotKey == nil or (mod.onHotKey and mod.onHotKey(v.id, v) ~= false))
               then
               v.callback(v)
            end
         end
         if keydown then
            local pos = mod.getKeyPosition(wparam)
            table.remove(tCurKeys, pos)
            if tModKeys[wparam] then
               local exKey = mod.getExtendedKeys(wparam, scancode, keyex)
               if exKey then
                  pos = mod.getKeyPosition(exKey)
                  table.remove(tCurKeys, pos)
               end
            end
         end
      end
if message == wm. WM_MOUSEWHEEL then
         local pos = mod.getKeyPosition(wparam)
         table.remove(tCurKeys, pos)
      end
      for k, v in ipairs(tHotKeys) do
         if v.aType == 2 or tActKeys[v.id] and not mod.isKeyComboExist(v.keys) then
            tActKeys[v.id] = nil
         end
      end
elseif message == wm. WM_KILLFOCUS then
      tCurKeys = {}
   end
end)

--- Registers a new keyboard shortcut. The isBlock parameter can be omitted
---@param keycombo table
---@param activationType integer
---@param isBlock_or_callback boolean|function
---@param callback function
---@return integer
function mod.registerHotKey(keycombo, activationType, isBlock_or_callback, callback)
   local newId = hkId + 1
   tHotKeys[#tHotKeys + 1] = {
      keys = keycombo,
      aType = activationType,
      callback = type(isBlock_or_callback) == "function" and isBlock_or_callback or callback,
      id = newId,
      isBlock = type(isBlock_or_callback) == "boolean" and isBlock_or_callback or false
   }
   hkId = hkId + 1
   return newId
end

--- Checks if the specified combo exists. The first parameter returns the result of the check, the second is the number of combos found.
---@param keycombo_or_id table|integer
---@return boolean,integer
function mod.isHotKeyDefined(keycombo_or_id)
   local bool = false
   local count = 0
   if type(keycombo_or_id) == "number" then
      for k, v in ipairs(tHotKeys) do
         if v.id == keycombo_or_id then
            bool = true
            count = count + 1
         end
      end
   elseif type(keycombo_or_id) == "table" then
      for k, v in ipairs(tHotKeys) do
         if mod.compareKeys(v.keys, keycombo_or_id) then
            bool = true
            count = count + 1
         end
      end
   end
   return bool, count
end

--- Returns hotkey data by ID or combo keys. Returns a search result and a data table.
---@param keycombo_or_id table|integer
---@return boolean,table
function mod.getHotKey(keycombo_or_id)
   local bool = false
   local data = {}
   if type(keycombo_or_id) == "number" then
      for k, v in ipairs(tHotKeys) do
         if v.id == keycombo_or_id then
            bool = true
            data = v
            break
         end
      end
   elseif type(keycombo_or_id) == "table" then
      for k, v in ipairs(tHotKeys) do
         if mod.compareKeys(v.keys, keycombo_or_id) then
            bool = true
            data = v
            break
         end
      end
   end
   return bool, data
end

---Changes the key combo for the hotkey. Returns the result of the change.
---@param id integer
---@param keycombo table
---@return boolean
function mod.changeHotKey(id, keycombo)
   local bool = false
   for k, v in ipairs(tHotKeys) do
      if v.id == id then
         bool = true
         v.keys = keycombo
      end
   end
   return bool
end

--- Removes combos. The first parameter returns the result of the deletion, the second parameter returns the number of deleted combos.
---@param keycombo_or_id table|integer
---@return boolean,integer
function mod.unRegisterHotKey(keycombo_or_id)
   local bool = false
   local count = 0
   local idsToRemove = {}
   if type(keycombo_or_id) == "number" then
      for k, v in ipairs(tHotKeys) do
         if v.id == keycombo_or_id then
            bool = true
            count = count + 1
            table.insert(idsToRemove, k)
         end
      end
   elseif type(keycombo_or_id) == "table" then
      for k, v in ipairs(tHotKeys) do
         if mod.compareKeys(v.keys, keycombo_or_id) then
            bool = true
            count = count + 1
            table.insert(idsToRemove, k)
         end
      end
   end
   for k, v in ipairs(idsToRemove) do
      table.remove(tHotKeys, v)
   end
   return bool, count
end

--- Checks if the keycombo hotkey is active in the keylist. If the keylist is omitted, it uses the currently pressed keys.
---@param keycombo table
---@param keylist table
---@return boolean
function mod.isKeyComboExist(keycombo, keylist)
   keylist = keylist or tCurKeys
   local b = false
   local i = 1
   for k, v in ipairs(keylist) do
      if v == keycombo[i] then
         if i == #keycombo then
            b = true
            break
         end
         i = i + 1
      end
   end
   return b
end

--- Compares two combos
---@param keycombo table
---@param keycombotwo table
---@return boolean
function mod.compareKeys(keycombo, keycombotwo)
   local b = true
   for k, v in ipairs(keycombo) do
      if keycombotwo[k] ~= v then
         b = false
         break
      end
   end
   return b
end

--- Looks for the keyid in the keylist. Unlike isKeyComboExist, it does not look for multiple keys, but only one with a specified date.
---@param keyid integer
---@param keylist table
---@return boolean
function mod.isKeyExist(keyid, keylist)
   keylist = keylist or tCurKeys
   for k, v in ipairs(keylist) do
      if tonumber(v) == tonumber(keyid) then
         return true
      end
   end
   return false
end

--- Looks for multiple ids from the list of keyids in the keylist. Returns true if at least one id of the keyids is found
---@param keyids table
---@param keylist table
---@return boolean
function mod.isKeysExist(keyids, keylist)
   keylist = keylist or tCurKeys
   for k, v in ipairs(keyids) do
      for kk, vv in ipairs(keylist) do
         if v == vv then
            return true
         end
      end
   end
   return false
end

--- Analogous to isKeyExist, but returns the position in the keylist if it finds it.
---@param keyid integer
---@param keylist table
---@return integer|nil
function mod.getKeyPosition(keyid, keylist)
   keylist = keylist or tCurKeys
   for k, v in ipairs(keylist) do
      if v == keyid then
         return k
      end
   end
   return nil
end

--- Gets advanced versions of Alt, Shift, Ctrl based on scancode and extension.
---@param keyid integer
---@param scancode integer
---@param extend integer
---@return integer|nil
function mod.getExtendedKeys(keyid, scancode, extend)
   local newKeyId = nil
if keyid == vkeys. VK_MENU then
      if extend == 1 then
newKeyId = vkeys. VK_RMENU
      else
newKeyId = vkeys. VK_LMENU
      end
elseif keyid == vkeys. VK_SHIFT then
      if scancode == 42 then
newKeyId = vkeys. VK_LSHIFT
      elseif scancode == 54 then
newKeyId = vkeys. VK_RSHIFT
      end
elseif keyid == vkeys. VK_CONTROL then
      if extend == 1 then
newKeyId = vkeys. VK_RCONTROL
      else
newKeyId = vkeys. VK_LCONTROL
      end
   end
   return newKeyId
end

--- Returns a list of the currently pressed keys in script format. As an argument, it takes what data needs to be displayed. ID only, do you need a key name
---@param keyname boolean
---@param keyscan boolean
---@param keyex boolean
---@return table
function mod.getKeys(keyname, keyscan, keyex)
   keyname = keyname or false
   local szKeys = {}
   for k, v in ipairs(tCurKeys) do
      table.insert(szKeys, ("%s%s"):format(tostring(v), (keyname and ":" .. id_to_name(v) or "")))
   end
   return szKeys
end

--- Returns the number of keys pressed
---@return integer
function mod.getCountKeys()
   return #tCurKeys
end

return mod

rkeys gamefixer:
--[[
   Register HotKey for MoonLoader
   Author: DonHomka
   Functions:
      - int id = registerHotKey(table keys, bool pressed, function callback)
      - unRegisterHotKey:
         > bool result, int count = unRegisterHotKey(table keys)
         > bool result = unRegisterHotKey(int id)
      - isHotKeyDefined:
         > bool result, int id = isHotKeyDefined(table keys)
         > bool result, table keys = isHotKeyDefined(int id)
      - table keys, bool end = getCurrentHotKey(bool show_name_keys)
      - table keys = getAllHotKey()
   HotKey data:
      - table keys                  Return table keys for active hotkey
      - bool pressed                True - wasKeyPressed() / False - isKeyDown()
      - function callback           Call this function on active hotkey
   E-mail: a.skinfy@gmail.com
   VK: http://vk.com/DonHomka
   TeleGramm: http://t.me/DonHomka
   Discord: DonHomka#2534

   Last update:
      #1.1.0:
      - Fixed bug isHotKeyHotKey
      - Deleted block-functions
]]
local vkeys = require 'vkeys'

vkeys.key_names[vkeys.VK_LMENU] = "LAlt"
vkeys.key_names[vkeys.VK_RMENU] = "RAlt"
vkeys.key_names[vkeys.VK_LSHIFT] = "LShift"
vkeys.key_names[vkeys.VK_RSHIFT] = "RShift"
vkeys.key_names[vkeys.VK_LCONTROL] = "LCtrl"
vkeys.key_names[vkeys.VK_RCONTROL] = "RCtrl"

local tHotKey = {}
local tKeyList = {}
local tKeysCheck = {}
local iCountCheck = 0
local tBlockKeys = {[vkeys.VK_LMENU] = true, [vkeys.VK_RMENU] = true, [vkeys.VK_RSHIFT] = true, [vkeys.VK_LSHIFT] = true, [vkeys.VK_LCONTROL] = true, [vkeys.VK_RCONTROL] = true}
local tModKeys = {[vkeys.VK_MENU] = true, [vkeys.VK_SHIFT] = true, [vkeys.VK_CONTROL] = true}
local tBlockNext = {}
local module = {}
module._VERSION = "1.1.0"
module._MODKEYS = tModKeys
module._LOCKKEYS = false

local function getKeyNum(id)
   for k, v in pairs(tKeyList) do
      if v == id then
         return k
      end
   end
   return 0
end

function module.isHotKeyHotKey(keys, keys2)
   if type(keys) ~= "table" then
      print("[RKeys | isHotKeyHotKey]: Bad argument #1. Value \"", tostring(keys), "\" is not table.")
      return false
   elseif type(keys2) ~= "table" then
      print("[RKeys | isHotKeyHotKey]: Bad argument #2. Value \"", tostring(keys2), "\" is not table.")
      return false
   else
      return table.concat(keys, " ") == table.concat(keys2, " ")
   end
end

function module.isKeyModified(id)
   if type(id) ~= "number" then
      print("[RKeys | isKeyModified]: Bad argument #1. Value \"", tostring(id), "\" is not number.")
      return false
   end
   return (tModKeys[id] or false) or (tBlockKeys[id] or false)
end

function module.isModifiedDown()
   local bool = false
   for k, v in pairs(tModKeys) do
      if isKeyDown(k) then
         bool = true
         break
      end
   end
   return bool
end

lua_thread.create(function ()
   while true do
      wait(0)
      local tDownKeys = module.getCurrentHotKey()
      for k, v in pairs(tHotKey) do
         if #v.keys > 0 then
            local bool = true
            for i = 1, #v.keys do
               if i ~= #v.keys and (getKeyNum(v.keys[i]) > getKeyNum(v.keys[i + 1]) or getKeyNum(v.keys[i]) == 0) then
                  bool = false
                  break
               elseif i == #v.keys and (v.pressed and not wasKeyPressed(v.keys[i]) or not v.pressed and not isKeyDown(v.keys[i])) or (#v.keys == 1 and module.isModifiedDown()) then
                  bool = false
                  break
               end
            end
            if bool and ((module.onHotKey and module.onHotKey(k, v.keys) ~= false) or module.onHotKey == nil) then
               v.callback(k, v.keys)
            end
         end
      end
   end
end)

function module.registerHotKey(keys, pressed, callback)
   tHotKey[#tHotKey + 1] = {keys = keys, pressed = pressed, callback = callback}
   return #tHotKey
end

function module.getAllHotKey()
   return tHotKey
end

function module.changeHotKey(id, newkeys)
   if type(id) ~= "number" then
      print("[RKeys | changeHotKey]: Bad argument #1. Value \"", tostring(keys), "\" is not number.")
      return false
   elseif type(newkeys) ~= "table" then
      print("[RKeys | changeHotKey]: Bad argument #2. Value \"", tostring(newkeys), "\" is not table.")
      return false
   else
      local bool = false
      if module.isHotKeyDefined(id) then
         tHotKey[id].keys = newkeys
         bool = true
      end
      return bool
   end
end

function module.unRegisterHotKey(keys_or_id)
   local result = false
   local count = 0
   if type(keys_or_id) == "number" and tHotKey[keys_or_id] then
      tHotKey[keys_or_id] = nil
      result = true
      count = nil
   elseif type(keys_or_id) == "table" then
      while module.isHotKeyDefined(keys_or_id) do
         local _, id = module.isHotKeyDefined(keys_or_id)
         tHotKey[id] = nil
         result = true
         count = count + 1
      end
      local id = 1
      local tNewHotKey = {}
      for k, v in pairs(tHotKey) do
         tNewHotKey[id] = v
         id = id + 1
      end
      tHotKey = tNewHotKey
   else
      print("[RKeys | unRegisterHotKey]: Bad argument #1. Value \"", tostring(keys_or_id), "\" is not number or table.")
      return false, -1
   end
   return result, count
end

function module.isHotKeyDefined(keys_or_id)
   if type(keys_or_id) == "number" and tHotKey[keys_or_id] then
      return true, tHotKey[keys_or_id].keys
   elseif type(keys_or_id) == "table" then
      local bool, hkId = false, -1
      for k, v in pairs(tHotKey) do
         if module.isHotKeyHotKey(keys_or_id, v.keys) then
            bool = true
            hkId = k
            break
         end
      end
      return bool, hkId
   else
      print("[RKeys | isHotKeyDefined]: Bad argument #1. Value \"", tostring(keys_or_id), "\" is not number or table.")
      return false, -1
   end
   return false, -1
end

function module.getKeysName(keys)
   if type(keys) ~= "table" then
      print("[RKeys | getKeysName]: Bad argument #1. Value \"", tostring(keys), "\" is not table.")
      return false
   else
      local tKeysName = {}
      for k, v in ipairs(keys) do
         tKeysName[k] = vkeys.id_to_name(v)
      end
      return tKeysName
   end
end

function module.getCurrentHotKey(show_name_keys)
   local show_name_keys = show_name_keys or false
   local tCurKeys = {}
   for k, v in pairs(vkeys) do
      if tBlockKeys[v] == nil then
         local num, down = getKeyNum(v), isKeyDown(v)
         if down and num == 0 then
            tKeyList[#tKeyList + 1] = v
         elseif num > 0 and not down then
            tKeyList[num] = nil
         end
      end
   end
   local i = 1
   for k, v in pairs(tKeyList) do
      tCurKeys[i] = show_name_keys == false and v or vkeys.id_to_name(v)
      i = i + 1
   end
   return tCurKeys, #tKeyList > 0 and not module.isKeyModified(tKeyList[#tKeyList]) or false
end

return module