RoKeys, easy Keybinding in Roblox

RoKeysIconFullTransparent RoKeysTitleWhite

(this page is recommended to be veiwed in dark mode)

RoKeys is an Open-source Keybinding script for Roblox that strives for usability and versatility

I created RoKeys because I saw a lot of people (like me) who had just begun scripting and wanted to know how to make a keybinding script. I saw a chance to help people get started with their projects without the hassle of having to make some convoluted UserInputService blob.

RoKeys can be downloaded from the Roblox Marketplace or GitHub, and has extensive documentation both here and on the GitHub page.

Rokeys 2.0 comes with the following features:

  • New function for clearing keybinds
  • New and Remove functions return two tables, one for binds and another for inputs
  • Inputs and Binds can be paused now
  • Removed values being passed that were unused
  • Implemented Began and Ended events for Binds/Inputs
  • Changed Function names to be more in line with Roblox’s naming schemes and to be more descriptive
  • Now using Dictionaries for adding and removing Binds/Inputs
  • Restructured how data is stored
  • You can now define the starting Value of Binds/Inputs when creating them
  • Complete rewrite

It can be downloaded from these two links:

Installation

To Install all you need to do is download the latest version from the Releases Page.

The file to look for will look something like this: RoKeys.lua

if using an older version: the documentation can be found in the source files on the download page

Once you’ve downloaded the file to your prefered destination all you have to do is make a Roblox project

Then (assuming you know how to make a new project), in Roblox Studio navigate to the View tab as seen at the top of the window.

Screenshot_20220716_235308

And enable the Explorer


In the Explorer navigate to a service called ReplicatedStorage and Right Click it to bring up a menu,

in that menu look for the option: Insert from File

Screenshot_20220716_235814
Screenshot_20220717_000404

From there all you have to do is look for the file you downloaded and open it.

Basic Use

Once installed you can now use RoKeys, except with one extra step.

First you must make a script (this script can be placed anywhere)

Inside that script paste the following code:

local ReplicatedStorage = game:GetService("Replicated Storage")
local RoKeys = require(ReplicatedStorage.RoKeys)

--you may have to edit this depending on where you put RoKeys and the version of RoKeys

And now you are ready to take full advantage of RoKeys.

Adding keybinds

To add a KeyBind use the function New. the function takes the name of a Bind (as a string), the Input you want to assign to the Bind (as an EnumItem), and BindToggle and InputToggle (as booleans) which determine wether the bind and input should use a toggle behavior.

as of v2 Enum.KeyCode is the only supported input type.

RoKeys.New({ 
  Binds = "example", 
  Inputs = Enum.KeyCode.X, 
  BindToggle = true. 
  InputToggle = false
})
--because this is a dictionary it does not matter what order you provide values in

This function can also be written where the Binds/Inputs are tables, containing both the Binds/Inputs’ Name and wether they use a toggle behavior.

RoKeys.New({ 
  Binds = {
    Name = "example", 
    Toggle = true
  }, 
  Inputs = {
    Name = Enum.KeyCode.X, 
    Toggle = false
  } 
  --notice the {} brackets surrounding the binds and inputs
}) 
--this does the same thing as the previous example

You can also add multiple Inputs, Binds, or both in one function!

RoKeys.New({ 
  Binds = "two inputs", 
  Inputs = {
    Enum.KeyCode.X, 
    Enum.KeyCode.Y
  } 
  --one bind has two inputs
}) 

RoKeys.New({ 
  Binds = {
    "bind 1", 
    "bind 2"
  }, 
  Inputs = Enum.KeyCode.X 
  --two binds, each with one input
}) 

RoKeys.New({ 
  Binds = {
    "two inputs 1", 
    "two inputs 2"
  }, 
  Inputs = {
    Enum.KeyCode.X, 
    Enum.KeyCode.Y
  } 
  --two binds, each with two inputs
}) 

not limited to two for each. you can also still provide Toggle for each individual Bind and Input, any toggles provided as BindToggle or InputToggle slots will apply for every Bind or Input without their own toggle provided.

Removing keybinds

The function Remove takes the name of a Bind (as a string) and an Input (as an EnumItem). The function will use the provided values to filter through the existing Keybinds and delete only the Inputs for the provided Binds and the Binds for the provided Inputs.

RoKeys.Remove({ 
  Binds = "example", 
  Inputs = Enum.KeyCode.X 
})
--the Input "Enum.KeyCode.X" and the Bind "example" will no longer interact

similarly to New, Remove supports deleting multiple Binds and Inputs.

You can also delete Inputs or Binds en-masse as shown below:

RoKeys.Remove({ 
  Binds = "example" 
  --notice you are not providing input
}) 
--the Bind "example" will be deleted in it's entirety

RoKeys.Remove({ 
  Inputs = Enum.KeyCode.X 
  --notice you are not providing bind
}) 
--the Input Enum.KeyCode.X will be deleted in it's entirety

Reading Keybinds

Reading Keybinds is a lot simpler as compared to Adding or Removing them. To read keybinds you are provided two functions; BindState and InputState, in each all you need to do is provide either the Bind or Input (depending on which function you are using) and the function will return a boolean of wether the Bind/Input is true or false.

if RoKeys:BindState("example") then --if bind "example" is on...
  --do something
end
--notice the function is in an if statement

InputState has the same usage except reads from wether an input is on.

Pausing and Resuming Keybinds

Pausing Keybinds is about the easiest thing you can do, provide the Binds and Inputs you want to pause/resume and your comand will be upheld

Rokeys.Pause({Binds = {"example1", "example2"}, Inputs = Enum.KeyCode.X)
--like other functions, you only need to give one or the other

--Rokeys.Resume() works the same way except will only resume the keybinds

Clearing Keybinds

When clearing keybinds you have three choices, “ALL” (which clears all Binds and Inputs), “BINDS” (which clears all Binds), and “INPUTS” (which you can imagine what it’d do)

Rokeys.Reset("ALL") --when this line is run everything is reset
Advanced Usage

Adding keybinds… Part 2

this will outline more you can do with the New function, as an example, here is a way to apply toggles, values, or pauses en-masse without BindToggle or InputToggle:

Rokeys.New({
  Binds = {
    { Name = "example1" },
    { Name = "example2" },
    Toggle = true --all binds have a toggle
  }
})

The new function also returns two tables (as of v2), one holding the Binds created and one holding the Inputs created

local binds, inputs = Rokeys.New({
  Binds = "example1",
  Inputs = {
    Enum.KeyCode.X,
    Enum.KeyCode.Y
  }
})

--the variable binds is now {"example1"}
--the variable inputs is now {Enum.KeyCode.X, Enum.KeyCode.Y}

the names of the two variables do not matter

You can also manually define what one thing references to another thing (Input triggers certain Nind and vice versa) by providing a table with the key value Refs

Rokeys.New({ 
  Binds = {Name = "example", Refs = Enum.KeyCode.X}
})
--this method is not reccomended as providing already existing inputs along with binds connects both of them, instead of the user having to manually connect the two together themselves

The Format Function

This Format Function Takes what you would use as the Input or the Bind in the New function and returns it as a standard format

print(Rokeys.Format({ 
  { Name = "example1", Toggle = true, Refs = {Enum.KeyCode.X} }, 
  { Name = "example2", Value = true, Paused = true }
}))

output:

{
  { 
    Name = "example1",
    Toggle = true,
    Refs = {Enum.KeyCode.X}
  },
  {
    Name = "example2",
    Value = true,
    Paused = true
  }
}
--the changes aren't as noticable here

Another example is the following

print(Rokeys.Format("example"))

output:

{
  {
    Name = "example"
  {
{
Changing the code

BEFORE CHANGING THE CODE PLEASE READ THE LICENSE

I made my best effort to comment as much as possible inside of my code and will incrementally be bringing some of that here, if you have any questions you can ask them on Github Issues (may not respond very fast) or Discord (link found at start of the document).

For frequently asked questions look in the following section (FAQ).

Manually reading data

All data for Keybinds are stored in two tables, BindTable and InputTable. These two tables’ formatting are as follows:

RoKeys.BindTable {
  bind { --the name of the bind, depending on how many binds you have there will be that many of these
    Value = boolean, --wether it is on or off
    Toggle = boolean, --wether toggle is on
    Paused = boolean, --wether it is paused
    Refs { --reference(s) to it's input(s)
      InputName, --names of the input(s)
      ...
    }
  }
}

RoKeys.InputTable { --same layout as bindTable
  input { --this will likely say token followed by a string of numbers, do not worry as it is just a side effect of using EnumItems
    Value = boolean,
    Toggle = boolean,
    Paused = boolean,
    Refs {
      BindName
    }
  }
}

I strongly recommend using the built in functions to add and remove Keybinds. this section is for if you want to be able to read more data or have a better understanding of how it is stored

FAQ

FAQ or Frequently Asked Questions, more specific questions can be found in the Discord (link found at start of the document)

Currently nothing here, this will become more populated as people ask questions.

Licensing

Copyright [2022] [Urdons]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
10 Likes

I made my own keybinding script, actually two versions, and they turned out quite nicely. I just want to know if there’s any possible way that this can correctly place touch buttons.

1 Like

The code could be improved, there are unnecessary checks like ~= nil when the value probably isn’t a bool. Some type checking for Luau would also be nice. You should add some example code to here and the Github repository.

1 Like

I will definitely be looking for places where I could improve my code for the the next major update. I myself am pretty new to coding so the feedback is greatly appreciated and it’s a big motivator to see people recognizing this project. I’ll definitely look into type checking (not sure why I didn’t in the first place) and removing that unnecessary code.

You may need to elaborate on what you mean by “touch buttons”, if you’re talking about on-screen buttons for mobile then that’s a no. I am planning on implementing a way to bind mobile and controller inputs but that will probably be a little further in the future.

1 Like