August 22, 200718 yr Commercial Member Hi all,This problem has been bothering me for a very long time and I was hoping someone here can help me...In my panel I want to capture keyboard inputs for my INS system whilst disabling all keyboard input to FS itself. For that I use the DirectInput example in the Dragonflight tutorial. I can capture the keyboard input, no problem but... I don't succeed to stop FS from also capturing the keyboard.Here's the code, note that I tried using both DISCL_BACKGROUND and DISCL_FOREGROUND but neither does what I want it to do:HRESULT CreateDirectInputDevice( HWND hDlg ){ HRESULT hr; DWORD dwCoopFlags; FreeDirectInput(); dwCoopFlags = DISCL_EXCLUSIVE; dwCoopFlags |= DISCL_BACKGROUND; if( FAILED( hr = DirectInputCreate( GetModuleHandle(NULL), DIRECTINPUT_VERSION, /*IID_IDirectInput, (VOID**)*/&g_pDI, NULL ) ) ) return hr; if( FAILED( hr = g_pDI->CreateDevice( GUID_SysKeyboard, &g_pKeyboard, NULL ) ) ) return hr; if( FAILED( hr = g_pKeyboard->SetDataFormat( c_dfDIKeyboard ) ) ) return hr; hr = g_pKeyboard->SetCooperativeLevel( hDlg, dwCoopFlags ); if( FAILED(hr) ) return hr; g_pKeyboard->Acquire(); return S_OK;} Bj
August 22, 200718 yr Commercial Member You can't take exclusive keyboard control with DirectInput... FS already has the keyboard control interface active before yours. Ed Wilson Mindstar AviationMy Playland - I69
August 22, 200718 yr You would have to hook the actual message loop and intercept the keyboard there (ie. below DirectX). There are a couple of threads that discuss some options other than this too... do a search and you'll find them.Not the easiest thing to do unless you are an advanced windows programmer.
August 24, 200718 yr Commercial Member Hi Guys,I found an example from a fellow programmer using the same technique and it worked for him !I found one big difference in his code opposed to mine however:hr = DirectInputCreate ( ( HINSTANCE ) something.hDll, DIRECTINPUT_VERSION, &pDI, NULL );Notice the first part, ( HINSTANCE ) something.hDll as opposed to me retrieving the instance handle to FS itself. I can't reach the person who created this code so if anyone has any ideas on what he's doing...Bj Bj
August 24, 200718 yr GetModuleHandle(NULL) will return a handle to the .exe process, i.e. FS itself, not your module/gauge.You can call this instead:GetModuleHandle("the_name_of_you_gau_or_dll");Another generic way which works great that I always use now:HMODULE hInst;GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) &Linkage, &hInst);(I use Linkage variable to get an address in my gau/dll, you can use any variable of your code, or a class member variable).Hope this helps!
August 27, 200718 yr Commercial Member Hi Jean-Luc,And will this make the keyboard capture exclusive ?Btw I have found a way to capture the keyboard exclusively by subclassing FS. Not sure if I can post this code though since it was given to me by a fellow programmer and is thus not exactly "my" code.Kind regards,Bj Bj
August 27, 200718 yr No, the code above permits having the actual HMODULE to the gauge/dll calling it, otherwise, what you'd get would be the HMODULE of the calling applicaition, the .exe, i.e. fs9.exe for example.As for subclassing, there are so many source code avail on the net, I don't think this is highly proprietary. I use this myself in a module:// hook to the FS event callbackfsWndHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)fsWndHookProc, hInst, GetCurrentThreadId());// hook to the FS message callbackfsGetMsgHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)fsGetMsgHookProc, hInst, GetCurrentThreadId());////////////////////////////////////////////////////////////////////////// Hook functions////////////////////////////////////////////////////////////////////////LRESULT CALLBACK fsWndHookProc( int nCode, WPARAM wParam, LPARAM lParam){ if (nCode == HC_ACTION) { switch (((CWPSTRUCT *) lParam)->message) { case WM_NCPAINT: MakeMenuRxp(); break; case WM_INITMENU: MakeMenuOption(); break; } } return(CallNextHookEx(fsWndHook,nCode,wParam,lParam));}LRESULT CALLBACK fsGetMsgHookProc(int nCode, WPARAM wParam, LPARAM lParam){ int msgParam; if (nCode == HC_ACTION) { switch (((MSG *)lParam)->message) { case WM_COMMAND: msgParam = LOWORD(((MSG *) lParam)->wParam); switch(msgParam) { // RXP menus case MENURXPWEBSITE: OpenWebPage(_T("http://www.reality-xp.com"));etc.... } } return CallNextHookEx(fsGetMsgHook, nCode, wParam, lParam);}
Create an account or sign in to comment