• 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.

Question Key press events in Lua vessel script?

Thunder Chicken

Resident Lua Script Rabble-Rouser
Donator
Joined
Mar 22, 2008
Messages
5,879
Reaction score
5,555
Points
188
Location
Massachusetts
I am trying to figure out how to implement key presses inside a vessel script. In particular, I'd like to trigger a landing gear animation by hitting the 'G' key.

In Lua there does not seem to be a callback function for this. There is a v:send_bufferedkey(keycode) method, but I am not quite sure what it does and where it should be located.

In a C++ module I had code to do this as follows in clbkConsumeBufferedKey:

C++:
    case OAPI_KEY_G: // Gear

        //gear_anim_status: 0 - stationary, 1 - raising, 2 - lowering

        if (gear_anim_status == 0 && gear_anim_state < 1.0) // if fully or partially extended
        {
            gear_anim_status = 1; //raise gear
        }

        else if (gear_anim_status == 0 && gear_anim_state == 1.0) //if fully retracted
        {
            gear_anim_status = 2; //lower gear
        }

        else if (gear_anim_status == 1) //if raising gear
        {
            gear_anim_status = 2; //lower gear
        }

        else if (gear_anim_status == 2) //if lowering gear
        {
            gear_anim_status = 1; //raise canopy
        }

        else
        {
            gear_anim_status = 0;
        }

        return 1;

I saw this thread but am not sure if this is the answer to my problem.
 
Back
Top