Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --hotkeys
- hk_hotkeys = {}
- hk_toggle = true
- function hk_register(key, command, env, ...)
- if hk_hotkeys[key] == nil then
- local args = { ... }
- hk_hotkeys[key] = {command, env, args}
- return true
- else
- return false, hk_hotkeys[key]
- end
- end
- function hk_unregister(key)
- if hk_hotkeys[key] == nil then
- return false
- else
- local command = hk_hotkeys[key]
- hk_hotkeys[key] = nil
- return true, command
- end
- end
- function hk_hotkey(key)
- local command = hk_hotkeys[key]
- if command == nil then
- return false
- else
- if toggle then
- local com = command[1]
- local env = command[2]
- if env == nil then env = {} end
- os.run(env, com, unpack(command[3]))
- return true
- else
- return false
- end
- end
- end
- function hk_save()
- --SAVE HOTKEYS
- end
- function hk_load()
- --LOAD HOTKEYS
- end
- local old_pullEventRaw = os.pullEventRaw
- function new_pullEventRaw( _sFilter )
- local event, p1, p2, p3, p4, p5 = os.coroutine.yield(_sFilter)
- if event == "key" then
- hk_hotkey(p1)
- end
- return event,p1,p2,p3,p4,p5
- end
- function hk_off()
- os.pullEventRaw = old_pullEventRaw
- end
- function hk_on()
- os.pullEventRaw = new_pullEventRaw
- end
- local comArgs = {...}
- local command = comArgs[1]
- if command == "register" or command == "r" then
- if #comArgs > 2 then
- local key = comArgs[2]
- local com = comArgs[3]
- local suc, result = hk_register(key, com)
- if suc then
- print("Registered key '"..key.."' with command '"..com.."'")
- else
- print("Key '"..key.."' is already registered with command '"..result.."'")
- end
- else
- print("Not enough arguments")
- end
- elseif command == "unregister" or command == "u" then
- if #comArgs > 1 then
- local key = comArgs[2]
- local suc, result = hk_unregister(key)
- if suc then
- print("Unregistered key '"..key.."' from command '"..result.."'")
- else
- print("Key '"..key.."' isn't registered!")
- end
- else
- print("Not enough arguments")
- end
- elseif command == "hotkey" or command == "h" then
- if #comArgs > 1 then
- local key = comArgs[2]
- local suc = hk_register(key)
- if suc then
- print("Ran hotkey '"..key.."'")
- else
- print("Not hotkey exists for key '"..key.."' or hotkeys are toggled off!")
- end
- else
- print("Not enough arguments")
- end
- elseif command == "toggle" or command == "t" then
- if hk_toggle == true then
- hk_toggle = false
- print("HotKeys toggled OFF")
- else
- hk_toggle = true
- print("HotKeys toggled ON")
- end
- elseif command == "off" then
- hk_off()
- elseif command == "on" then
- hk_on()
- elseif command == "help" or command == "h" then
- if comArgs[2] == nil then
- print("HotKey Commands;")
- print(" toggle | t = toggle hotkeys on/off")
- print(" register | r = register a new hotkey")
- print(" unregister | u = unregister a hotkey")
- print(" hotkey | h = run a hotkey")
- print(" off = turn hotkeys off (safe mode)")
- print(" on = turn hotkeys on")
- else
- local ch = comArgs[2]
- if command == "register" or command == "r" then
- print("HotKey Commands;")
- print(" Help: hotkeys register KEY COMMAND")
- elseif command == "unregister" or command == "u" then
- print("HotKey Commands;")
- print(" Help: hotkeys unregister KEY")
- elseif command == "hotkey" or command == "h" then
- print("HotKey Commands;")
- print(" Help: hotkeys hotkey KEY")
- elseif command == "toggle" or command == "t" then
- print("HotKey Commands;")
- print(" Help: toggles hotkeys on/off (basic)")
- elseif command == "on" then
- print("HotKey Commands;")
- print(" Help: turns hotkeys on (safe mode off)")
- elseif command == "off" then
- print("HotKey Commands;")
- print(" Help: turns hotkeys off (safe mode on)")
- else
- print("Help: Invalid command")
- end
- end
- else
- print("Invalid Command, try 'hotkeys help'")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement