...skip Keyboard and Mouse messages in the own Application?

Author: P. Below

Category: Misc

{
 Connect a handler to the Application.OnMessage event.
 You have to do this in code:
}

  
private
    procedure 
AppOnMessage(var Msg: TMsg; var Handled: Boolean);
    { Private declarations }
  
public
    
{ Public declarations }
  
end;
  
var
  
Form1: TForm1;

implementation

{$R *.dfm}

var
  
FConnected: Boolean;

procedure TForm1.AppOnMessage(var Msg: TMsg; var Handled: Boolean);
begin
  if 
FConnected then
    case 
Msg.Message of
      
WM_KEYFIRST..WM_KEYLAST,     // Keyboard events
      
WM_MOUSEFIRST..WM_MOUSELAST: // Mouse events
        
Handled := True
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  
Application.OnMessage := AppOnMessage;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  
Application.OnMessage := nil;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
FConnected := True;
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base