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:
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
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.
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
Isn't there a Module class in Orbiter2010 that you can derive from which has a key callback?
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
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.
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
Nevermind, carry on then :)
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
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.
 
Top