C++ Question Advice for recording key events in a plugin

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
288
Reaction score
67
Points
28
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
Hi All,

I am trying to develop a simple plugin which interacts with vessels in a simulation (for example refuel all vessels). This is not a dialog box but rather a plugin which when active will always run.

However I cannot seem to be able to record key events.

I can interact with Orbiter's PreStep callback with the code below:
C++:
DLLCLBK void opcPreStep(double SimT, double SimDT, double mjd)
{
    
}

but I cannot seem to do this for the direct key callback. I have this:
C++:
DLLCLBK int opcConsumeDirectKey (char *kstate)
{
    if(KEYDOWN (kstate, OAPI_KEY_UP)) {
        sprintf(oapiDebugString(), "up key pressed");
    }

    return 0;
}

but this doesn't work. Am I missing something obvious? I remember I think I grabbed the opcPreStep function from one of the example pluggins in Orbiter's SDK.

Any help would be greatly appreciated,

Thanks in advance!
 

BrianJ

Addon Developer
Addon Developer
Joined
Apr 19, 2008
Messages
1,676
Reaction score
900
Points
128
Location
Code 347
Hi,
I don't know if this is the correct way to do it, but I can get it to work in my current "CrewDragonMFD" project by declaring "ConsumeKeyImmediate" in the Class section:

C++:
class CrewDragonMFD: public GraphMFD {
public:
    CrewDragonMFD (DWORD w, DWORD h, VESSEL *vessel);
    ~CrewDragonMFD ();
    bool ConsumeKeyBuffered (DWORD key);
    bool ConsumeKeyImmediate (char *kstate);
..................etc.............................}

and using it like this:

C++:
bool CrewDragonMFD::ConsumeKeyImmediate (char *kstate)
{
    if(KEYDOWN (kstate, OAPI_KEY_UP))
        {
        sprintf(oapiDebugString(), "up key pressed");
        return true;
        }
    return false;
}

I know even less about MFD coding than I do about Vessels, so you may wish to ignore this advice.
Good luck!
BrianJ
 
Top