John117 Posted August 1, 2007 Share Posted August 1, 2007 (edited) I need a way to tell if a user is active so that a database is updated with their last action time I am thinking that the keyboard or mouse use could help with this. maybe MouseGetPos() then time till it changes. If more than 60 seconds unchanged = N Then keyboard use if more than 60 seconds = N If keyboard = N and mouse = N then active = False But false would have to be the most recient time of activity for the mouse or keyboard (whichever is more recient) True would also me the most recient, but since it would be sooner, it would fit within the 60 second thing and could be considered active when added to the database. Can anyone help me with a demo of any part of this? Even how to store time since keyboard or mouse movement? Edited August 1, 2007 by Hatcheda Link to comment Share on other sites More sharing options...
John117 Posted August 1, 2007 Author Share Posted August 1, 2007 Ok, I've worked out the mouse part, can anyone help me with the keyboard? In the example below the edit box will update when the mouse is still. It will not update again until you move the mouse and then the mouse is still again. CODE#include <GUIConstants.au3> #Include <Date.au3> Opt("GuiOnEventMode", 1) Global $Mouse1, $Mouse2, $hParent, $Edit1, $Time $hParent = GUICreate("Time Mouse Movement", 716, 561, 155, 134) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit", $hParent) $Edit1 = GUICtrlCreateEdit("Increase count when mouse not active for X time", 10, 30, 230, 60, $ES_WANTRETURN) GUISetState(@SW_SHOW) $n = 0 ; Counter While 1 _CheckMouse1() ; Goto get mouse pos first time Sleep(2000) $n = $n + 1 ; Adds 1 to the counter every two seconds _CheckMouse2() ; Goto func Get mouse pos second time WEnd Func _CheckMouse1() $pos1 = MouseGetPos() $Mouse1 = $pos1[0] + $pos1[1] EndFunc ;==>_CheckMouse1 Func _CheckMouse2() $pos2 = MouseGetPos() $Mouse2 = $pos2[0] + $pos2[1] If $Mouse1 <> $Mouse2 Then $n = 0 ElseIf $Mouse1 = $Mouse2 And $n = 2 Then _UserNotActive() EndIf EndFunc ;==>_CheckMouse2 Func _Quit() Exit EndFunc ;==>_Quit Func _UserNotActive() GUICtrlSetData($Edit1, _NowTime (5)) EndFunc ;==>_UserNotActive _NowTime (5) Link to comment Share on other sites More sharing options...
qazwsx Posted August 2, 2007 Share Posted August 2, 2007 i would say use _ispressed to see if the keyboard is active. If you want an already typed list of _ispressed and the keys just pm and ill send it to you. Link to comment Share on other sites More sharing options...
Paulie Posted August 2, 2007 Share Posted August 2, 2007 I didn't come up with this, but its pretty clever, Returns 1 if any key is pressed, otherwise return 0 Func _IsAnyKeyPressed($start = 0, $end = 255) For $i = $start to $end if _IsPressed(Hex($i,2)) Then return 1 Next Return 0 EndFunc Link to comment Share on other sites More sharing options...
sandman Posted August 2, 2007 Share Posted August 2, 2007 I just wrote a simple UDF for checking mouse movement earlier today:;=============================================================================== ;_MouseIsMoving() ; Description: Check if the mouse is moving. ; Parameter(s): None ; Requirement(s): A mouse to check, obviously ; Return Value(s): If mouse is moving: return True ; If mouse is not moving: return False ; Author(s): Me ; Note(s): None ; ;=============================================================================== Func _MouseIsMoving() $pos = MouseGetPos() Sleep(10) $pos2 = MouseGetPos() If $pos[0] <> $pos2[0] Or $pos[1] <> $pos2[1] Then Return True Else Return False EndIf EndFunc [center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center] Link to comment Share on other sites More sharing options...
John117 Posted August 2, 2007 Author Share Posted August 2, 2007 @all Thanks! I can use this! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now