KeyPress event in Lua?
Solution 1
Lua is predicated on extreme portability. As such it's based on supplying, essentially, only that which is available in ANSI C in terms of capabilities. (I think the sole exception to that is dynamic linking which is a non-ANSI feature not available on all platforms, but is so useful that they've put it in for many.)
ANSI C doesn't provide keypress functionality so the default Lua library doesn't either.
That being said, the LuaRocks repository might lead you to a library with this capability. For example it could be that ltermbox, found on the LuaRocks page there, has the functionality you need. (You'll probably have to remove the bits you don't want, mind.) There may be other libraries available. Go digging.
Failing that, the whole point of Lua is extensibility. It's an extensible extension language. It's not actually all that hard to hand-roll your own extension that provides the functionality you want.
Solution 2
There is a binding to getkey() in the NTLua project. You can get some sources from there.
(it just wraps getch())
Solution 3
Not in stock Lua. Probably with an additional library.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on December 29, 2020Comments
-
Admin over 3 years
is it possible to get users keypress on lua? fe.
while true do if keyPress(27)==true then print("You just pressed ESC") end end
-
AnnoyinC about 3 yearsThis is roblox lua, not pure lua