nIdleMinutes = 0 && Number of minutes that the computer is now idle. Used by IdleMinutes() > && method. >nLastInputInfo = 0 && Milliseconds the computer was on when the last keystroke or mousemove > && was. Used internally by the IdleMinutes() method. >ptLastPoint = 'xxxxxxx' && Internal to IdleMinutes() method. The pt stands for 'pointer'. >nIdleBaseline = 0 && Used internally by the IdleMinutes() method.>
* METHOD IdleMinutes > >* (C) Viafox 2005 >* >* get last input moment >* compare with previous last input moment >* if same, increase minute counter >* if not same, save last input moment >* return minute counter > >lparameter tlInit > >local llIdleNow > >with this > > if val( os( 3 ) ) >= 5 && if w2000 or higher, then use GetLastInputInfo() > > Local lnLast As Integer, plii As String, lcLast As String > > if m.tlInit > Declare Short GetLastInputInfo In win32API String @ plii > endif > > plii = Chr(8) + Replicate( Chr(0), 7 ) > lcLast = GetLastInputInfo( @plii ) > lnLast = ( Asc( Substr( plii, 8, 1 ) ) * 16777216 ) + ; > ( Asc( Substr( plii, 7, 1 ) ) * 65536 ) + ; > ( Asc( Substr( plii, 6, 1 ) ) * 256 ) + ; > Asc( Substr( plii, 5, 1 ) ) > > * lnLast is the milliseconds the computer was on when the last keystroke or mousemove was. > if m.lnLast = .nLastInputInfo > * > llIdleNow = .T. > else > .nLastInputInfo = m.lnLast > endif > > else && if WinNT or lower, then use this less sophisticated method > > LOCAL lpPoint, llKeypress, llMouseMove, ln > > if m.tlInit > declare short GetCursorPos in win32api string @ lpPoint > declare short GetAsyncKeyState In win32api integer nVirtKey > endif > > lpPoint = space(8) && lp = local pointer > > * Check mouse cursor position. > if ( GetCursorPos( @lpPoint) # 0 AND m.lpPoint # .ptLastPoint ) > * > .ptLastPoint = m.lpPoint && Save new pos > llMouseMove = .T. > endif > > * Check keystate and mouse buttons. > * Also do it if llMouseMove is .T., in order to reset things. > * That's why all 256 cycles are done anyway. > for ln = 0 to 255 > If GetAsyncKeyState( m.ln ) # 0 > llKeypress = .T. > endif > next > > llIdleNow = ( not m.llMouseMove and not m.llKeypress ) > > endif > > if m.llIdleNow > * > .nIdleMinutes = ( seconds() - .nIdleBaseline ) / 60 > else > .nIdleBaseline = seconds() > .nIdleMinutes = 0 > endif > > RETURN .nIdleMinutes