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

Creating a initiate type script?

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.

1 answer

✓ Accepted answer

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

3 comments

0

This is very complex. Could you please link me some sources and stuff to help me understand this? I am a very basic scripter and rather understand almost intermediate topics and skills.

0

UserInputService is a bit more complicated, but here are some links for both: http://wiki.roblox.com/index.php?title=API:Class/TextBox http://wiki.roblox.com/?title=API:Class/UserInputService If you have any questions, feel free to PM my main (EmeraldSlash).

0

I'm a little more experienced now, this is easy stuff to me. I forgot to accept your answer by the way.

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