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

How do I make a user press down a key?

Asked by
sonuka 24
5 years ago

How do I make a user press down a key? So for example I want to make a player press Q how would I do that?

1
You can't force a player to press a key. User#19524 175 — 5y
0
^ Not with standard methods. You could make a custom BindableEvent for when a key is pressed and fire that at will. ee0w 458 — 5y
0
Not possible. There literally is no way to "hack" a player's PC through Roblox to force them to press a key. It's just not possible and it's also wrong. DeceptiveCaster 3761 — 5y

2 answers

Log in to vote
0
Answered by
ee0w 458 Moderation Voter
5 years ago

Required Knowledge:

  • BindableEvents
  • UserInputService
  • KeyCode Enumeration

Probably the best approach to this would be making a BindableEvent and fire that when a key is pressed. You could then fire said event at will, effectively simulating a keypress.

Example:

local uis = game:GetService("UserInputService")
-- Set up the event
local event = Instance.new("BindableEvent")
event.Name = "KeyPressEvent"
event.Parent = script

uis.InputBegan:Connect(function(key)
    event:Fire(key.KeyCode) -- Fire the event
end)
event.Event:Connect(function(keycode) -- Use this from now on instead of UIS.InputBegan
    -- Your code
    if keycode == Enum.KeyCode.E then
        print("E was pressed")
    end
end)

event:Fire(Enum.KeyCode.E) -- Force a keypress

This is only an example and can be easily expanded on.

If I helped, be sure to accept/upvote!

Ad
Log in to vote
-1
Answered by
LuaDLL 253 Moderation Voter
5 years ago
Edited 5 years ago
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Key,GameProcessed)
    if not GameProcessed then -- If Player Is Typing For Example, It wont do anything
        if Key.KeyCode == Enum.KeyCode.Q then -- Checks if the key is Q
            -- Run Your Code Here
        end
    end
end)

Or The WIKI

0
Im asking how to make the player press a key not how to DETECT a player pressing a key sonuka 24 — 5y

Answer this question