Customizable KeyBinds. Better UIS or Advanced CAS

Version 2.3 is out.

MaxTIme works. GUIs added and now you have more than DoubleKeys(you can use index for their function). Example

KeyHandler.Keys[1] = {
	Keys = {"Q", "Q", "Q"}
	Func = function(state, ht)
		--code
	end,
	Funcs = {
		function()
			print("First Q")
		end,
		function()
			print("Second Q")
		end,
		function()
			print("Third Q")
		end,
	}
	GUIs = {
		Q = Gui
	}
}

For the Gui you don’t need to use true or false. You need to index Gui or path to it, so the only requirement is it needs to be ImageButton or TextButton. Image, Text, Size, Position, Color and many more are your choice. If you don’t want them to be visible on PC then make Visible = false. For the Guis, you need to thank @Kotium_I

1 Like

Hey I am trying to make my crouch system use your module instead of contextactionservice and I am having a bit of trouble making it work. I am using this code to test and it doesn’t seem to print anything at all. Please let me know if I did something wrong which is why it isn’t working.

Code: (This is in a local script)

local KeyHandler = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("Keybinds"))

KeyHandler.Keys[1] = {
	Keys = {"Q"}, --required
	Func = function(state, ht)
		
		if state == "began" then
			
			print("worked")
			
		else
			
			print("no")
			
		end
		
	end, --required
}

Thanks in advance

Edit: Found out you have to do KeyHandler:Start() lol. Also what does the “ht” parameter do and what does it stand for?

Few ideas to make this module better:

  • Adding a way so 2 different keys can activate the same function without having to press them both at the same time for the function to start.

  • State Change. Example:

From this:

if State == "began" then

to this:

if State == Enum.UserInputState.Begin then

Excited to use this module and figure out its full potential and I hope these suggestions help! (I can try and explain better if you don’t understand the first suggestion.)

ht = hold time.
Long story short, time between button press and release(between InputBegan and InputEnded)

I used “began” and “ended” for tables:

local Actions = {
	began = function()
		--code
	end,
	ended = function()
		--code
	end,
}
Actions[state]()

but I fugured out that, unless you use more than 5 items in table, if else statements are faster
2 items in table < if else(Win)
5 items in table(Win) > if else
So, I think I will change State name.

And about first suggestion, I understood it. Something like that:

KeyHandler.Keys[1] = {
	Keys = {"Q,R"}, 
	Func = function(state, ht)
		--code
	end,
}

Or

KeyHandler.Keys[1] = {
	Keys = {"Q"}, 
	Alternate = {
		Q = {"E", "G"}
	}
	Func = function(state, ht)
		--code
	end,
}

I will add both of your suggestions, but right now I’m working on my own game and for my game I need “GlobalKey”(you will see what it is when I finish it)

Edit:
States name changed in 2.4

1 Like

Does this module support Gamepad controls?

Yes.
Key = Enum.KeyCode[Key], so
Use:

KeyHandler.Keys[1] = {
	Keys = {"ButtonX"}, 
	Func = function(state, ht)
		--code
	end,
}

Okay, awesome module! I’ll definitely be using this long into the future.

1 Like

I’m stuck at update right now. So guess what, I give up?

Nah, I will rewrite whole module just to contain new features.

If be honest I just reread my code and it’s not OOP. I don’t really know OOP, but I will learn it(the features I want is “type” and “constructors”, they are easy to implement, however I will add any feature that I will consider useful from OOP). I will optimize my code as much as possible.

Soon version 3.0 will come

Edit:
That is how it’s going

Keytable.Init({
	Keys = {"E", "R"},
	Func = function(state, ht)
		print(state, ht)
	end,
	Funcs = {
		E = function(state, ht)
			print("E")
		end,
		R = function(state, ht)
			print("R")
		end,
	}
} :: KeyHandler.KeyValues)
1 Like

Version 3.0 is out.

Whole code rewriting. OOP and metatables are used.
Connections are optimized.
Alternate Keys are added. (@Kotium_I )

Let me know if there is any bugs or features that you want

Edit: I’m testing some features about module scripts. So soon new patch
Btw,
Key = Table created by KeyHandler
key = button pressed by player

2 Likes

Hey, module looks good. But I think it would make more sense to have one table that contains the index as the key and the value as the function instead of 2 tables. Like so

Keytable.init({
	Keys =  {
		["E"] = function(state, ht)
			print("R")
		end
	}
})

It’s more readable and easy to configure. But besides that, module is fine. Good work

Hmm. I can do that.
It will take math.random(2, 4) days
It’s not big deal, but my PC is broke, it shut downs itself every 30 minutes, which lowers my efficiency

Sick, will def use it in the future for combo keys.

Best of luck man. Hope your pc gets fixed👋

@skelworks, I implemented that.
Types:

Keys: {{
		key : string,
		func : (state: Enum.UserInputType, ht : number) -> nil,
		GUI : ImageButton | TextButton
	}},

Example code:

local Keytable = KeyHandler.Create({
	Keys = {
		{"E", function(state, ht)
			print("E")
		end
		}, 
		{"R", function(state, ht)
				print("R")
			end, 
			plr.PlayerGui.Settings.ImageButton
		}
	},
	Func = function(state, ht)
		print(state, ht)
	end,
} :: KeyHandler.KeyValues)

Edit: Simple Key

local Keytable = KeyHandler.Create({
	Keys = {
		{"E"}, {"R"}
	},
	Func = function(state, ht)
		print(state, ht)
	end,
} :: KeyHandler.KeyValues)

Key without function but with GUI

local Keytable = KeyHandler.Create({
	Keys = {
		{"E", nil, GUI}, 
		{"R", nil, GUI}
	},
	Func = function(state, ht)
		print(state, ht)
	end,
} :: KeyHandler.KeyValues)

Could you tell me what’s going wrong here? I’m not getting any explicate errors but it’s not working and it was working fine before I switched to 3.1

local Projectiles = KeyHandler.Create({
	Keys = {
		{"E"}, {"ButtonR1"}
	},
	Func = function(state, ht)
		print("Working")
	end,
} :: KeyHandler.KeyValues)
local Projectiles = KeyHandler.Create({
	Keys = {
		{"E,ButtonR1"}
	},
	Func = function(state, ht)
		print("Working")
	end,
} :: KeyHandler.KeyValues)

Use this. R1 is a alternative of E, so you need to write them in one table

1 Like

Thanks for clarifying! charlimit

Does this module support mouse inputs?

No. I will implement that soon(tomorrow maybe). Tomorrow my PC will be fixed and I will release good update to this module.

Things to remake or add:
AlterFunc,
LateFunc,
MaxTime,
KeyTime,
KeytableTime
Mouse

In future, I think, this module will become better than CAS. Who knows

1 Like

Do you know what causes this error? If so that would help me a ton in fixing it. It happens whenever my character respawns, and I feel it’s also important to note that I have CharacterAutoLoads turned off.