Solved

How differentiate use 'mouse'  click the button or use 'enter'  press the button?

Posted on 2001-07-17
4
145 Views
Last Modified: 2010-04-06
hi,dear experts,now I need your kind help very much.The question is as follows:
   When I did a little program,the 'showmessage' box was used.You see,there exists a 'confirm' button on the showmessage box,now,I want to differentiate if the user click the confirm button with mouse or use 'enter' to press the button?What shall I do?
    Hope to hear from you soon.Thank you for your viewing.
     
0
Comment
Question by:bingohua
4 Comments
 
LVL 6

Expert Comment

by:MannSoft
ID: 6289198
I think you would probably have to create your own custom message box and use it in place of ShowMessage.  Then you would know if the mouse or keyboard was used to press the button by watching its OnKey* and OnMouse* events for that object.
0
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 6289239
Hi,
One label and one button on a form. IsMouse boolean variable stores the last user action (mouse or keyboard)

Regards, Geo

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure AppOnMessage(var Msg: TMsg; var Handled: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  IsMouse : boolean = true;

implementation

{$R *.DFM}

procedure TForm1.AppOnMessage(var Msg: TMsg; var Handled: Boolean);
begin
  { if keyboard or left mouse btn is used }
  if Msg.Message = WM_LBUTTONUP then begin
    IsMouse := true;
  end else begin
    IsMouse := false;
  end;
  Handled := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('hello');
  if IsMouse then
    Label1.Caption := 'Mouse'
  else
    Label1.Caption := 'Keyboard';
end;

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

end.
0
 

Expert Comment

by:Yunoshev
ID: 6289294
Either write your own custom message box or use subclassing.....
0
 

Author Comment

by:bingohua
ID: 6289544
Thank you for your instant help.
Best regards.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now