Hey! I am trying to make a textbox detect what you click, for keybinds. I have a clip example of this, and I have no clue how this is done. Any help is appreciated!
Clip:
Hey! I am trying to make a textbox detect what you click, for keybinds. I have a clip example of this, and I have no clue how this is done. Any help is appreciated!
Clip:
Use UserInputService InputBegan and you can gain the key code from that
Example code:
local uis = game:GetService("UserInputService")
uis.InputBegan:connect(function(input,gameProcessed)
if gameProcessed then return end -- makes sure that it's not entered in Roblox chat
if input.UserInputType == Enum.UserInputType.Keyboard then
print(input.KeyCode)
end
end
end)
I was just about to ask if that is a solution lol, I just realized it. What a dumb moment for me. Thanks for the help though
This is done by UserInputService’s InputBegan event.
-- In order to use the InputBegan event, the UserInputService service must be used.
local UserInputService = game:GetService("UserInputService")
-- Input is handled with this event! It fires every time a key is pressed locally. The gameProcessed variable indicates if the input was handled by roblox or not. A common example of this is when a key is pressed while chatting, which is processed.
local changingControl = ""
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA('TextButton') then
v.MouseButton1Click:Connect(function() changingControl = v.Name end)
end
end
-- This code assumes the script is in the folder/frame parent of the text buttons, and that each text button has its name defined separately.
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end -- Make sure it wasn't processed!
if changingControl ~= "" then
script.Parent[changingControl].Text = tostring(input.KeyCode):sub(13) -- Substring 13 characters from Enum.KeyCode., which allows us to only see the keycode being used!
-- Other handling would go in here.
changingControl = ""
end
end)
On mobile while writing this so formatting might not be the best, but this is an example of how something like this could be done.
Cheers.
EDIT: ninja’d