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

How would I go about doing this?

So I am making a user-interface and I figured out all of the other code such as, backspace, enter, shift, and other key input, but I have not figured out how to gain access to the number keys, and the i and o keys.

Can someone explain how I would go about doing this?

It would be a great help,

Sincerely, Darkness246810

1 answer

✓ Accepted answer

Use the UserInputService.

(I can't edit the page just yet, and they removed the link to the input object, so click here for it. It's the 'touch' or 'input' Instance returned by most of the events.)

--LocalScript
local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(inst) --inst is the InputObject
	if inst.UserInputType == Enum.UserInputType.Keyboard then --KeyDown
		if inst.KeyCode == Enum.KeyCode.I then
            print("I was pressed")
		elseif inst.KeyCode == Enum.KeyCode.O then
            print("O was pressed")
		elseif inst.KeyCode == Enum.KeyCode.LeftShift then
            print("Left shift was pressed")
		elseif inst.KeyCode == Enum.KeyCode.Two then
            print("2 was pressed")
	    end
	end
end)

uis.InputEnded:connect(function(inst)
	if inst.UserInputType == Enum.UserInputType.KeyBoard then
		if inst.KeyCode == Enum.KeyCode.I then
			print("I was released")
		end --I think you get the point.
	end
end)

The InputChanged event can be used to catch mouse movement (though you'll need to capture a Mouse object to get the CFrame it's pointing at) and scrolling, and the myriad of Touch events are all useful for mobile games.

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