ShortcutService - Easily create contextual keyboard shortcuts

I’ve recently noticed a rather strange hole within the Roblox community, despite so many plugins and games having shortcuts, there is no resource (that I found) to enable creation of them. While this would be incredibly helpful as an engine feature (perhaps one that builds off of ContextActionService), until that time comes, I present my solution:

ShortcutService

ShortcutService is a small, easy-to-use custom service that follows in ContextActionService’s footsteps, enabling the creation of contextual keyboard shortcuts.

Usage Example:

local ShortcutService = require(script.ShortcutService)

ShortcutService:Bind(
    "Print Hi",
    function()
        print("Hi!")
    end,
    Enum.KeyCode.LeftControl,Enum.KeyCode.M
)


ShortcutService:Activate()
Above is one of many ways to bind a shortcut (but is also the simplest)

You can also do the following:

local ShortcutService = require(script.ShortcutService)

ShortcutService:CreateShortcut("Print Hi",Enum.KeyCode.LeftControl,Enum.KeyCode.M)
ShortcutService:BindShortcutHandler("Print Hi",function()
	print("Hi!")
end)
ShortcutService:ActivateShortcut("Print Hi")

ShortcutService:Activate()

Or

local ShortcutService = require(script.ShortcutService)

ShortcutService:CreateShortcut("Print Hi",Enum.KeyCode.LeftControl,Enum.KeyCode.M)
ShortcutService:BindShortcut("Print Hi",function()
	print("Hi!")
end)

ShortcutService:Activate()

Now, some notes:

  • It requires that only the keys within the shortcut to be active in order to trigger
  • It does not support multiple shortcuts for the same action, but this functionality can be achieved by binding multiple shortcuts to the same function
  • It does not have a begin, change, end state like ContextActionService does
  • It does not prevent default shortcuts from occurring
  • No wiki is available (currently), I hope that the function descriptions can guide you well enough, but if you have questions, don’t be afraid to ask

With that said, I hope this helps! If you think you can make it better (you probably can), send a pull request on the github!

1 Like

really cool! i’ll try it out and give feedback.

1 Like