Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 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