Software Coding Key press / input

paddy2

Addon Developer
Addon Developer
Joined
Jul 21, 2012
Messages
384
Reaction score
1
Points
18
Location
Kent, UK
Yet again I am up here asking for help. I do thank you nice people in advance and am grateful for the time you take. ( Creep over)

I am having a go at my first c++ vessel and learning c++ at the same time.
I wish to have some doors open on command. They would be covers over cages which hold UCGO cargo. I feel I would be able to do the "moving" as I have written and published a UCGO "car" which had moving parts. DAN ( most wise and revered one ( vénéré )) had a cfg file which had the keyboard input mapped to groups for movement so it was a "no brainer".

What I need is help on getting code which says some thing like
" when this key is pressed, do the following animations, when that key is pressed here are some other stuff to move."


As I am modding the default ShuttlePB code a lot of "stuff" just happens for free; press F1/F8 and the ext view/VC pops up; I have no idea how this happens but it works fine when running the .dll

Could some kind soul points in the direction of "stick this above your animation, stick this below your animation" and control shift caps whatever will open and close the doors.

As I say I think I can do the moving its the pressing that I just can not get started on

THanks thanks and bye the way thanks
 

paddy2

Addon Developer
Addon Developer
Joined
Jul 21, 2012
Messages
384
Reaction score
1
Points
18
Location
Kent, UK
I did try to follow the whole series but got lost along the way somehow
 

Izack

Non sequitur
Addon Developer
Joined
Feb 4, 2010
Messages
6,665
Reaction score
13
Points
113
Location
The Wilderness, N.B.
To interpret key presses in your module, the easiest and recommended way is to use clbkConsumeBufferedKey(), which is explained in the API documentation.

Here's one implementation of it:

Code:
int Deepstar::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate)
{
	if(!down)
		return 0;
	//Return without proceeding if key is being released

	if(!KEYMOD_CONTROL(kstate) && !KEYMOD_SHIFT(kstate) && !KEYMOD_ALT(kstate)) //CLEAN, no CTRL, no ALT, no SHIFT
	{
		switch (key)
		{
		case OAPI_KEY_D:
			//Do a thing when D is pressed
			return 1;
		}
	}
	else if (KEYMOD_CONTROL(kstate) && !KEYMOD_SHIFT(kstate) && !KEYMOD_ALT(kstate)) //CTRL
	{
		switch(key)
		{
		case OAPI_KEY_A:
			//Do a thing when CTRL+A is pressed
			return 1;
		}
	}
	else if (!KEYMOD_CONTROL(kstate) && KEYMOD_SHIFT(kstate) && !KEYMOD_ALT(kstate)) //SHIFT
	{
		
	}
	else if (!KEYMOD_CONTROL(kstate) && !KEYMOD_SHIFT(kstate) && KEYMOD_ALT(kstate)) //ALT
	{
		
	}
	return 0;
}

"Do a thing" can be anything - change an animation state, activate a thruster, spawn another vessel, crash Orbiter, etc.

Animation in Orbiter is a whole topic not easily summarised. Do you have an understanding of it already, and only have trouble tying it to user input, or are you starting from scratch?
 

paddy2

Addon Developer
Addon Developer
Joined
Jul 21, 2012
Messages
384
Reaction score
1
Points
18
Location
Kent, UK
I think I can do the animation it is just getting it "triggered" by a keypress. That code from Deepstar seems to be the sort of thing I need and it gives me a place to drop the animation into.

Not sure what the last two "else" are doing other than testing for shift and Alt!

Grandkids over the weekend so will play with it come monday
Ta
 
Top