Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Keyboard & Mouse delay

Posted on 1999-06-30
7
Medium Priority
?
338 Views
Last Modified: 2010-08-05
I wrote a program with some buttons, what i want to do is
if user not press(no matter use mouse or keyboard) those buttons within 2 mins, the program will automatically closed.

Sample code needed.

Thanks & Rgds

Shekou
0
Comment
Question by:shekou
[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
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 400 total points
ID: 1385617
Hi Shekou,

Drop a TTimer component on the form.  Set its Interval to 120000.  In its OnTimer event, put a Close statement.

In your buttons' OnClick even, add this:

   Timer1.Enabled := False;

This will stop the timer event from firing if the button is pressed.


Hope this helps,

Cheers,


Stuart
0
 

Expert Comment

by:pbaw
ID: 1385618
One way of doing this is to use the onEnter event on the buttons to set a flag for a timer to use to see if it should terminate the program.  You should use the OnEnter event because you can do other things to a button e.g. double click,  drag and drop etc.

This can be done directly or as in the example below you can create a new button from Tbutton and override the DoEnter method to set a property flag if the button is used.  Use the New Component option in the component menu.

unit myButton;

interface

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

type
  TmyButton = class(TButton)
  private
    { Private declarations }
    FModified : boolean;
  protected
    { Protected declarations }
    procedure DoEnter; override;

  public
    { Public declarations }
  published
    property Modified: boolean
      read FModified write FModified;
     { Published declarations }
  end;

procedure Register;

implementation


procedure TmyButton.DoEnter;
begin
  inherited;
  FModified := TRUE;
end;

procedure Register;
begin
  RegisterComponents('xxxx', [TmyButton]);
end;

end.


1.  Use the new buttons on your form.

2.Place a timer on the main form.  In the OnTimer event place the following.  Remember to set the interval to 2000 (2 seconds)

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if myButton1.Modified Then Application.Terminate;
  Timer1.Enabled := false; // only do this once
end;


Regards
Peter
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385619
Peter,

Thats basically what I have posted, except there is no component modification and it about 30 lines shorter :)

Stu.
0
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!

 

Expert Comment

by:pbaw
ID: 1385620
Hi Stu,

This is the first time I've been here.  I thought that my post was a bit more complete and instructive- but essentially you are right.

Is there any ettiquette to observed here?  I do not wish to offend anyone.

Please reply to pbaw@pacific.net.sg

Regards
Peter
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385621
Hi Peter,

I think just common courtesy is sufficient.  I think there is actually a section on here somewhere about ettiquette - but I dont know for sure.  Things have changed a lot in 3 years :)

The only reason I responded the way I did was to defend my proposed answer.  Quite often I have given the basics for solving a problem, only to have the answer rejected and the points awarded to someone else just because they added a line or two of extra code.

I hope you dont think I was being rude (and besides, it was almost 1:30 AM in Australia when I wrote that too <G>).

Welcome to our little community anyway!  I really hope you enjoy yourself here.  Its a great place to meet people and thrash out ideas.

All the best,

Stuart.
0
 

Author Comment

by:shekou
ID: 1385622

Thank you all very much

0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1385623
Thank you, shekou.

Stuart.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

670 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