Jump to content

Activate when away from keyboard.


Recommended Posts

Just like the title says(and I really have no clue if this can be done)

Is there a way to activate certain functions when no input from mouse or keyboard is found after like say 5min. Like on instant messengers when no input has been detected it switches there status to afk(away from keyboard). Can AutoIt do something like this? If not then thanks for telling me.

Link to comment
Share on other sites

You could use a timer and _IsPressed to find out when a user is not entering data and away from the computer.

You'll need to check for every form of input, however. Here's something I threw together in 2 minutes:

While 1
    TimerFunction
    Sleep(100)
WEnd

Func TimerFunction()

    If IsPressedFunction() = False Then
        ;start timer
        $timer = TimerInit()
        
        Do
            ;check for user input, if so then return
            If IsPressedFunction() Then Return
            Sleep(100)
        Until TimerDiff($timer) > 300000 ;5 minutes time
        
        AFK_Function()
        
    EndIf

EndFunc

Func IsPressedFunction()
    ;I am not going to write this, it will require lots of if's, else's, switches, etc.
    ;Look up _IsPressed() in the help file
    ;return True if a button is pressed
    ;return False if no button is pressed
EndFunc

Func AFK_Function()
    ;what you want to do after 5 minutes here
EndFunc
Edited by Affe

[center][/center]

Link to comment
Share on other sites

  • Moderators

KurogamineNox,

Dog eaten the Help file? ;)

Try _Timer_GetIdleTime. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Affe,

My pleasure. ;)

That Help file is just too big sometimes - as GeoSoft proved to me only yesterday by pointing out something I had never noticed! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hey I was checking the help file, How could I edit it to have it work the same way but after 5 seconds(Without the sleep and with a while function)

original

#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <Timers.au3>

; Mouse/Keyboard action during this 10 sec delay will change reported idle time
Sleep(10 * 1000); 10sec

Global $iIdleTime = _Timer_GetIdleTime()

MsgBox(64, "_Timer_GetIdleTime", "Idle time = " & $iIdleTime & "ms")

What I was thinking and need help on

#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <Timers.au3>

; Mouse/Keyboard action during this 10 sec delay will change reported idle time

Global $iIdleTime = _Timer_GetIdleTime()

While 1

If $iIdleTime = 5000 Then

MsgBox(64, "_Timer_GetIdleTime", "Idle time = " & $iIdleTime & "ms")

EndIf

WEnd

I clearly am doing something wrong. Any thoughts or at least a better understanding of it?

Link to comment
Share on other sites

You need to set $iIdleTime to the current Idle Time each instance through the loop. So you can declare it, but you must still get a new value for the idle time.

Global $iIdleTime

While 1
Sleep(100) ;you really want some kind of sleep to prevent CPU overload
$iIdleTime = _Timer_GetIdleTime()
If $iIdleTime > 300000 Then
;you can either exit the loop, or call a function
AFK_Function()
EndIf
Wend

Also, time in AutoIt is in milliseconds.

1000 ms = 1 second

60 s = 1 minute

60 m = 1 hour

So 5 minutes is: 1000 * 60 * 5 = 300000 milliseconds.

Edited by Affe

[center][/center]

Link to comment
Share on other sites

  • Moderators

KurogamineNox,

Just keep testing like this: ;)

#include <Timers.au3>

$iPermitted_IdleTime = 5000 ; 5 secs max

While 1

    If  _Timer_GetIdleTime() > $iPermitted_IdleTime Then ExitLoop
    
    ; If you press a key or move the mouse BEFORE 5 secs elapse, the timer is automatically reset

WEnd

MsgBox(0, "Idle Too Long!", "Do Something Now!")

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...