CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1

    Any way to disable the 'Print Screen' key?

    Is there a way to disable the 'Print Scrn' key to prevent screen capturing?

  2. #2
    Join Date
    Jun 2003
    Posts
    91
    Yep there sure is a way to disable the print screen key. You can do it using low level keyboard hooks. Here is the code to disable the print screen key.

    Hope this helps!

    Cheers,
    Greg

    BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
    typedef UINT (CALLBACK* LPREGISTERSERVICEPROC)(DWORD,DWORD);

    HHOOK hhkLowLevelKybd;

    LRESULT CALLBACK LowLevelKeyboardProc(int nCode,
    WPARAM wParam, LPARAM lParam) {

    BOOL fSuppressKeystroke = FALSE;

    if (nCode == HC_ACTION) {
    switch (wParam) {
    case WM_KEYDOWN: case WM_SYSKEYDOWN:
    case WM_KEYUP: case WM_SYSKEYUP:
    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
    fSuppressKeystroke = ((p->vkCode == VK_SNAPSHOT));
    break;
    }
    }
    return(fSuppressKeystroke ? 1 : CallNextHookEx(NULL, nCode, wParam, lParam));
    }


    //Call this when you want to start capturing the printscreen key
    hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0);


    //call this to stop disabling the print screen key
    UnhookWindowsHookEx(hhkLowLevelKybd);

  3. #3
    Join Date
    Nov 2003
    Posts
    22
    a perfect answer!

  4. #4
    Thanks for the help.

    The code is for NT/2K/XP, how about Win9x ?

    I changed the parameter from WH_KEYBOARD_LL to WH_KEYBOARD and it doesn't work in Win9x.
    Last edited by Kurosan; November 13th, 2003 at 05:08 AM.

  5. #5
    Join Date
    Jun 2003
    Posts
    91
    oooh... windows9x...

    I am at work right now, and we don't have any windows 9x boxes around here anymore

    I have some win 9x machines at home, so when I get home I will try to see if I can get you a solution for win 9x.

    Cheers,
    Greg

  6. #6
    Join Date
    Jun 2003
    Posts
    91
    I haven't tried it yet, but to disable the print screen key in windows 98 you might try registering that key as a hotkey and just make it do nothing.

    You could check out this article
    http://www.codeproject.com/system/nishhotkeys01.asp

    Cheers,
    Greg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured