Autor Beitrag
joelrodrigues
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20



BeitragVerfasst: Mo 01.01.07 13:40 
Hi folks,

I am developing an application that captures Keyboard keys pressed and mouse actions and display them on the screen ... For this, i have two hooks (WM_KEYBOARD and WM_MOUSE), each one in its own DLL (MouseHook.dll and KeyHook.dll).


MouseHook has the following procedure:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
// declaration
procedure OnMouseEvent(Sender: TObject; AMouseStates: TMouseStates);

// implementation
procedure TForm1.OnMouseEvent(Sender: TObject; AMouseStates: TMouseStates);
begin
  if ((AMouseStates.ButtonInfo = WM_LBUTTONDOWN)) then
  begin
    Label1.Caption := 'Left Mouse Button pressed';
  end;
end;



KeyHook has the following procedure:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
// declaration
procedure OnKeyPressed(Sender: TObject; AKeyStates: TKeyStates; AKeyNames: TKeyNames);

// implementation
procedure TForm1.OnKeyPressed(Sender: TObject; AKeyStates: TKeyStates; AKeyNames: TKeyNames);
begin
  if AKeyStates.KeyDown then   // i need check if the (AMouseStates.ButtonInfo = WM_LBUTTONDOWN)
  begin
    Label1.Caption := 'Key Pressed';
  end;
end;



I need change the Label1.Caption to "Key Pressed and Left Mouse Button pressed" when the user press a key and the left mouse button simultaneously.

So, i am trying change the line "if AKeyStates.KeyDown then" (inside the OnKeyPressed procedure) to something like this:


KeyHook has the following procedure:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
// declaration
procedure OnKeyPressed(Sender: TObject; AKeyStates: TKeyStates; AKeyNames: TKeyNames);

// implementation
procedure TForm1.OnKeyPressed(Sender: TObject; AKeyStates: TKeyStates; AKeyNames: TKeyNames);
begin
  if (AKeyStates.KeyDown) and (AMouseStates.ButtonInfo = WM_LBUTTONDOWN) then   // line changed
  begin
    Label1.Caption := 'Key Pressed and Left Mouse Button pressed';
  end;
end;




But, when i changed that line, Delphi says: "Undeclared identifier: 'AMouseStates' ...

What´s wrong with my code?


Any help or comments will be deeply appreciated.

Best regards and happy new year...

JOEL RODRIGUES

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 01.01.07 13:50 
'AMouseStates' is only declared in the procedure:
ausblenden Delphi-Quelltext
1:
procedure TForm1.OnMouseEvent(Sender: TObject; AMouseStates: TMouseStates);					

So you have to save the MouseState in another variable:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
// implementation

var LeftMouseDown: boolean;
procedure TForm1.OnMouseEvent(Sender: TObject; AMouseStates: TMouseStates);
begin
  if ((AMouseStates.ButtonInfo = WM_LBUTTONDOWN)) then
  begin
     Label1.Caption := 'Left Mouse Button pressed';
     LeftMouseDown := true;
  end
  else LeftMouseDown := false;
end;

So you can check if the left mouse button is pressed:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// implementation
procedure TForm1.OnKeyPressed(Sender: TObject; AKeyStates: TKeyStates; AKeyNames: TKeyNames);
begin
   if (AKeyStates.KeyDown) and (LeftMouseDown = true) then
   begin
     Label1.Caption := 'Key Pressed';
   end;
end;

Hope that is helpful. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
joelrodrigues Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 20



BeitragVerfasst: Mo 01.01.07 14:17 
OH, so fast!!! That´s why i appreciated german programmers! (Crytek rules! :)

Ich denke nicht Deutsche aber ich will warum you are really good programmers!

Thanks very much MARCO D!