Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I go about doing this?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

Ad

Answer this question