Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detect mouse movement or clicks anywhere in Windows

Posted on 2010-08-23
8
Medium Priority
?
559 Views
Last Modified: 2012-08-14
I'm working on a Touch-Screen app,
I want to have a timer and whenever the mouse moves or clicks I want to reset the timer (after 60 seconds or whatever a flash animation will be launched.)
0
Comment
Question by:rfwoolf
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 13

Assisted Solution

by:aflarin
aflarin earned 600 total points
ID: 33505093
you can intercept mouse messages by setting mouse hook. SetWindowsHookEx function with WH_MOUSE param. Here is samples:

http://delphi.about.com/od/windowsshellapi/a/mousehook.htm
http://en.allexperts.com/q/Delphi-1595/setWindowsHookEx-2.htm
0
 
LVL 13

Author Comment

by:rfwoolf
ID: 33505109
aflarin>
Looks like just what I need.
Thanks :)

Question will remain open a day or two in case.
0
 
LVL 9

Assisted Solution

by:Mahdi78
Mahdi78 earned 300 total points
ID: 33505510
this example allow you to detect move, right up, right down, left up left down and wheel mouse evens

http://www.swissdelphicenter.ch/torry/showcode.php?id=1729
0
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!

 
LVL 14

Assisted Solution

by:DragonSlayer
DragonSlayer earned 200 total points
ID: 33508555
Alternatively, install your application as the screen saver and set the system to launch the screen saver after 60 seconds ;-)
0
 
LVL 13

Author Comment

by:rfwoolf
ID: 33508569
Dragonslayer
Do you know if that would work? Would the screen saver app terminate after mouse input?
0
 
LVL 25

Accepted Solution

by:
epasquier earned 900 total points
ID: 33508599
better yet , there is a windows function that will return the timer when the last mouse or keyboard action occurred.

http://msdn.microsoft.com/en-us/library/ms646302
function MilliSecondsIdle: DWord;
var
 liInfo: TLastInputInfo;
begin
 liInfo.cbSize := SizeOf(TLastInputInfo) ;
 GetLastInputInfo(liInfo) ;
 Result := GetTickCount - liInfo.dwTime;
end;

function SecondsIdle: DWord;
begin
 Result := MilliSecondsIdle Div 1000;
end;

procedure TForm1.tmrIdleTimer(Sender: TObject);
begin
 lblLastInput.Caption:=Format('Last Input %f s',[MilliSecondsIdle/1000]);
end;

Open in new window

0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 33508654
@rtwoolf:
I was just assuming that you wanted your programme to do something if there is a 60 sec inactivity, hence the suggestion to install your app as a screen saver instead.

Once Windows starts your "screen saver", it is up to you what you want to do with it... e.g. setting it to a maximised form and closing it in the OnMouseMove event, etc.
0
 
LVL 25

Assisted Solution

by:epasquier
epasquier earned 900 total points
ID: 33508660
Yes, creating a screen saver application would be the real thing.

Here is a complete example of a Delphi application turned into a screen saver :
http://delphi.about.com/gi/o.htm?zi=1/XJ&zTi=1&sdn=delphi&cdn=compute&tm=25&f=22&tt=14&bt=1&bts=1&zu=http%3A//www.mindspring.com/~cityzoo/scrnsavr.html

Important things :
- how the app is detected by windows as being a Screen Saver : simply by putting it in \Windows directory and changing its extension to .SCR
- how Windows get the display name (for the control panel) : with a simple compiler directive
{$D SCRNSAVE My Delphi Screen Saver Name}
- how the application knows when launched that it must execute the screen saver or simply configure it : with a different command line parameter , "/s" for active mode and "/c" for configuration mode

other things explained in this example are more trivial, and you can read it or take the full source as a basis for yours
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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