Jump to content

Problem in windows 10 "_Timer_GetIdleTime()"


 Share

Recommended Posts

#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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

Link to comment
Share on other sites

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

Link to comment
Share on other sites

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,
 

Link to comment
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?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

Link to comment
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!

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

Link to comment
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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

Link to comment
Share on other sites

  • 1 month later...

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

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

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

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

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

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

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.

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

Au3Record.exe

Link to comment
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.

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

×
×
  • Create New...