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

x
?
Solved

Detect mouse movement or clicks anywhere in Windows

Posted on 2010-08-23
8
Medium Priority
?
542 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

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!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
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