Solved

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

Posted on 2001-07-17
4
144 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SIM number for APK using Delphi 10 2 363
build html 5 client that connect to indy Tidtcpserver 3 303
Working with hours 3 31
LAN or WAN ? 11 66
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

12 Experts available now in Live!

Get 1:1 Help Now