Events Lua中的按键事件?
可以让用户在lua上按键吗? feEvents Lua中的按键事件?,events,lua,keypress,Events,Lua,Keypress,可以让用户在lua上按键吗? fe 没有存货,卢阿。可能有一个额外的图书馆 Lua基于极端的可移植性。因此,它基本上只提供ANSI C中提供的功能。(我认为唯一的例外是动态链接,这是一种非ANSI特性,并非在所有平台上都可用,但非常有用,他们已经为许多平台提供了它。) ANSI C不提供按键功能,因此默认的Lua库也不提供 也就是说,存储库可能会引导您找到具有此功能的库。例如,可以在LuaRocks页面上找到,它具有您需要的功能。(请注意,您可能需要删除不需要的位。)可能还有其他可用的库。去挖吧
没有存货,卢阿。可能有一个额外的图书馆 Lua基于极端的可移植性。因此,它基本上只提供ANSI C中提供的功能。(我认为唯一的例外是动态链接,这是一种非ANSI特性,并非在所有平台上都可用,但非常有用,他们已经为许多平台提供了它。) ANSI C不提供按键功能,因此默认的Lua库也不提供 也就是说,存储库可能会引导您找到具有此功能的库。例如,可以在LuaRocks页面上找到,它具有您需要的功能。(请注意,您可能需要删除不需要的位。)可能还有其他可用的库。去挖吧
如果做不到这一点,Lua的全部要点就是可扩展性。它是一种可扩展的扩展语言。实际上,提供您想要的功能并不难。项目中有一个到getkey()的绑定。你可以从那里得到一些消息来源
(它只是包装了getch())似乎您正在尝试制作一个游戏。对于2D游戏,你可能需要考虑。它看起来有点奇怪,但它可以工作,而且与其他语言(如C)相比相对容易。第一件事是:如果您使用我的方法来执行此操作,则需要将您使用的脚本放入本地脚本中。不这样做将导致密钥不显示在控制台中(F9查看控制台) 好的,现在我们知道它在本地脚本中,下面是脚本:
local player = game.Players.LocalPlayer -- Gets the LocalPlayer
local mouse = player:GetMouse() -- Gets the player's mouse
mouse.KeyDown:connect(function(key) -- Gets mouse, then gets the keyboard
if key:lower() == "e" or key:upper() == "E" then -- Checks for selected key (key:lower = lowercase keys, key:upper = uppercase keys)
print('You pressed e') -- Prints the key pressed
end -- Ends if statement
end) -- Ends function
如果您只想发出一个键的信号(仅限小写或仅限大写),请选中下面的复选框
仅小写字母:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "e" then
print('You pressed e')
end
end)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "E" then
print('You pressed E')
end
end)
仅大写:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "e" then
print('You pressed e')
end
end)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "E" then
print('You pressed E')
end
end)
或者,如果您想在一般情况下发出任何键的信号,也可以执行以下操作:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
print('You pressed '..key)
end)
我希望我能帮你回答你的问题。这是罗布洛克斯·卢阿,不是纯卢阿