Key Pressed In Studio

How do detect when a user in studio presses a key. I know about UserInputService but that only applies to players in game and not in studio. Any help is greatly appreciated and I don’t want full scripts. Thank you for your time!

2 Likes

Are you making a plugin? In that case, you can detect mouse and keyboard input using UserInputService just like detecting input in games.

Alternatively, if you want to let users bind custom key combos to plugin actions, use PluginActions.

EDIT: Example plugin to test keyboard input:

local InputS = game:GetService("UserInputService")

InputS.InputBegan:Connect(function(inputObject)
    print(inputObject.KeyCode)
end)

Right click and “Save as Local Plugin”

1 Like

It works the same as in game? I never knew that, thanks for the help!

Just to clarify, in a DockWidgetPluginGui, after the WindowFocused event fires, inputs are not detectable with UserInputService’s InputBegan, InputChanged or InputEnded. The only way of handling this is using the Roblox PluginActions, placing all the ui inside of CoreGui and StarterGui, or utilizing the input events from a Gui.

How to detect Input with a ScrollingFrame in CoreGui and StarterGui (C&S) or in DockWidgetPluginGuis(DW)l
You may ask, why not use the active property? Heres why, when this property is activated in C&S, it forces you to have a PluginMouse Icon, which is very inconvenient, and if you scroll with it off, it will zoom the camera. To prevent this, create a ScrollingFrame with a canvasSize of {0,0},{0,0}, with the Active property set to false, when doing so the ScrollingFrame’s XY bars will disappear. Now you can detect scrolling without the forced PluginMouse Icon being in the way or the camera moving. The nice thing is buttons behind this ScrollingFrame will still work, so if you overlay it on top of your ui, button events still fire.

ezgif-2-c69062d748dbezgif-2-d440d43f8d7b
Detecting Scrolling Input:

local ScrollingEvent = ScrollingFrame.InputChanged:Connect(function(Key)
	if Key.UserInputType == Enum.UserInputType.MouseWheel then
		local Direction = math.sign(Key.Position.Z)
        --// scrolling code here
	end
end)

However, when in a DW, it is advised to use a Frame so it doesn’t interrupt the functions of ScrollingFrames underneath it. These events in a DW only work if it’s selected, and for DW & C&S if the mouse is over the gui object.

local Changed = ScrollingFrame.InputChanged:Connect(function(Key)
	print(Key.KeyCode, Key.UserInputType)
end)
local Began = ScrollingFrame.InputBegan:Connect(function(Key)
	print(Key.KeyCode, Key.UserInputType)
end)
local Ended = ScrollingFrame.InputChanged:Connect(function(Key)
	print(Key.KeyCode, Key.UserInputType)
end)

ezgif-4-70443764d85cThe default button Cursor Icon just changed, it looks much better, :smiley: .

3 Likes