Detecting keyboard or mouse-click across entire application

Andy Brown
Andy Brown used Ask the Experts™
on
I have an Access application and want to run a function called IdleLogoutSet(), if the keyboard or mouse is pressed in any of the forms.  Is there an easy way to do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You should add your sub to all forms and to all buttons. Events could be: Form_KeyPress and Form_MouseDown.
Look at small sample
DbKM.accdb
Andy BrownDeveloper

Author

Commented:
That was the conclusion I came to also.  Thanks for your help.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
Andy, there is a shortcut for what your trying to do (I think), which is to use ActiveForm and Active Control:

https://msdn.microsoft.com/en-us/vba/access-vba/articles/detect-user-idle-time-or-inactivity

Jim.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Agree with Jim.

When I have a need to check for application idle, I usually put the code in the timer event of a startup form, which gets hidden shortly after startup.  This timer event checks for ActiveForm, and ActiveControl, and if the Active control is a subform, it checks drills down until the ActiveControl refers to a control.  If either the ActiveForm.Name or the ActiveControl.Name retrieved from this process is not equal to the value stored in the timer event, it resets the idle time counter and the strActiveForm and strActiveControl variable values.

This avoids having to put code in every form and control.

Dale
Andy BrownDeveloper

Author

Commented:
Thank you everyone - I'll give it a try.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial