LuaU脚本(Roblox),我怎样才能用脚本按下一个键

问题描述 投票:0回答:3

一个例子就像

local E = game:GetService('UserInputService').SetKeyDown(Enum.KeyCode.E) 

但是它当然不起作用,因为我不能用这个东西让我的游戏本身按E,所以它需要更长的时间,如果你找到解决方案,你也可以做一个让它按下的地方吗?

lua scripting user-input roblox lua-userdata
3个回答
0
投票

输入只能在客户端上注册,因此您必须在

LocalScript
中进行编码。有 2 个服务用于获取玩家的输入:-

此示例展示了如何使用 UserInputService 来获取玩家的 LeftMouseButton 输入。

local UserInputService = game:GetService("UserInputService")
 
local function onInputBegan(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("The left mouse button has been pressed!")
    end
end
 
UserInputService.InputBegan:Connect(onInputBegan)

此示例正确展示了如何使用 ContextActionService 将用户输入绑定到上下文操作。上下文是正在配备的工具;该动作正在重新装载一些武器。

local ContextActionService = game:GetService("ContextActionService")
 
local ACTION_RELOAD = "Reload"
 
local tool = script.Parent
 
local function handleAction(actionName, inputState, inputObject)
    if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
        print("Reloading!")
    end
end
 
tool.Equipped:Connect(function ()
    ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)

你应该看看维基页面。


0
投票

听起来您想编写一个脚本来按

E
键,但这是不可能的。

您可以将操作绑定到按键,就像 Giant427 提供的示例一样,您也可以手动调用绑定到这些操作的函数,但您无法编写脚本来触发键盘输入。


0
投票

loadstring(游戏:HttpGet("https://raw.githubusercontent.com/LOLking123456/toilet3/main/Tower5"))() -- 关键 https://link-center.net/256968/toilet-tower-best

© www.soinside.com 2019 - 2024. All rights reserved.