?
Solved

emulate mouse click

Posted on 2006-04-30
9
Medium Priority
?
210 Views
Last Modified: 2010-04-05
hi

how would i detect if a mouse button is pressed

so i can the use it like this

function mouseclick  //boolean i suppose as need true or false
////some code here

end;


if mouseclicked the begin
showmessage('mouse clicked');
//do something
end;

thanks pete
0
Comment
Question by:peter2001
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:A. Cristian Csiki
ID: 16572597
there are several exemples on torry's page:

private
  procedure WMNCRBUTTONDOWN(var msg: TMessage); message WM_NCRBUTTONDOWN;
  procedure WMNCLBUTTONDOWN(var msg: TMessage); message WM_NCLBUTTONDOWN;
  procedure WMNCLBUTTONDBLCLK(var msg: TMessage); message WM_NCLBUTTONDBLCLK;
end;



implementation


procedure TForm1.WMNCRBUTTONDOWN(var msg: TMessage);
begin
  if msg.wParam = HTCAPTION then Caption := 'Right Click!';
  // Message.Result := 0; {to ignore the message}
  inherited;
end;

procedure TForm1.WMNCLBUTTONDOWN(var msg: TMessage);
begin
  if msg.wParam = HTCAPTION then Caption := 'Left Click!';
  // Message.Result := 0; {to ignore the message}
  inherited;
end;

procedure TForm1.WMNCLBUTTONDBLCLK(var msg: TMessage);
begin
  if msg.wParam = HTCAPTION then Caption := 'Double Click!';
  // Message.Result := 0; {to ignore the message}
  inherited;
end;
0
 
LVL 1

Author Comment

by:peter2001
ID: 16572653
hi

what i need is a function to check to see if the mouse has been clicked and if it has set the result to true (i assume) so i can use it like this


if mouseclicked the begin
showmessage('mouse clicked');
//do something
end;

is this possible?

0
 
LVL 28

Expert Comment

by:2266180
ID: 16573381
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:peter2001
ID: 16573476
hi

i looked at that link but still can not see how i would do it

i don't want to click the mouse i just want to detect if the a mouse button was pressed

thanks for your help


pete
0
 
LVL 11

Accepted Solution

by:
A. Cristian Csiki earned 320 total points
ID: 16573529
0
 
LVL 28

Expert Comment

by:2266180
ID: 16573940
you don't have to click the mouse. just call the function (it's an api function declared in user32.dll). for example:
http://www.swissdelphicenter.ch/torry/showcode.php?id=360
0
 
LVL 28

Expert Comment

by:2266180
ID: 16573959
ok, after re-reading your question, I see that indeed I got it wrong from the beging. sorry. it's mouse hooks you're looking for and nodramus has given you the correct link for system-wide detection
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 16574021
Why not just put code within the Application Messages to check for a mouse click

procedure AppMessages(var Msg: TMsg; var Handled: Boolean);

procedure TForm1.AppMessages(var Msg: TMsg; var Handled: Boolean);
begin
  // check which messages are to be processed
  case msg.message of
    // mouse events.
    WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN: begin

    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // capture the messages
  Application.OnMessage := AppMessages;
end;
0
 
LVL 1

Author Comment

by:peter2001
ID: 16574116
thanks alot
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Screencast - Getting to Know the Pipeline
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

569 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