Detecting keyboard or mouse-click across entire application

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?
Andy BrownDeveloperAsked:
Who is Participating?
 
als315Connect With a Mentor Commented:
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
0
 
Andy BrownDeveloperAuthor Commented:
That was the conclusion I came to also.  Thanks for your help.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
1
 
Dale FyeCommented:
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
1
 
Andy BrownDeveloperAuthor Commented:
Thank you everyone - I'll give it a try.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.