Solved

Detect mouse movement or clicks anywhere in Windows

Posted on 2010-08-23
8
505 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 150 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 75 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
 
LVL 14

Assisted Solution

by:DragonSlayer
DragonSlayer earned 50 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 225 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 225 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now