Link to home
Start Free TrialLog in
Avatar of Nirmal Sharma
Nirmal SharmaFlag for United States of America

asked on

Getting System Idle Time

Hi,

I got this working example from EE to wait for User input (keyboard and Mouse):

Local iTime As Integer, iLast As Integer
Local plii As String, cLast As String

Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii

iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
cLast      = GetLastInputInfo(@plii)
iLast      = (Asc(Substr(plii, 8, 1)) * 16777216) + ;
(Asc(Substr(plii, 7, 1)) * 65536) + ;
(Asc(Substr(plii, 6, 1)) * 256) + ;
Asc(Substr(plii, 5, 1))

iTime is the milliseconds your computer has been on.
iLast is the milliseconds your computer was on when your last keystroke or mousemove was.

To get minutes idle:
TotTime=(m.iTime - m.iLast) / 1000

The above example checks only user inputs (Keyboard and Mouse) but as per MS Article the system is idle only if the following conditions are not true:

The System Idle Task Scheduler service monitors for the system to be idle. The system is considered to be idle if for the last 10 minutes:

There is no user input.
The CPU and disk usage is less than 10 percent.

Question: My question is that how I know if the system is idle in Visual Foxpro based on the above conditions (CPU and Disk Usages)?

Thanks
SP



Avatar of Nirmal Sharma
Nirmal Sharma
Flag of United States of America image

ASKER

and also what I have obsereved is that CPU is taking at least 80% when I run the above code with a Do While loop.

Please advise.

Thanks!
Avatar of Pavel Celba
It is not necessary to check keyboard hits and mouse moves continuously in a loop. To decrease CPU loading significantly during the loop you have to insert some waiting command into the loop, e.g.:

= INKEY(0.5)
or
WAIT WINDOW "" TIMEOUT 0.5

CPU Usage/Idle time is available in GetSystemTimes API routine: http://www.vbforfree.com/?p=319
Unfortunately, i have no info about Disk usage API and you should ask this specific question in some operating system zone.
Thanks for your response!

If it is not necessary to check using a loop then how I check for user input without a loop? is there any other mechanism to do so?

Could you please give me an example how I leverage GetSystemTimes with the above example?

Appreciate your help!

Thanks!
SP
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You
Much appreciated!
Hi (sorry I don't have enough points to ask a small query in separate question but it's urgent)

Is there any way to cover a user's desktop using any command in VF9?

For example:

IF asds="Y"
   define wind mn1 from -03,-03 to 1000,1000 IN DESKTOP
   acti wind mn1
else
endif

the above code works fine except sometimes the program is minized to the taskbar. Therefore, user has to click on Taskbar program (Application) get desktop covered again.

Is there any way that if asds="Y" then user's desktop should be covered with wind mn1?

Thanks!
Nirmal

You could try ZOOM WINDOW mn1 MIN
or  _screen.WindowState = 2