Solved

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

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Base1 Encode/Decode 3 85
DBGrid or StringGrid ? 6 119
Problem working with dynamic array - help 2 35
TlistView is Really heavy on Android 3 11
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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