Jump to content
Sign in to follow this  
Guest JeanLuc_

Exclusive keyboard capture with DINPUT not working

Recommended Posts

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;}


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites

You can't take exclusive keyboard control with DirectInput... FS already has the keyboard control interface active before yours.


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

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.

Share this post


Link to post
Share on other sites

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


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites
Guest JeanLuc_

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!

Share this post


Link to post
Share on other sites

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


simcheck_sig_banner_devteam.jpg

 

Bj

Share this post


Link to post
Share on other sites
Guest JeanLuc_

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);}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...