Solved

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

Posted on 2001-07-17
4
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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
Connection between libmysql.dll and MySQL Versions 7 130
Correct Component for Shopping Cart. 2 132
Dev express lookupcombo 3 63
Firemonkey Queue list 1 50
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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