Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a "Get Keyboard Input" function in Lua? (Arrow keys)

Tags:

input

lua

I was wondering if you could receive keyboard input just like Java, C+, etc. Or if there isn't is there external libraries?

Here's some info on the 2D, Maze-Game: You use the arrow keys to navigate through the maze. You use the UP and DOWN arrow keys to select the objects in the menu, for example:

--> New Game

Load Game

Options

And so on... I appreciate any help. Good day.

like image 470
Carlos Lombardii Avatar asked Feb 04 '26 01:02

Carlos Lombardii


2 Answers

Lua on its own does not provide any libraries that aren't part of ANSI C, which is part of the extensive portability of the language.

As such, you miss out on things like keyboard input and graphics, but also operations that might be considered "simple," like listing the files in a directory.

Most likely, there's a library for what you need, and if there isn't, then keep in mind that Lua is one of the friendliest languages to write C-side libraries for.

LOVE is a good framework that couples quite a few extensions to Lua (including a rather abstracted interface to SDL) with a distribution method, more or less. If you're developing games with Lua, this is a good place to start.

EDIT: If you're on Windows with LuaJIT and you're okay with global key hooks, then I developed a library recently (May 2015) that solves that problem: https://github.com/LPGhatguy/global-keys

like image 72
Lucien Greathouse Avatar answered Feb 05 '26 21:02

Lucien Greathouse


There are libraries like curses that may help; here is one tutorial one reading arrow keys with curses in Lua. There is also luaposix library, which includes curses.

like image 31
Paul Kulchenko Avatar answered Feb 05 '26 22:02

Paul Kulchenko