Jump to content
  • Advertisement
Sign in to follow this  
darkhydro

DX11 Windows key hook suddenly stops working in DX11 game

This topic is 2508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am creating a DX11 game and am using a low-level windows key hook to capture Alt+Enter so that I can toggle fullscreen using my own methods instead of having Windows do it automatically, which inevitably causes problems. A description of this process and details are available in the linked question. My problem is that the key hook consistently stops working after the 6th Alt+Enter for some reason. I am not unregistering it myself.

Here is the key hook code:


LRESULT _stdcall MyClass::WindowsKeyHook( s32 nCode, WPARAM wParam, LPARAM lParam ) {
printf("Key hook called, nCode: %d. ", nCode);
if( nCode < 0 || nCode != HC_ACTION ) { // do not process message
return CallNextHookEx( MyClassVar.GetWindowsKeyHook(), nCode, wParam, lParam );
}
printf(" Key hook status ok.\n");

BOOL bEatKeystroke = FALSE;
KBDLLHOOKSTRUCT* p = ( KBDLLHOOKSTRUCT* )lParam;
switch( wParam ) {
//NOTE: Alt seems to be a system key when it is PRESSED, but a regular key when it is released...
case WM_SYSKEYDOWN:
if(p->vkCode == VK_MENU || p->vkCode == VK_LMENU || p->vkCode == VK_RMENU) {
MyClassVar.SetAltPressed(TRUE);
}
if(MyClassVar.IsAltPressed() && p->vkCode == VK_RETURN) {
bEatKeystroke = TRUE;
MyClassVar.SetAltEnterUsed(TRUE);
printf("Alt+Enter used.\n");
}
break;
case WM_SYSKEYUP:
//NOTE: releasing alt+enter causes a SYSKEYUP message with code 0x13: PAUSE key...
break;
case WM_KEYDOWN:
break;
case WM_KEYUP: {
if(p->vkCode == VK_MENU || p->vkCode == VK_LMENU || p->vkCode == VK_RMENU) {
MyClassVar.SetAltPressed(FALSE);
}
bEatKeystroke = ( !MyClassVar.IsShortcutKeysAllowed() &&
( p->vkCode == VK_LWIN || p->vkCode == VK_RWIN ) );
break;
}
}

if( bEatKeystroke ) {
return 1;
}
else {
return CallNextHookEx( MyClassVar.GetWindowsKeyHook(), nCode, wParam, lParam );
}
}



If you need more information, just tell me what is needed. I have no idea why this is happening, so I'm not sure what kind of information I need to provide. The only way to get rid of a key hook besides unregistering it explicitly is if Windows times it out, as far as I know. All MyClassVar methods are inline to be as fast as possible, and Alt+Enter is handled from a separate thread.

This question is also posted on http://stackoverflow...ok-stop-working

Share this post


Link to post
Share on other sites
Advertisement
You don't need a keyboard hook to handle Alt-Enter...just handle WM_SYSKEYDOWN and disable automatic DXGI Alt-Enter handling (call IDXGIFactory::MakeWindowAssociation and pass DXGI_MWA_NO_ALT_ENTER).

Share this post


Link to post
Share on other sites
I tried this. It doesn't seem to work at all. Alt+Enter is still enabled. The only way I've been able to reliably disable Alt+Enter is with a Windows key hook.

Share this post


Link to post
Share on other sites
Scratch that. You have to move MakeWindowAssosciation to AFTER swap chain creation. It seems creating the swap chain calls MakeWindowAssosciation internally with default values. All is well!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!