Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// All made by Sten :)
- --// Services
- local UserInputService = game:GetService("UserInputService")
- --// Blocks inputs that will break the input system if enabled
- local blocked_input = {
- Enum.UserInputType.MouseMovement,
- Enum.UserInputType.Focus,
- }
- --// Combines multiple arrays into one Array
- local function CombineArray(...)
- local table = {}
- for _, array in next, {...} do
- for i, v in next, array do
- table[i] = v
- end
- end
- return table
- end
- --// Module
- local keybinds = {} do
- keybinds.keys_down = {}
- keybinds.keybinded = {}
- --// Keybind remover
- function keybinds.AddKeybind(_keycodes, _callback, _args, _settings)
- local bind = {}
- _args = _args or {}
- _settings = _settings or {}
- function bind.Remove()
- keybinds.keybinded[bind.index] = nil
- end
- bind.index = #keybinds.keybinded + 1
- bind.settgins = _settings
- bind.keycodes = _keycodes
- bind.callback = _callback
- bind.args = _args
- keybinds.keybinded[bind.index] = {
- _keycodes,
- _callback,
- _args,
- _settings
- }
- return bind
- end
- --// Activates on input
- function Input(_bool, _input, _processedevent)
- local current_key = (_input.UserInputType == Enum.UserInputType.Keyboard and _input.KeyCode) or (not table.find(blocked_input, _input.UserInputType) and _input.UserInputType) or nil
- if _processedevent or current_key == nil then
- return
- end
- current_key = tostring(current_key):split(".")[3]
- keybinds.keys_down[current_key] = _bool
- if #keybinds.keybinded == 0 then
- return
- end
- for _, bind in next, keybinds.keybinded do
- local can_activate = true
- for key, value in next, keybinds.keys_down do
- if (value == true and bind[4].singular and not table.find(bind[1], key)) or (value == false and table.find(bind[1], key)) then
- can_activate = false
- break
- end
- end
- if not can_activate or not table.find(bind[1], current_key) then
- continue
- end
- --// Activates callback
- task.spawn(bind[2], unpack(bind[3]))
- end
- end
- UserInputService.InputBegan:Connect(function(_input, _processedevent)
- Input(true, _input, _processedevent)
- end)
- UserInputService.InputEnded:Connect(function(_input, _processedevent)
- Input(false, _input, _processedevent)
- end)
- do -- Setup
- local inputs = CombineArray(Enum.KeyCode:GetEnumItems(), Enum.UserInputType:GetEnumItems())
- for _, key in next, inputs do
- key = tostring(key):split(".")[3]
- keybinds.keys_down[key] = false
- end
- end
- end
- return keybinds
Add Comment
Please, Sign In to add comment