Solved

Detect mouse movement or clicks anywhere in Windows

Posted on 2010-08-23
8
510 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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