[AccessD] shutting down

Drew Wutka DWUTKA at Marlow.com
Mon Dec 17 12:21:46 CST 2007


Put in a module (mine's called modCallBacksForMouseAndKeyboard):

Option Compare Database
Option Explicit
Public gblCurrentKBHookID As Long
Public gblCurrentMouseHookID As Long
Public gblLastActivityTime As Date
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As
Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Type MOUSEHOOKSTRUCT
    pt As POINTAPI
    hwnd As Long
    wHitTestCode As Long
    dwExtraInfo As Long
End Type
Public Function MouseCallbackProc(ByVal intCode As Integer, ByVal wParam
As Long, lParam As MOUSEHOOKSTRUCT) As Long
MouseCallbackProc = CallNextHookEx(gblCurrentMouseHookID, intCode,
wParam, lParam)
gblLastActivityTime = Now
End Function
Public Function KeyboardCallbackProc(ByVal intCode As Integer, ByVal
wParam As Long, lParam As Long) As Long
KeyboardCallbackProc = CallNextHookEx(gblCurrentKBHookID, intCode,
wParam, lParam)
gblLastActivityTime = Now
End Function

Then in a form:

Option Compare Database
Option Explicit
Private Const WH_KEYBOARD = 2
Private Const WH_MOUSE = 7
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook
As Long) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal
hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Sub Form_Load()
gblCurrentMouseHookID = SetWindowsHookEx(WH_MOUSE, AddressOf
MouseCallbackProc, 0, GetCurrentThreadId)
gblCurrentKBHookID = SetWindowsHookEx(WH_KEYBOARD, AddressOf
KeyboardCallbackProc, 0, GetCurrentThreadId)
End Sub
Private Sub Form_Timer()
Me.lblInactivity.Caption = "Inactivity Timer: " & Format(Now -
gblLastActivityTime, "HH:MM:SS")
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx gblCurrentMouseHookID
UnhookWindowsHookEx gblCurrentKBHookID
End Sub

Note, in this example, the form's timer is displaying the time of
inactivity.  (based on the gblLastActivityTime)  You could set any
frequency you want on the time, to check for that inactivity time being
longer then XX from Now (XX being your predetermined inactivity
allowance).

This code monitors for any mouse or keyboard activity within the Access
Window.  So until MS comes out with a neural interface it should do the
trick.

Drew

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Susan Harkins
Sent: Saturday, December 15, 2007 1:31 PM
To: AccessD at databaseadvisors.com
Subject: [AccessD] shutting down

I'm trying to come up with an easy-to-implement solution that shuts down
a 
database automatically after a predetermined period of inactivity.

I can do this by dropping KeyPress events into every form that update a 
global timer, but <gag> that just seems so terribly intrusive and 
inefficient. There's got to be a better way. Seems like there ought to
be an 
API or something.

Susan H. 

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list