About using a keybind to textbox

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

For the player to select a key(keybind) to then show on the textbox,
(Player>select key… show key in textbox, the player can see the key they select in the textbox

  1. What is the issue? Include screenshots / videos if possible!
    Well I have a gui, and also a textbox, but when the player enters the key they want, then it dosent assign it nor show that they choose it

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have been looking for a while on the Web to see if I could see any thing relating to the issue, but i couldn’t see anything about it

1 Like

So you want to bind a key to activate the textbox like pressing “/” to chat?

3 Likes

I mean like for the player to select the key, if it was for a move or something like if they wanted the key to be E or F or R or something ?

2 Likes

Oh ok so you can try this:

Create a StringValue inside the LocalScript and replace your TextBox with a TextButton

local UserInputService = game:GetService("UserInputService")
local StringValue = script.--StringValue Name
local TextButton = --Path to TextButton
local ChangingKeybing = false

TextButton.MouseButton1Click:Connect(function()
    ChangingKeybind = true
    TextButton.Text = "Press something"
end)

UserInputService.InputBegan:Connect(function(Input)
    if ChangingKeybind == false then
        if Input.KeyCode == Enum.KeyCode[StringValue.Value] then
            --Do something
        end
    else
        local Key = string.sub(tostring(Input, 1, 13))
        TextButton.Text = Key
        StringValue.Value = Key
    end
end)

try this

local UIS = game:GetService("UserInputService")

local TextBox = script.Parent -- So This Script Is Fine Parented Into The TextBox Itself

local Key 

UIS.InputBegan:Connect(function(Input, Event)
	if Input.UserInputType == Enum.UserInputType.Keyboard then
		if TextBox:IsFocused() then
			Key = Input.KeyCode
			TextBox.Text = tostring(Input.KeyCode):split(".")[3]
			TextBox:ReleaseFocus() 
		end
		
		if Input.KeyCode == Key and not Event then
			print("You Press The Key!")
			-- Your Code Here
		end		
		
	end
end)

for some reason i didnt use :GetStringForKeyCode cuz it just return letters it returns nil when those shift ctrl tab etc

so i just split instead the enumaration on the input keycode