Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 299737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:51:01+00:00 2026-05-12T06:51:01+00:00

The below code will block all the keyboard shortcuts. Since i wanted to implement

  • 0

The below code will block all the keyboard shortcuts. Since i wanted to implement this in my main application. I created a .dll out of the below code.
After i included the .dll as reference to my main application, i started the application.
It is working fine in the begining. Then if i do some other stuffs and then check the shorcut, it is not disabled, which my .dll has to do always, untill the .exe for my main application is terminated.

Why my .dll is not disabling the shortcuts after some time ?

source code for calling .dll from Program.cs :


using DisableHotKeys;


public static class Program
{  
    public static DisableKeys disableKeysInstance = new DisableKeys(); 

    [STAThread]
    static void Main()
    {
        disableKeysInstance.DisableKeyboardHook();
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(Screensaver.ScreensaverRef); 
    }

}

Source code of .dll :


namespace DisableHotKeys
{

    public class DisableKeys
    {
        private delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
        [DllImport("user32.dll", EntryPoint = "SetWindowsHookExA", CharSet = CharSet.Ansi)]
        private static extern int SetWindowsHookEx(int idHook,     LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId);
        [DllImport("user32.dll")]
        private static extern int UnhookWindowsHookEx(int hHook);
        [DllImport("user32.dll", EntryPoint = "CallNextHookEx", CharSet = CharSet.Ansi)]
        private static extern int CallNextHookEx(int hHook, int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
        const int WH_KEYBOARD_LL = 13;
        private int intLLKey;

        private struct KBDLLHOOKSTRUCT
        {
            public int vkCode;
            int scanCode;
            public int flags;
            int time;
            int dwExtraInfo;
        }
        private int LowLevelKeyboardProc(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam)
        {
            bool blnEat = false; switch (wParam)
            {
                case 256:
                case 257:
                case 260:
                case 261:
                    //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key                           
                    if (((lParam.vkCode == 9) && (lParam.flags == 32)) ||
                        ((lParam.vkCode == 27) && (lParam.flags == 32)) ||
                        ((lParam.vkCode == 27) && (lParam.flags == 0)) ||
                        ((lParam.vkCode == 91) && (lParam.flags == 1)) ||
                        ((lParam.vkCode == 92) && (lParam.flags == 1)) ||
                        ((true) && (lParam.flags == 32)))
                    {
                        blnEat = true;
                    }
                    break;
            } if (blnEat) return 1; else return CallNextHookEx(0, nCode, wParam, ref lParam);
        }
        public void DisableKeyboardHook()
        {
            intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, new LowLevelKeyboardProcDelegate(LowLevelKeyboardProc), System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32(), 0);
        }
        private void ReleaseKeyboardHook()
        {
            intLLKey = UnhookWindowsHookEx(intLLKey);
        } 
    } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:51:01+00:00Added an answer on May 12, 2026 at 6:51 am

    What other code does your application do?

    When using WH_KEYBOARD_LL your hook is required by the system to process the message it gets within a certain time frame (specified in the registry: KEY_CURRENT_USER\Control Panel\Desktop\LowLevelHooksTimeout) – if it fails to do so, the system will simply call the next hook in the chain. So make absolutely certain that whatever other code you have is pumping messages at the highest priority.

    Try setting the registry value up and test if that helps – if it does you know that your code needs to respond faster to the hook switch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, The VBA code below will create an Excel QueryTable object and display it
Will the code below work if the clock on the server is ahead of
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
In the below code sample, what does {0:X2} mean? This is from the reflection
I have a block of code that runs within a TransactionScope and within this
When running the below code a type is never returned, despite there being a
In the below code snippet can i replace char * to const char *
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
In the below code, the ListBox gets filled with the names of the colors
I would like to know how to modify the below code to strip =20

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.