luarobloxcomputercraft

Lua: Key pressing


Is there any way to detect key pressing in Lua?

Im using replit for excecuting my own code. (Im new to lua)

In roblox (eLua), computerCraft mod, there some kind of key function that lets you detect, if key up or down, what kind of key pressed. i need same result but in replit.

AKA:

Computer Craft:

local event, key, isHeld = os.pullEvent("key")
while true
  write(keys.getName(key))
  print( isHeld and " is being held." or " was pressed." )
end

Solution

  • Lua Itself does not provide a method for detecting keys being pressed. That said, there are many implementations that provide methods for detecting key states.

    There are libraries and such that provide support for keys, though in this case if you're using Repl.it to execute your code I'd suggest using Löve2D, which is a Lua-based Game engine that can run in Repl.It The Docs of which can be found Here. Key state can then be polled with love.keyboard.isDown(key) method or love.keypressed event

    If you just wanted a Lua Terminal with Keyboard support, You'd have to have a look for standalone libraries.