• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Direct Input

Messages
158
Country
us-northcarolina
Fellow developers,

My project involves an FMC-like gauge. I'm working on the option to allow the player to use his own keyboard to control it vs. clicking on key images on the screen. This involves using DirectX DirectInput, and thanks to the sd2gau28 C gauge writeup, and various tidbits of sample code from around the net I have the input side working fine and dandy, in both FS9 and FSX (even though the sd2gau28 says their technique doesn't work in FSX I think that was for DX3 and we're on DX9 now).

The problem is that the keystrokes also go on into FS too. When the player hits F1 on my gauge to login it works, but the F1 also goes into FS and sets the throttles to zero, and so on.

Does anyone know the magic incantation to temporarily shut off keyboard input to FS so I can intercept the keys all for myself?

I know this can be done...the PMDG 737 FMC does it as does the iFly 747-400 and I'm sure many others.

This same question was asked at least 3 times on the Avsim forums over the last few years and never answered although there were hints this way and that. Someone even said "you can do it but it's complex" and left it at that! Grrrrrr. Don't tease me like that :)

Reassigning keys isn't the answer...I need the whole keyboard or at least the letters, numbers, and function keys.

The only thing I can think of offhand is to hook the FS message loop and intercept keys with WM_KEYDOWN when I want to and allow them through when I'm done.

Any thoughts? Any ideas helpful.

Dutch
 
Last edited:
Indeed hooking the windows messages and intercepting the keyboard is the way to go. In my system I have a DLL module and a gauge, and they communicate thru shared variables. (I'm 98% sure this would work by installing a message hook into a gauge too but I have not verified that.) When the user clicks on the "I want to capture the keyboard" button on the gauge, it sets a bool variable on. The DLL looks for that variable (INT32 Keylock) and when on sends all keys into the bit bucket:

Code:
		case WM_KEYDOWN:
		case WM_KEYUP:
			if (!Keylock) {
				return CallWindowProc(oldWndProc, FS_hWnd, uMsg, wParam, lParam);
			}
			return 0;

The above is in my main message loop inside the DLL. Meanwhile, the keys that are not getting to the FS window because of the above are being read and processed by the DirectInput functions in the gauge!

I use the same technique in the same loop to prevent FS9 from writing over my dialog boxes:

Code:
		case WM_PAINT:
			GetClientRect(hFSimWindow, &rcl);
			ValidateRect(hFSimWindow, &rcl);
			return 0;

This intercepts all WM_PAINT messages and sends them to the bit bucket. (This last was advice from the Peter Dowson FSUIPC support forum -- thanks to those who figured it out there!)

Note this last technique for keeping FS's fingers off your DLL dialogs won't work in FSX. There, you have to use SimConnect to put the thing into "Dialog Mode" and take it back out when you're done.

Hope this helps,
Dutch
 
Last edited:
Hi Dutch,

I just came across your forum entry and I was wondering, how do you subclass the FS window ?

I am also trying to catch keyboard input, I have first used SimConnect but this method is deeply flawed and will only work for a limited number of keyboard definitions, then I tried DirectInput but:

a) the keys seem to hang and I have to reset my dinput connection each time a key is pressed
b) directinput always retrieves keystrokes as if using a Querty keyboard !

So now I'm looking at catching WM_KEYDOWN message but for that I have to subclass the FS window (from a gauge btw).

I understand that I have to use:

Code:
LRESULT CALLBACK A300WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	LRESULT lr = 1;
	
	switch(msg)
	{
			case WM_KEYFIRST:	
				
				switch(wParam)
				{
					case VK_Y: //==> Keycodes here!
					{
						int i = 1;
						//return 0;
					}
					break;

				}
		break;

	}

	return CallWindowProc((WNDPROC)OldWndProc, hwnd, msg, wParam, lParam);
	
}

But where and how do I set up the actual subclassing ? Is this in the

Code:
BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)

and how do I do it ?

Thanks for helping out !
Björn
 
Back
Top