?
Solved

Mouse and keyboard

Posted on 1998-12-27
3
Medium Priority
?
290 Views
Last Modified: 2013-11-20
I want to write an application which receives all mouse- and keyboard-messages and decides whether let them through to the destination window or throw it. Any sample-code would be very helpfull.
0
Comment
Question by:joker1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1326747
Looks like you need to use

SetWindowsHookEx

The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the system.

HHOOK SetWindowsHookEx(
  int idHook,        // type of hook to install
  HOOKPROC lpfn,     // address of hook procedure
  HINSTANCE hMod,    // handle to application instance
  DWORD dwThreadId   // identity of thread to install hook for
);

Consider looking it up in the help file for additional information.  If you have questions, please ask.
0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 1326748
tresher_shark is absolutely right concerning 'SetWindowsHookEx()'. This is an example on how to implement it:
This is a system wide message hook (see 'SetWindowsHookEx()' and 'WH_GETMESSAGE', the hook has to reside in a DLL)
LRESULT CALLBACK HookProc   (   int     nCode,  // hook
code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;
    MSG     msg;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (   /* ... check whether it's a mouse message */
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_MOUSEFIRST,
                            WM_MOUSELAST,
                            PM_NOREMOVE
                        )
        )
        {
            /* appropriate action, e.g. suppress msg by removing it /*
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_MOUSEFIRST,
                            WM_MOUSELAST,
                            PM_REMOVE
                        );
        }

 
}
0
 

Author Comment

by:joker1
ID: 1326749
I tried this out. First I used WH_KEYBOARD Hook and installed a hook which received only keyboardevents sent to the current application (the hook-procedure isn't located in a dll). This worked fine, but after another application received keyboard-input, the hook didn't work (even if the "hook-application" got the focus back). - Any ideas why?

I also tried WH_KEYBOARD_LL. With this hook I am able to receive keyboardevents of ALL applications (the hook-procedure isn't located in a dll too). This works fine, but only with WinNT.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question