SDK Question Using keys in a plugin module?

astrosammy

Dash!
Addon Developer
Donator
Joined
Apr 27, 2008
Messages
2,124
Reaction score
0
Points
36
Location
ICAO ID: EDFB
I'm just trying to write a little autopilot plugin, and want to switch it on and off by some key (let's say F5), but I just don't get it working.

Here's the code, nothing is happening when I press F5:

Code:
#define STRICT
#define ORBITER_MODULE
#include <Orbitersdk.h>
 
DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
}
 
DLLCLBK int clbkConsumeDirectKey(char *kstate)
{
    if(KEYDOWN(kstate,OAPI_KEY_F5))
    {
        sprintf(oapiDebugString(),"PRESSED");
    }
    return 0;
}

:thankyou:
 
This is neither a vessel, so it won't get clbkConsumeDirectKey & clbkConsumeBufferedKey callbacks, nor an MFD, so it won't get ConsumeKeyBuffered & ConsumeKeyImmediate callbacks, and there are no generic callbacks for keyboard in Orbiter API, but you can use Windows API's GetKeyState in opcPreStep instead, to retrieve the state of a given key.
 
Isn't there a Module class in Orbiter2010 that you can derive from which has a key callback?
 
Isn't there a Module class in Orbiter2010 that you can derive from which has a key callback?
No, Module class doesn't define key pressing callbacks. At least there is nothing about it I could find in the API reference, nor in headers, nor in the Orbiter.exe (101016) itself by looking directly at the export table.
 
Nevermind, carry on then :)
 
This should work:

Code:
#define STRICT
#define ORBITER_MODULE
#include <orbitersdk.h>
 
DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
    if ( GetAsyncKeyState(VK_F5) )
    {
         sprintf(oapiDebugString(), "Pressed");
    }
}

A word of advice: I would only perform this test every 200 milliseconds or so. Otherwise this code will be executed several times in the time it takes for you to press the key and let go of it.
 
Back
Top