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

How do I make a user press down a key?

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?

3 comments

1

You can't force a player to press a key.

0

^ Not with standard methods. You could make a custom BindableEvent for when a key is pressed and fire that at will.

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.

2 answers

##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!

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

1 comment

0

Im asking how to make the player press a key not how to DETECT a player pressing a key

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