How would I make a script when a player pushes a specific key that they are then able to type in anything in a certain bar just like the chat? (ex: press / to type in chat)
I know how to do this:
player = game:GetService("Players").LocalPlayer mouse = player:GetMouse() mouse.KeyDown:connect(function(k) key = k:lower() if key == "" then --etc end end)
But I also wanted to specifically use unlisted key buttons that aren't numbers or letters such as '/', 'SHIFT', and etc. I think I saw a page to it but never knew what to do. (or maybe put that ID into the empty key quotations)
EDIT: This question has been answered.
Part 1: UserInputService
Easy enough to learn is UserInputService
, a better way get inputs than KeyDown
(as it's deprecated):
game:GetService("UserInputService").InputBegan:connect(function(key,gameProcessed) -- key = InputObject, gameProcessed = bool (check to see if it's false to make sure the rest of the event isn't going when typing, for example) if key.KeyCode == Enum.KeyCode.Slash and gameProcessed == false then -- use autocomplete or the wiki to get the rest of the Enum.KeyCode keys -- code end end)
Hopefully you can understand that. It will only work in LocalScripts
, as far as I can tell.
Part 2: CaptureFocus
CaptureFocus
is a method of TextBox
objects, and is used to basically automatically select the TextBox
you are calling it with:
textBox:CaptureFocus() -- also note the following relevant things: textBox:ReleaseFocus() -- opposite textBox.Focused -- event textBox.FocusLost -- opposite event
Hopefully I have given you what you wanted!
~TDP