API Question Help with SendBufferedKey and keydown...

Mogeley

New member
Joined
Jan 4, 2009
Messages
38
Reaction score
0
Points
0
I'm writing an MFD and I need help with a certain type of keypresses. For some reason the ships functions that respond to a keydown like the brakes I cannot send the ship the key.

Here's the code I'm using currently. I'm not sure if this makes a difference but all my processing coding is being called on "opcPreStep". For debugging I put these lines in a location where they are being called on every time step.

Vessel->SendBufferedKey(OAPI_KEY_COMMA, true);
Vessel->SendBufferedKey(OAPI_KEY_PERIOD, true);

the following code:
sprintf (oapiDebugString(), "LB %i RB %i", mV->SendBufferedKey(OAPI_KEY_COMMA, true), mV->SendBufferedKey(OAPI_KEY_PERIOD, true));

returns:
"LB 0 RB 0"

Stating that the keydown calls are NOT being sent.

The doc's have a keystate section. Though it compiles without it so I'm not sure if it's needed. If I need the keystate then could someone explain a little on how they are supposed to be used. That part confused me.

From doc:
int VESSEL::SendBufferedKey ( DWORD key, bool down = true, char * kstate = 0)

Anyone know what I am doing wrong here?
 
Last edited:
kstate is only required if you need to check for modifier keys (Shift, Ctrl, Alt).

You will only get a nonzero return value from SendBufferedKey if the vessel returns nonzero from clbkConsumeBufferedKey as a result of processing the key. Are you doing that? (a nonzero value indicates that orbiter should skip default processing of the key). Have you checked if your key is arriving in clbkConsumeBufferedKey?
 
I found the function for controlling the wheel brakes, SetWheelbrakeLevel...

Yet I can still use the comma and period keys to press the wheel brakes. This must be built into Orbiter's core functionality. Is there a way to send Orbiter this keypress? I'm not using a clbkConsumeBufferedKey, nor clbkConsumeDirectKey function. So there's nothing to intercept

But I'm still confused as to how to send a CRTL-G to the vessel. I'm not sure how to create the "kstate array" for:

vessel->SendBufferedKey(OAPI_KEY_G, true, char *kstate=0);

where the "kstate array" of OAPI_KEY_LCONTROL is passed into: char *kstate=0

Any help is appreciated.
 
I found the function for controlling the wheel brakes, SetWheelbrakeLevel...

Yet I can still use the comma and period keys to press the wheel brakes. This must be built into Orbiter's core functionality. Is there a way to send Orbiter this keypress? I'm not using a clbkConsumeBufferedKey, nor clbkConsumeDirectKey function. So there's nothing to intercept

But I'm still confused as to how to send a CRTL-G to the vessel. I'm not sure how to create the "kstate array" for:

vessel->SendBufferedKey(OAPI_KEY_G, true, char *kstate=0);

where the "kstate array" of OAPI_KEY_LCONTROL is passed into: char *kstate=0

Any help is appreciated.

As I have found it, kstate is a char kstate[256], with every kstate[OAPI_KEY_<key>] being 0x80 for pressed keys and 0x00 for all other keys.

If you want to send a CTRL-G, you could do the following:

Code:
char kstate[256];
for(int i=0;i<256;i++) kstate[i]=0x00;
kstate[OAPI_KEY_G]=0x80;
kstate[OAPI_KEY_LCONTROL]=0x80;
vessel->SendBufferedKey(OAPI_KEY_G, true, kstate);
Hope this helps.

...wait.. what? SendBufferedKey? Is this from release candidate?

regards,
Face
 
Yet I can still use the comma and period keys to press the wheel brakes. This must be built into Orbiter's core functionality. Is there a way to send Orbiter this keypress? I'm not using a clbkConsumeBufferedKey, nor clbkConsumeDirectKey function. So there's nothing to intercept
In that case, SendBufferedKey probably won't do what you want. You may have to use this method:

http://orbiter-forum.com/showthread.php?t=6101
 
Face, Thanks! I'll try that.

Yeah this is for the current beta release 091124.

Orbiter 2010 will probably be released before I ever finish my MFD.


Martins, Thanks for the link to the thread. I think the hangup I was having was that I was assuming the vessel interpreted the key presses for the brakes just like some vessels interpret a key for landing gear.
 
Thanks! This works great! I was able to just drop it in my code and use it.
 
Back
Top