careca

Problem in windows 10 "_Timer_GetIdleTime()"

15 posts in this topic

#include <Timers.au3>

While 1
Local $iIdleTime = _Timer_GetIdleTime()
ConsoleWrite($iIdleTime &' - '&@MSEC&@CRLF)
Sleep(150)
WEnd

Hi all, This used to work well in Win7, now in Win10 it auto resets constantly without any input, any ideas?


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites



I tried it on my computer and the results:

image.png

 


Regards,
 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I tried it on my computer and the results:

I see, here's what happens here:

So what do you suggest?

 

 

Capture.PNG

Edited by careca
Screenshot

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Results from the test showed script runs very good.

If I do not move the mouse or press any key (inactive)
it will start counting IdleTime.

If any activity, IdleTime will be reset.
And will continue counting when the computer inactive!

;#include <Timers.au3>

While 1
    Local $iIdleTime = _Timer_GetIdleTime()
    ConsoleWrite($iIdleTime & ' - ' & @MSEC & @CRLF)
    Sleep(150)
WEnd

Func _Timer_GetIdleTime()
    ; Get ticks at last activity
    Local $tStruct = DllStructCreate("uint;dword");
    DllStructSetData($tStruct, 1, DllStructGetSize($tStruct));
    Local $aResult = DllCall("user32.dll", "bool", "GetLastInputInfo", "struct*", $tStruct)
    If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, 0)

    ; Get current ticks since last restart
    Local $avTicks = DllCall("kernel32.dll", "dword", "GetTickCount")
    If @error Or Not $aResult[0] Then Return SetError(@error, @extended, 0)

    ; Return time since last activity, in ticks (approx milliseconds)
    Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2)
    If $iDiff < 0 Then Return SetExtended(1, $avTicks[0]) ; Rollover of ticks counter has occured
    ; Normal return
    Return $iDiff
EndFunc   ;==>_Timer_GetIdleTime

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

@careca,

first, redeclaring Local inside a loop hurts my very few left brain cells. please stop it.

now, even if you do not touch your mouse or keyboard, something else obviously does - but it does not have to be human. i once noticed that same issue with an nVidia driver which needed to be updated, and in another occasion i overheard that a laptop touchpad driver was to blame.

i just searched my mail, but i can't seem to find the related info. if i do, perhaps i can get some more details for you. meanwhile, follow a standard troubleshooting procedure: test in safe mode, if that works then start disabling drivers, services, apps and stuff, until you find the culprit.

also: is it a physical or virtual machine running Windows 10?

Share this post


Link to post
Share on other sites

first, redeclaring Local inside a loop hurts my very few left brain cells. please stop it.

now, even if you do not touch your mouse or keyboard, something else obviously does - but it does not have to be human. i once noticed that same issue with an nVidia driver which needed to be updated, and in another occasion i overheard that a laptop touchpad driver was to blame.

i just searched my mail, but i can't seem to find the related info. if i do, perhaps i can get some more details for you. meanwhile, follow a standard troubleshooting procedure: test in safe mode, if that works then start disabling drivers, services, apps and stuff, until you find the culprit.

also: is it a physical or virtual machine running Windows 10?

Hi, i never redeclare inside a loop, it's just that i copy-pasted from the example and then put a loop around it, don't worry, i never do it unless for these test examples.

Ok, i'll test safe mode.

It's a physical machine, without touchpad, meaning desktop, but does the same in my laptop...


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

Results from the test showed script runs very good.

Well, it doesn't here, as i said before, and i understand how it works, just need to find what is reseting it. ;)


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

... it's just that i copy-pasted from the example ...

as my professor used to say, "even copying is something one must know how to do correctly" ;)

now, assuming GetLastInputInfo or GetTickCount are being messed with, and if you want a reliable functionality over multiple systems, perhaps a different approach is in order - depending on your actual purpose. if you are comfortable with "idle time" being redefined as "the time since last mouse move" (ignoring keyboard input), then the script hereunder demonstrates how it can be applied:

AdlibRegister('_MouseIdleTime')

HotKeySet('{ESC}', '_Exit')

While True
    ConsoleWrite(_MouseIdleTime() & @CRLF)
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _MouseIdleTime()
    Local Static $hTimer ; a running timer measuring the required idle time
    Local Static $aMousePosOld[2] ; holding the previous mouse position, to be compared to current mouse position
    Local $aMousePosNew = MouseGetPos() ; get current mouse position for comparison
    If $aMousePosOld[0] <> $aMousePosNew[0] Or $aMousePosOld[1] <> $aMousePosNew[1] Then ; mouse has moved
        ; remember new pos
        $aMousePosOld[0] = $aMousePosNew[0]
        $aMousePosOld[1] = $aMousePosNew[1]
        ; zero timer
        $hTimer = TimerInit()
        ; return zero, which indicates a mouse move to the calling script
        Return 0
    Else ; mouse has not moved
        Return TimerDiff($hTimer) ; let the calling script know for how long
    EndIf
EndFunc   ;==>_MouseIdleTime

important: this script does not consider keyboard input, as well as any other input device which does not simulate a mouse cursor!

1 person likes this

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Yeah, i was thinking about that, it will work, thanks, it's for a code that turns the monitor off with a hotkey when im going away.

PS: I'll probably add some more lines to that, in order to detect space and enter to wake up.

Thanks everyone!

 

EDIT: So i discovered that DWM.exe or 'Desktop Windows Manager' was the culprit, had to kill explorer first, and as soon as i killed DWM the count started to climb. So now that i know that, do you think there's a way to ignore that process?

Edited by careca
Found out

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

... it's for a code that turns the monitor off with a hotkey when im going away.

isn't that a built-in "Power Options" feature? set it to turn the monitor off after 1 minute and you'll be fine.

EDIT: So i discovered that DWM.exe or 'Desktop Windows Manager' was the culprit, had to kill explorer first, and as soon as i killed DWM the count started to climb. So now that i know that, do you think there's a way to ignore that process?

DWM by itself is, in all likelihood, innocent. DWM is responsible for integrating Windows (the OS) effect and windows (of programs) graphics to a composite image which is then displayed on screen (here is a pretty decent article about it). you really should investigate further on to which is the app that - when its graphics is processed by DWM - creates the issue.

Share this post


Link to post
Share on other sites

isn't that a built-in "Power Options" feature? set it to turn the monitor off after 1 minute and you'll be fine.

DWM by itself is, in all likelihood, innocent. DWM is responsible for integrating Windows (the OS) effect and windows (of programs) graphics to a composite image which is then displayed on screen (here is a pretty decent article about it). you really should investigate further on to which is the app that - when its graphics is processed by DWM - creates the issue.

I want to decide when to shut it off.

If DWM is not the one, how can i find what is?, i literally killed every process and that was the only one that did the trick.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I am seeing the same problem with a BlissBox (USB hub that works with almost all old retro game controllers).

 

As soon as I plug that in, the timer never goes above 16ms, even with no joysticks plugged into it. As soon as I unplug it, the idle timer starts rising.

Not that I expect any help with that from this forum, I just thought it is worth nothing for the future if anyone else have any problem. I've yet to find a solution for it.

#include <Timers.au3>

HotKeySet("+{ESC}", "_Quit")

While 1
   SplashTextOn("Test of idle timer. Shift-Esc to quit.", "This timer should go up if you do not touch anything." & @CRLF & @CRLF & _Timer_GetIdleTime(),-1,100)
   Sleep(1000)
WEnd

Func _Quit()
   SplashOff()
   Exit
EndFunc

 

Edited by Turranius

Share this post


Link to post
Share on other sites

Sounds like the hub does this on purpose to prevent the screensaver/sleep from kicking in. It's probably because the controllers aren't seen as keyboard or mouse input so the screensaver might come on if it didn't do that, but that's just a guess.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I ended up discovering that for me, it was a controller/gamepad, that was connected in those ports i never touch in the back..


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

To follow up on this...

 

If you are using the release version of Windows 10 (10240?), the _Timer_GetIdleTime() is indeed reset when using a Game Controller. Microsoft considers this a bug, so...

In the big november update (1511), they fixed this so Game Controllers no longer reset the _Timer_GetIdleTime() (And your screensaver goes on if you are only using a game controller...).

 

So the reason for my problems was because the BlissBox was sending out a signal every 16ms. With the release version of Windows 10, this reset the _Timer_GetIdleTime() every 16ms. I've updated to Windows 10 version 1511 and the problem is gone.

 

Of course, now _Timer_GetIdleTime() is pretty useless if you are sitting with a game controller only, but that is not Autoits fault but a design decision from Microsoft.

1 person likes this

Share this post


Link to post
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

  • Similar Content

    • BBs19
      By BBs19
      Features:
      Create modern looking borderless and resizable GUIs with control buttons (Close,Maximize/Restore,Minimize, Fullscreen, Menu) True borderless, resizeable GUI with full support for aerosnap etc. Many color schemes/themes included. See MetroThemes.au3 for more details. 3 type of Windows 8/10 style buttons. Modern checkboxes, radios, toggles and progressbar. All buttons, checkboxes etc. have hover effects! Windows 10 style modern MsgBox. Windows 10/Android style menu that slides in from left. Windows 10 style right click menu  
      Credits: @UEZ, for the function to create buttons with text using GDIPlus. @binhnx for his SSCtrlHover UDF
       
      Changelog:
      Download UDF with example:
       
       
    • keelaji
      By keelaji
      Hello,
      first of all i searched in the forum but i didn't found any solution to my problem.
      I am using windows 10.
      I made a script that is supposed to change the title to the active window, resize it to the smallest size possible (should be around 800 x 600) and move to (0, 0).
      I can change the title but i fail to do the other 2 tasks.
      i use wingettitle [active] copied from the F1 help tool (and this works), i i put the title in a variable and than i use
      winsettitle ($variable, "one") (this works too)
      winmove ("one", 0, 0, 800, 600) (doesn't do anything)
      i also tried
      local $x = winget ( "one")
      msgbox (0, "", $x) (i get a completely white box so i suppose winget can't have any data about my window ??)
      any suggestion ?
    • spuuunit
      By spuuunit
      I have a script that autostart with Windows, and sometimes some of my code is skipped. My script takes long pauses, so it's not that the script "goes too fast". This is my script for now:
      TraySetIcon("C:\Portables\AutoIt\_\icon.ico") AutoItSetOption("WinTitleMatchMode", 2) Run("C:\Portables\Key Manager\keymanager.exe") WinActivate("ATNSOFT Key Manager v") WinWaitActive("ATNSOFT Key Manager v") WinMove("ATNSOFT Key Manager v", "", 650, 200, 600, 800) Sleep(500) $pos = MouseGetPos() MouseClick("left", 1220, 210, 1, 100) MouseMove($pos[0], $pos[1], 100) Run("C:\Portables\foobar2000\foobar2000.exe") $version = 298 For $i = 0 To 99 Step 1 $path = "C:\Users\spunit\AppData\Local\Discord\app-0.0." & $version + $i & "\Discord.exe" If FileExists($path) Then Run($path) ExitLoop EndIf Next Run("C:\Portables\Firefox\FirefoxPortable.exe") Sleep(10000) WinMove("- Mozilla Firefox", "", 205, 0, 1214, 1047) Sleep(100) MouseClick("left", 1300, 15, 1, 10) Sleep(100) MouseClick("left", 1130, 275, 1, 10) Sleep(100) MouseClick("left", 930, 105, 1, 10) Sleep(100) Send("#{m}") Sometimes it skips to click and move mouse right after Key Manager starts. Almost always it skips everything after the last run.

      This type of script were never an issue with Windows 7... Any thoughts?
    • VIP
      By VIP
      I can not do anything with any user in the "Local Users Group"
      I tried from my account but I could not change my password (ie set new password)!
      But I was able to activate the Administrator account and I logged into the Administrator account and still could not do anything with my account! But I can set the password and disable the Administrator account from my account or Administrator.
      Any ideas? (Ignore the click on the Sign-in option in the Change Accout settings.)
       

    • dreivilo47
      By dreivilo47
      When I want to test Example 1 of Function _IECreate (AutoIt Help File), I see that function _IECreate doesn't work in Windows 10.
      Syntax Check (Ctrl+F5) gives no errors.
       
      Example 1:
      ; Create a browser window and navigate to a website #include <IE.au3> Local $oIE = _IECreate("www.autoitscript.com")  
      The error I receive with F5 (Tools, Go) in SciTE: