Jump to content

help tweaking gafrost's code for custom use . . .


Recommended Posts

I have the following code. much of it (the important stuff) is form gafrost. I would like it to do three things differently.

I would like to drop the counter that appears by the mouse.

I would like to only preform the _UserNotActive function once unless the user has been active again since the last inactive run

I would like it to fill Edit2 with the first active time since return to active

Ex

edit1, edit2

user is active, edit2 = now

two minutes later:

User is not active, edit1 = now

two hours later user is still not active:

edit1 still = two hours before.

two minutes later:

user active, edit2 = now

and repeat . . .

Code that needs help: I have done about as much as I can see to do to it

CODE
#include <GUIConstants.au3>

#Include <Date.au3>

Opt("GuiOnEventMode", 1)

Global $hParent, $Edit1

$hParent = GUICreate("Time User Action", 716, 561, 155, 134)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit", $hParent)

$Edit1 = GUICtrlCreateEdit("Add Last Use Time Here", 10, 30, 230, 60, $ES_WANTRETURN)

$Edit2 = GUICtrlCreateEdit("Add Last Use Time Here", 250, 30, 230, 60, $ES_WANTRETURN)

GUISetState(@SW_SHOW)

Dim $last_active = 0

Dim $Inactive_Seconds = 10

Dim $timer = TimerInit()

$not_idle = _CheckIdle($last_active, 1)

While (1)

$not_idle = _CheckIdle($last_active)

If $not_idle <> 0 Then $timer = TimerInit()

ToolTip(Int(TimerDiff($timer) / 1000))

Sleep(200)

If Int(TimerDiff($timer) / 1000) >= $Inactive_Seconds Then

_UserNotActive()

$timer = TimerInit()

$not_idle = _CheckIdle($last_active, 1)

EndIf

WEnd

Func _CheckIdle(ByRef $last_active, $start = 0)

$struct = DllStructCreate("uint;dword");

DllStructSetData($struct, 1, DllStructGetSize($struct));

If $start Then

DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))

$last_active = DllStructGetData($struct, 2)

Return $last_active

Else

DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))

If $last_active <> DllStructGetData($struct, 2) Then

Local $save = $last_active

$last_active = DllStructGetData($struct, 2)

Return $last_active - $save

EndIf

EndIf

EndFunc ;==>_CheckIdle

Func _Quit()

Exit

EndFunc ;==>_Quit

Func _UserNotActive()

GUICtrlSetData($Edit1, _NowTime (5))

EndFunc ;==>_UserNotActive

Func _UserActive()

GUICtrlSetData($Edit2, _NowTime (5))

EndFunc ;==>_UserActive

Please help if you can! :) other post and tips welcome!

Edited by Hatcheda
Link to comment
Share on other sites

While (1)
    $not_idle = _CheckIdle($last_active)
    If $not_idle <> 0 Then 
        $timer = TimerInit()
        _UserActive()
    Else
        ToolTip(Int(TimerDiff($timer) / 1000))
        Sleep(200)
    EndIf
    If Int(TimerDiff($timer) / 1000) >= $Inactive_Seconds And $last_active <> 0 Then
        _UserNotActive()
        $timer = TimerInit()
        $not_idle = _CheckIdle($last_active, 1)
    EndIf
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

ok, thanks! It is now updating the active box! (over and over as needed!)

It is still updating the inactive every x seconds when it is not used though. (idea would be to only update once then wait till active, if inactive after active again then update again . . .)

Suppose it is inactive for 20hours. If the timer is set to 2 minutes, it should only have one timestamp for inactive (19hours and 58 minutes ago) :)

is there any way to drop\hide the counter by the mouse?

Thanks for your help!

an example of updating only once is in the code below: (only setup for mouse detection)

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

Edited by Hatcheda
Link to comment
Share on other sites

You'll have to play around with how you want it to update....

Dim $last_active = 0
Dim $Inactive_Seconds = 120
Dim $idling = False
Dim $timer = TimerInit()

$not_idle = _CheckIdle($last_active, 1)

While (1)
    $not_idle = _CheckIdle($last_active)
    If $not_idle <> 0 Then 
        $timer = TimerInit()
        _UserActive()
        $idling = False
        Sleep(200)
    ElseIf Int(TimerDiff($timer) / 1000) >= $Inactive_Seconds Then
        If Not $idling Then _UserNotActive()
        $idling = True
        Sleep(200)
    EndIf
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

It is still updating the inactive every x seconds when it is not used though. (idea would be to only update once then wait till active, if inactive after active again then update again . . .)

Suppose it is inactive for 20hours. If the timer is set to 2 minutes, it should only have one timestamp for inactive (19hours and 58 minutes ago) :)

is there any way to drop\hide the counter by the mouse?

#include <GUIConstants.au3>
#Include <Date.au3>
Opt("GuiOnEventMode", 1)


Global $hParent, $Edit1
$hParent = GUICreate("Time User Action", 716, 561, 155, 134)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit", $hParent)
$Edit1 = GUICtrlCreateEdit("Add Last Use Time Here", 10, 30, 230, 60, $ES_WANTRETURN)
$Edit2 = GUICtrlCreateEdit("Add Last Use Time Here", 250, 30, 230, 60, $ES_WANTRETURN)
GUISetState(@SW_SHOW)



Dim $last_active = 0
Dim $Inactive_Seconds = 10
Dim $timer = TimerInit()

$not_idle = _CheckIdle($last_active, 1)

$activity = false;<------------- added

While (1)
    $not_idle = _CheckIdle($last_active)
    If $not_idle <> 0 Then
        $timer = TimerInit()
        _UserActive()
    Else
       ;ToolTip(Int(TimerDiff($timer) / 1000))
        Sleep(200)
    EndIf
    If Int(TimerDiff($timer) / 1000) >= $Inactive_Seconds And $activity Then;$last_active = 0 Then <-----------changed
        _UserNotActive()
        $timer = TimerInit()
        $not_idle = _CheckIdle($last_active, 1)
    EndIf
WEnd

Func _CheckIdle(ByRef $last_active, $start = 0)
$struct = DllStructCreate("uint;dword");
DllStructSetData($struct, 1, DllStructGetSize($struct));
If $start Then
DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
$last_active = DllStructGetData($struct, 2)
Return $last_active
Else
DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
If $last_active <> DllStructGetData($struct, 2) Then
Local $save = $last_active
$last_active = DllStructGetData($struct, 2)
Return $last_active - $save
EndIf
EndIf
EndFunc;==>_CheckIdle


Func _Quit()
Exit
EndFunc;==>_Quit

Func _UserNotActive()
GUICtrlSetData($Edit1, _NowTime (5))
$activity = false;<---------------------
EndFunc;==>_UserNotActive

Func _UserActive()
GUICtrlSetData($Edit2, _NowTime (5))
$activity = true<-------------------------
EndFunc;==>_UserActive
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...