I have tried taking automated screenshots of FSX:SE several different ways in my C++ program. The automated screenshot is supposed to take place after I set several flight variables through SimConnect such that I can take a screenshot of those gauges at those positions for use elsewhere. I have tried using emulated keypresses using SendInput() from the Windows library to trigger PrtSrc, the Win+Alt+PrtSrc used in the Xbox bar for screenshots, and F12 to trigger a Steam screenshot. For some unknown reason, seperate programs running those emulated keypresses produce the desired effect outside of FSX, but when I try to use it in the FSX window, all of the keypresses are sent, but nothing occurs afterward. Here is a code snippet from my most recent test showing the Dispatch function. Everything except for the keypresses work as expected.
Does anyone know why this doesn't work? Pressing the keys manually also produces the desired effect. It is only emulated keypresses that do not work.
C++:
void CALLBACK MyDispatchProcSD(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
HRESULT hr;
switch(pData->dwID)
{
case SIMCONNECT_RECV_ID_EVENT:
{
SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
switch(evt->uEventID)
{
case EVENT_SIM_START:
{
hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_6, SIMCONNECT_STATE_ON);
}
break;
case EVENT_6:
{
SIMCONNECT_DATA_INITPOSITION Init;
Init.Altitude = 5000.0;
Init.Latitude = 47.64210;
Init.Longitude = -122.13010;
Init.Pitch = 0.0;
Init.Bank = -1.0;
Init.Heading = 180.0;
Init.OnGround = 0;
Init.Airspeed = 60;
hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_6, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(Init), &Init );
printf("\nEVENT_6 received and data sent");
hr = SimConnect_TransmitClientEvent(hSimConnect, 0, EVENT_7, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
Sleep(25000);
INPUT input[1] = {};
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = VK_LWIN;
UINT test = SendInput(ARRAYSIZE(input), input, sizeof(INPUT));
std::cout << test << std::endl;
Sleep(250);
input[0].ki.wVk = VK_MENU;
test = SendInput(ARRAYSIZE(input), input, sizeof(INPUT));
std::cout << test << std::endl;
Sleep(250);
input[0].ki.wVk = VK_SNAPSHOT;
test = SendInput(ARRAYSIZE(input), input, sizeof(INPUT));
std::cout << test << std::endl;
Sleep(250);
input[0].ki.wVk = VK_LWIN;
input[0].ki.dwFlags = KEYEVENTF_KEYUP;
test = SendInput(ARRAYSIZE(input), input, sizeof(INPUT));
std::cout << test << std::endl;
Sleep(250);
input[0].ki.wVk = VK_MENU;
test = SendInput(ARRAYSIZE(input), input, sizeof(INPUT));
std::cout << test << std::endl;
Sleep(250);
input[0].ki.wVk = VK_SNAPSHOT;
test = SendInput(ARRAYSIZE(input), input, sizeof(INPUT));
std::cout << test << std::endl;
}
break;
default:
break;
}
break;
}
case SIMCONNECT_RECV_ID_QUIT:
{
quit = 1;
break;
}
default:
printf("\nReceived:%d",pData->dwID);
break;
}
}
Does anyone know why this doesn't work? Pressing the keys manually also produces the desired effect. It is only emulated keypresses that do not work.