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.

 

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.

 

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.

 

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.

 

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.

 

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.

 

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.

 

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

    • 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:

    • Chaym
      By Chaym
      Does AutoIT supported  in Windows 10 OS (x64)?
      After installing AutoIT in x64 OS and recompiling code,
      I get a lot of error messages...
       
    • kristo
      By kristo
      The DriveGetDrive command returned all drives (option "ALL") for years now and my program could always rely on that function. Suddenly a drive letter that was created with the subst command does not appear in the list of drives anymore. And it clearly did, because I used to react to a certain subst command by reacting to new or revoked (subst /D) drive letters.
      Why is that? I think this a bug because there's no way left to list ALL drive letters anymore.
      And why should I use an API command for that when this was already built in for years?

       
    • kokoilie
      By kokoilie
      I'm making a program that has a combo control in a gui and back in win7 when the window was focused the scroll wheel could be used to scroll through it's contents, now i'm using win10 and i have to put the mouse on that control to scroll up and down.
      Since now the scroll wheel works depending on where the mouse is, is there a way to make it no matter where on the gui the pointer is?
      Also if the only way to do it is some complex hotkey functions will it work with pressing space to toggle a checkbox?
      If you need to see what i have so far let me know and i'll copy it here.
    • ModemJunki
      By ModemJunki
      Hello,
      In Windows 10 PowerShell, one can do this to change the metric for a NIC in Windows 10:
      Get-NetAdapter | Where-Object -FilterScript {$_.InterfaceAlias -Eq "Ethernet 2"} | Set-NetIPInterface -InterfaceMetric 2 I know I can script the above PowerShell line (and it works!), but I wanted to try something I hadn't done before after looking into jguinch's most excellent Network configuration UDF. I wanted to make use of the SetIPConnectionMetric method in the WMI classes. There is an example VBscript here but this is not for Windows 10. Using AutoIT would also give better control over capturing error return codes than with PowerShell.
      But I cannot get my script to work! The return from SetIPConnectionMetric() is 0, which would indicate success. Yet the change does not happen. I also tried WMI methods using .put_ but this fails.
      Anyone more experienced than I have ideas to make this work?
      #RequireAdmin _SetNicInterfaceMetric2("Ethernet 2", "2") Func _SetNicInterfaceMetric2($NIC_NAME, $METRIC) Local $s_setIndx = 0 $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2") $colNICItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & $NIC_NAME & "'", "WQL") If IsObj($colNICItems) Then For $objItem In $colNICItems $s_nicIndex = $objItem.Index Next ConsoleWrite("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'" & @CRLF) $colNAC = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = '" & $s_nicIndex & "'", "WQL") If IsObj($colNAC) Then For $objNetCard In $colNAC If $METRIC <> $objNetCard.IPConnectionMetric Then ConsoleWrite("Metric was set to " & $objNetCard.IPConnectionMetric & ". Setting to " & $METRIC & "." & @CRLF) $s_isSet = $objNetCard.SetIPConnectionMetric($METRIC) ConsoleWrite("SetIPConnectionMetric Result = " & $s_isSet & @CRLF) Else ConsoleWrite("Metric is already set to " & $METRIC & @CRLF) EndIf Next EndIf EndIf EndFunc ;==>_SetNicInterfaceMetric2