Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I allow the user to create custom keybinds for opening GUIs?

I'm trying to make a button where the keybind to toggle a GUI is changed by clicking a TextButton - the next key they press will be the new keybind

keybind is the default keybind, it will be updated with the Enum code for the new keybind.

TextButton.Text will also be changed to the current keybind

like this:

[RightShift] [E] [R]

etc.

local keybind = Enum.KeyCode.RightShift
local UIS = game:GetService("UserInputService")

script.Parent.MouseButton1Click:connect(function()
	UIS.InputBegan:connect(function(input)
	--Detect the next key pressed and nothing else
end)
end)

hope this all makes sense lol

1 answer

✓ Accepted answer

something along these lines. i am assuming you're already familiar with scripting and understand what this would do.

local UIS = game:GetService("UserInputService")

local Button = script.Parent

local DefaultKeybind = Enum.KeyCode.LeftShift

local CurrentlyBinding = false
Button.MouseButton1Down:Connect(function()
	CurrentlyBinding = true
end)

UIS.InputBegan:Connect(function(input)
	if CurrentlyBinding == true and input.KeyCode ~= DefaultKeybind then
		CurrentlyBinding = false
		
		local ReplaceKeybindWithThis = input.KeyCode
		--do something to change the keybind
	end
end)

8 comments

0

Yeah that mostly makes sense... How would I go about changing "keybind" to the new value?

0

Nevermind... just saw your edit, thanks! I'll give it a try

0

i make edits often to make sure i fix any flaws, sorry about that. let me know how it goes. (just made another edit)

0

Now whenever I print keybind.Name I get "InputObject", not sure whats going on

0

made an edit to line 16, my bad. gotta check the input.KeyCode

0

Thank you, got it working, gonna mess around with Button.Text to try and get it to display the current keycode.

0

awesome, good luck.

1

Managed to do that now too, working perfectly. You're a life saver - this was driving me absolutely insane

This discussion is preserved as it was. New answers, comments, and votes are closed.