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 8011813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:07:33+00:00 2026-06-04T19:07:33+00:00

The following snippet is meant to display the message when the user types a

  • 0

The following snippet is meant to display the message when the user types a key. Even when the focus is not on the application. But there seems to be a problem with the following code. It doesn’t call the function registered in the hook-chain with the windows. I guess the problem is with HINSTANCE hInst. How should I modify the below code so that I am able to see the message as the user taps a key.

// Global Variables
static HHOOK handleKeyboardHook = NULL;
HINSTANCE hInst = NULL;

void TestKeys_setWinHook // i call this function to activate the keyboard hook
  (...) {
    hInst = GetModuleHandle(NULL);
    handleKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInst, 0); // LowLevelKeyboardProc should be put in the hook chain by the windows,but till now it doesn't do so.
    printf("Inside function setWinHook !");
}

// the following function should be called when the user taps a key.

static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
  printf("You pressed a key !\n");
  return CallNextHookEx(handleKeyboardHook, nCode, wParam, lParam);
}

But the windows doesn’t call the function LowLevelKeyboardProc. I don’t understand the reason but I am sure that the problem is with hInst in the hook function. How do i need to initialize it ?

Till now, output that I see is Inside function setWinHook !

  • 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-06-04T19:07:34+00:00Added an answer on June 4, 2026 at 7:07 pm

    Here’s an example of a LowLevelKeyboardProc.

    HHOOK hHook;
    
    LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
    {
        printf("You pressed a key!\n"); 
        return CallNextHookEx(hHook, nCode, wParam, lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
      hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0);
      MSG msg;
      while(GetMessage(&msg, NULL, 0, 0))
      {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      return msg.wParam;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following snippet is not working for me. Basically I want to check if
I have the following snippet of jQuery: $(elementId).prevAll().appendTo(prevDiv); It works but the problem is
In the following code snippet (meant to work in an init.d environment) I would
Following snippet attempts to write the name of directories and files present in some
The following snippet from RuntimeUtil.java from jlibs guarantees GC that garbage collection is done.
I first implemented the following snippet to show a hi alert and do a
Consider the following snippet of code: foreach (var setting in RequiredSettings) { try {
I wrote the following snippet in order to handle errors. (Page.php gets included in
I've got the following snippet of code and its all working, and bringing in
I have the following snippet of code: import csv def has_header(first_lines): sniffer = csv.Sniffer()

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.