Solved

Detect mouse movement or clicks anywhere in Windows

Posted on 2010-08-23
8
533 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

624 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