Board index » delphi » Intercept Windows Messages ... all or one by one

Intercept Windows Messages ... all or one by one

Hello All:

    I live a estrange experience. I want to detect mouse and keyboard
activities in my application (to set
some variables).
    If I try to manage the messages separately I dont have any results...
(***************************************************************************
*)
  TBlockForm = class(TForm)
    ....
  private
    procedure AppKeyDown(Msg: TMessage); message WM_KEYDOWN;
    procedure AppMouseMove(Msg: TMessage); message WM_MOUSEMOVE;
    ...

procedure TBlockForm.AppKeyDown(Msg: TMessage);
Begin
    Beep;
End;

procedure TBlockForm.AppMouseMove(Msg: TMessage);
Begin
    Beep;
End;
(***************************************************************************
*)
Only works when I trap all the messages...
(***************************************************************************
*)
procedure TBlockForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
     Case msg.message of
     WM_KEYFIRST..WM_KEYLAST: Beep;
     WM_MOUSEFIRST..WM_MOUSELAST: Beep
End;
     Handled:= False;
end;
(***************************************************************************
*)
Does Anybody know why?
Or is a bad implementation with the messages separately?

Thanks in advance
Cristian.

 

Re:Intercept Windows Messages ... all or one by one


Quote
In article <3cdac2ba_1@dnews>, Cristian Zujew wrote:
>     I live a estrange experience. I want to detect mouse and keyboard
> activities in my application (to set some variables).
>     If I try to manage the messages separately I dont have any results...
> (***************************************************************************
> *)
>   TBlockForm = class(TForm)
>     ....
>   private
>     procedure AppKeyDown(Msg: TMessage); message WM_KEYDOWN;
>     procedure AppMouseMove(Msg: TMessage); message WM_MOUSEMOVE;

This declares message handlers for your form only, so these methods will only
get messages that are send to your form, not messages send to any controls on
the form or to other forms in your application.

The only point where you can trap all mouse and keyboard messages going to
your application is the Application.OnMessage event.

Quote

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Other Threads