• ORBITER-FORUM will be temporarily closed at 2026-07-23 18:00 UTC while we complete some OF maintenance tasks. The amount of downtime is expected to take up to one hour, but probably less.

LUA Catching keyboard keys in LUA

widdernix

New member
Joined
Mar 8, 2010
Messages
6
Reaction score
2
Points
0
Location
Lich
I am searching for a method to catch a pressed key in LUA. In the help file I found a method oapi.keydown(kstate,<Scanode_of_key>) but I get a error message, when I call it: oapi_keydown: argument1: invalid type (expected handle).

This is what I tried so far:

Code:
kstate = {}
for i=1,256 do kstate[i] = string.char(0) end

function _test1()
  kstate[OAPI_KEY.V] = string.char(0x80)
  if oapi.keydown(kstate[OAPI_KEY.V],OAPI_KEY.V) then
    term.out('V')
    return true
  end
  return false
end

I think the problem is kstate. It seems that the called C function needs a pointer here, but as far as I know LUA does not know anything about pointers.

The purpose is to do custom things in Orbiter for example gear down with the key combination Ctrl-G and gear up with Alt-G for use with a gear switch.
 
The trouble is Lua in Orbiter seems to be unaware of external events, and all the waiting is done by running empty cycles.
 
Back
Top