Jump to content
  • Advertisement
Sign in to follow this  
wyrzy

Trapping Key Presses

This topic is 4651 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

Does anyone know how to trap a key press in a console window? I'm trying to prevent the user of my application from pressing ALT-ENTER and switching to fullscreen. The reason I don't want to let the user switch into fullscreen mode is I'm using a custom font that only works in window mode. Any help or suggestions are greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
hmm i haven't tried this yet, but what i'd try first is
using the console function GetConsoleWindow to retrieve
the handle of the console window, and then subclass it.
hopefully it uses the WM_SYSKEYDOWN/WM_KEYDOWN messages
etc and you can override that. worth a try. it should
work as ur subclass and the console are in the same
process.

Share this post


Link to post
Share on other sites
Quote:
Original post by yadango
hmm i haven't tried this yet, but what i'd try first is
using the console function GetConsoleWindow to retrieve
the handle of the console window, and then subclass it.
hopefully it uses the WM_SYSKEYDOWN/WM_KEYDOWN messages
etc and you can override that. worth a try. it should
work as ur subclass and the console are in the same
process.

I could just use "SetWindowLong()" or "SetWindowLongPtr()" inorder to subclass the window, right?

Share this post


Link to post
Share on other sites
I found a subclassing example on MSDN, but it doesn't seem to be working for me. Is there something wrong with my code?

WNDPROC wpOrigEditProc;

// Subclass procedure
LRESULT APIENTRY SubclassProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
if (uMsg == WM_SYSKEYDOWN)
if( wParam == VK_TAB )
return 1;

return CallWindowProc(wpOrigEditProc, hwnd, uMsg,
wParam, lParam);
}

//at the beginning of the program
wpOrigEditProc = (WNDPROC) SetWindowLong(HWND_CONSOLE,
GWL_WNDPROC, (LONG) SubclassProc);



I set a break point in "SubclassProc", but my program never reaches it. Any suggestions?

Share this post


Link to post
Share on other sites
Hmmm just tried it myself and i see that SetWindowLong returns
the "Invalid index" error code when inputting the console window.
So I guess subclassing the console window is out of the question.
I'm at a loss now, but I'm curious to know too so I think I'll
throw this question to someone who might know.

Share this post


Link to post
Share on other sites
I think what you're trying to do is impossible. You can only subclass windows which belong to the same process you're subclassing from, and I'm guessing console windows don't fall into that category since more than one process can be attached to the same one.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yeah, the responses i'm getting from the microsoft ui
newsgroups pretty much say the same thing. impossible.
though some said you might want to try WH_KEYBOARD_LL
hooking.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!