Thread: disabling system keys in a windows console

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    disabling system keys in a windows console

    Does anybody know anything about this?

    I'm on Win98 SE using gcc and I need to know if there's a way to disable alt+space while my program is running. It can't be done by using PIF / program property files. For one, this is disabled for me, for two it's just better that way as when you do it with code it ensures it will work. The program is doing it and it's not dependant on a file.
    The world is waiting. I must leave you now.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    You need to setup a Windows low-level keyboard hook and capture the keypresses there. Here is example code:

    Code:
    LRESULT CALLBACK LowLeveKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
        if(nCode == HC_ACTION)
        {
        	int eatKeyPress = 0;
        	
            switch(wParam)
            {
            case WM_KEYDOWN:
            case WM_KEYUP:
            case WM_SYSKEYDOWN:
            case WM_SYSKEYUP:
                {
                    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
    
                    // capture alt space
                    if(p->vkCode == VK_SPACE && (p->flags & LLKHF_ALTDOWN))
                    {
                       eatKeyPress = 1;
                    }
                    break;
                }
            }
        }
    
        return(eatKeyPress ? 1 : CallNextHookEx(NULL, nCode, wParam, lParam));
    }
    
    int main(void)
    {
    	SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(0), NULL);
    	printf("While this app is running, alt+space is disabled");
    	char c = getchar();
    	return(1);
    }
    i havent' compiled it, but it should give you an idea of the kind of thing you need to do... if it doesn't work, play and fiddle with it til it does!

    good luck
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Can you refer me to a Windows Hooks tutorial, web page, document or the like?
    Possibly where you learned how to use them.

    I have searched for it, and this is a problem that's been bugging me for a few months.
    The world is waiting. I must leave you now.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Look at MSDN... search for HOOK tutorials and articles in there.

    BTW, manners will help you get help in the future!
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. One process with two console windows
    By siavoshkc in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2009, 04:13 PM
  2. Console C++ to full Windows
    By foxon177 in forum Windows Programming
    Replies: 5
    Last Post: 05-12-2008, 09:37 PM
  3. console screen (Windows)
    By hakan in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2008, 06:35 AM
  4. Windows apps verses Console apps
    By nano78 in forum Windows Programming
    Replies: 8
    Last Post: 09-22-2007, 03:41 AM