I would like my server scripts to pause/resumed based on last user interaction/input. I found this but how do I define the size of the structure?
https://docs.microsoft.com/en-us/window ... tinputinfo
Time since last user input
Moderators: Dorian (MJT support), JRL
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Time since last user input
I managed to get it working using Python. MS is such a bad*ss tool
Move your mouse during the time and you'll see that the time gets reset.
Code: Select all
/*
python_code:
import ctypes, ctypes.wintypes
class LASTINPUTINFO(ctypes.Structure):
_fields_ = [
('cbSize', ctypes.wintypes.UINT),
('dwTime', ctypes.wintypes.DWORD),
]
PLASTINPUTINFO = ctypes.POINTER(LASTINPUTINFO)
liinfo = LASTINPUTINFO()
liinfo.cbSize = ctypes.sizeof(liinfo)
user32 = ctypes.windll.user32
GetLastInputInfo = user32.GetLastInputInfo
GetLastInputInfo.restype = ctypes.wintypes.BOOL
GetLastInputInfo.argtypes = [PLASTINPUTINFO]
kernel32 = ctypes.windll.kernel32
GetTickCount = kernel32.GetTickCount
GetLastInputInfo(ctypes.byref(liinfo))
print(GetTickCount() - liinfo.dwTime)
*/
LabelToVar>python_code,temp
// idle time in "ticks"... 1tick=1ms?
Let>k=0
Repeat>k
Add>k,1
PYExec>temp,idleTime
Message>idleTime
Wait>1
Until>k=10
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Time since last user input
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Time since last user input
Not really since I want to halt/idle the script when a user (me) make any interaction with the computer (my server).Marcus Tettmar wrote: ↑Wed Dec 09, 2020 9:15 pmis Timer no help?
https://www.mjtnet.com/manuals/v15/HTML/timer.html
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Time since last user input
A vbscript based code snippet. I use the IO read of the csrss.exe process. There's multiple sessions open but for me the second seems to be my users input.
Code: Select all
VBSTART
Function IdleComputer()
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_process where name='csrss.exe'")
For Each objItem in colItems
IdleComputer = IdleComputer & vbNewLine & objItem.ReadOperationCount
Next
End Function
VBEND
Let>REFERENCE_TIMER=0
Let>LAST_INPUT_TICKS_TIME_STAMP=0
Label>START
VBEval>IdleComputer(),TEMP_LAST_INPUT_BASED_ON_IO
Trim>TEMP_LAST_INPUT_BASED_ON_IO,TEMP_LAST_INPUT_BASED_ON_IO
Separate>TEMP_LAST_INPUT_BASED_ON_IO,%CRLF%,TEMP_check
Let>CURRENT_INPUT_IO_READ=TEMP_check_2
IfNot>CURRENT_INPUT_IO_READ=LAST_INPUT_IO_READ
Timer>REFERENCE_TIMER
Else>
Timer>LAST_INPUT_TICKS_TIME_STAMP
Endif>
Let>LAST_INPUT_IO_READ=CURRENT_INPUT_IO_READ
Let>USER_IDLE_TIME=LAST_INPUT_TICKS_TIME_STAMP-REFERENCE_TIMER
If>USER_IDLE_TIME<0
Let>USER_IDLE_TIME=0
Endif>
Message>USER_IDLE_TIME
Wait>0.1
Goto>START
Re: Time since last user input
Track timestamps in your script define the structure size based on your server requirements for accurate tracking.