Search  
Wednesday, May 23, 2012 ..:: Forum ::.. Register  Login
 Forum Minimize
Pentru a putea posta mesaje trebuie să vă înregistraţi.
Notă: Mesajele cu conţinut jignitor sau ilegal (inclusiv cereri de soft piratat) nu sunt acceptate şi vor fi şterse imediat .

Pentru a primi raspunsuri rapide si corecte, scrieti in mesaj ce intentionati sa faceti, ce mesaj de eroare primiti, in ce context si in urma caror actiuni. De asemenea, mentionati versiunea de FoxPro in care lucrati!
Dacă nu specificați versiunea, se consideră VFP 9.0 SP2.

SearchForum Home
  Visual FoxPro  Visual FoxPro in general  Evenimente mous...
 Evenimente mouse si tastatura
 
 9/19/2011 7:55:46 AM
User is offlinegavroche
82 posts


Evenimente mouse si tastatura
 (N/A) Modified By gavroche  on 9/19/2011 7:59:05 AM)
Salutare.
Cum as putea sa fac sa pot detecta o perioada de inactivitate (nu se misca mouse-ul si nu se foloseste tastatura).
Nu as vrea sa folosesc eventul OnMouseMove sau on KeyPress pentru fiecare element din form.
Plus ca eu vreau sa stiu daca s-a folosit mouse-ul si tastatura si daca nu e nici un form deschis.
Exista o modalitate mai eleganta?

 9/19/2011 8:40:23 AM
User is offlinemmarius28
139 posts
5th


Re: Evenimente mouse si tastatura
 (N/A) Modified By mmarius28  on 9/19/2011 8:44:34 AM)
Uite 2 linkuri care te pot ajuta:

http://www.experts-exchange.com/Microsoft/Applications/FoxPro/Q_21053578.html

http://www.experts-exchange.com/Microsoft/Applications/FoxPro/Q_25534460.html
 9/19/2011 10:01:20 AM
User is offlinegavroche
82 posts


Re: Evenimente mouse si tastatura
 (N/A)
Site-ul ala iti cere sa te inregistrezi ca sa vezi raspunsurile, iar la inregistrare iti cere cardul de credit.
Daca tu ai cont acolo posteaza tu te rog raspunsul aici.
Multumesc.
 9/19/2011 10:28:55 AM
User is offlineclivius33
68 posts


Re: Evenimente mouse si tastatura
 (N/A)
Salut,

Rapsunsul il gasesti aici : http://www.foxite.com/archives/auto-logoff-0000171582.htm
 9/19/2011 12:17:28 PM
User is offlinemmarius28
139 posts
5th


Re: Evenimente mouse si tastatura
 (N/A)

Determining system idle time using GetLastInputInfo and LastInputInfo

Asked by Bryan_123 in FoxPro Database

Tags: lastinputinfo, getlastinputinfo

Is there a way in FoxPro that I can read the system idle time. I have a timer on the main form that is set up for 15 second intervals and I'd like it to check how long the computer has been idle. I don't want to record my own keystokes and mouse clicks. I just want to read the system settings. I'm having trouble with the GetLastInputInfo and LastInputInfo API calls.

09/07/04 01:34 PM, ID: 11515770

If your problem is the struct type here is an example from MSDN how to do it in FoxPro

typedef struct _SYSTEMTIME { 
   WORD wYear ;
   WORD wMonth ;
   WORD wDayOfWeek ;
   WORD wDay ;
   WORD wHour ;
   WORD wMinute ;
   WORD wSecond ;
   WORD wMilliseconds ;
} SYSTEMTIME

To pass data between Visual FoxPro and the GetSystemTime( ) function, you must create a 40-byte string buffer (consisting initially of spaces) and then pass the address of this string to the function for it to fill in. When the string is returned, you must parse it in 2-byte increments to extract the individual fields of the structure. The following fragment illustrates how you could extract three of the fields from the structure:

DECLARE INTEGER GetSystemTime IN win32api STRING @
cBuff=SPACE(40)
=GetSystemTime(@cBuff)

tYear = ALLTRIM(STR(ASC(SUBSTR(cBuff,2)) *  ; 
   256 + ASC(SUBSTR(cBuff,1))))
tMonth = ALLTRIM(STR(ASC(SUBSTR(cBuff,4)) * ; 
   256 + ASC(SUBSTR(cBuff,3))))
tDOW = ALLTRIM(STR(ASC(SUBSTR(cBuff,6)) * ; 
   256 + ASC(SUBSTR(cBuff,5))))
09/07/04 02:15 PM, ID: 11516068
I'm trying this:

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

iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
iLast      = GetLastInputInfo(@plii)

iLast ends up being an 8 character string instead of a number.

In VB.Net GetTickCount() gave me the in milliseconds how long my computer has been on (It does this in FoxPro). Then GetLastInputInfo would get me the number of milliseconds that my computer had been on when the last keypress or mousemove had been made. I then just subtracted the GetLastInputInfo from the GetTickCount and divided the result by 60000 to get how long in minutes the computer had been idle. But in foxpro, I can't use the GetLastInputInfo the same way because of the syntax. I'm stuck. I don't know how to translate the 8 character that GetLastInputInfo returns.
09/07/04 03:23 PM, ID: 11516446
Thank you for pointing me in the right direction!
Here's how I got it to work

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:
(m.iTime - m.iLast) / 60000


--------------------

---------------------

http://www.experts-exchange.com/Microsoft/Applications/FoxPro/Q_25534460.html



Asked by SystmProg in FoxPro Database

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)?



SystmProg:
26/03/10 06:43 AM, ID: 28683077
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!
26/03/10 07:40 AM, ID: 28687813
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.
26/03/10 09:59 AM, ID: 28700432
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
26/03/10 10:55 AM, ID: 28704754
I didn't write "loop is not necessary"...  I wrote continuous loop is not necessary... 

The loop is necessary but you may wait in each pass, so the CPU loading will be minimal.

Following example calculates CPU loading based on GetSystemTimes. You may check CPU loading for continuous loop or when waiting for a key press by INKEY (just un/comment appropriate lines):
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
clear

DECLARE integer
GetSystemTimes IN "kernel32.dll" string @, string @, string @

t1
= SECONDS()
a1
= repl(CHR(0),8)
b1
= repl(CHR(0),8)
c1
= repl(CHR(0),8)
? GetSystemTimes(@a1,@b1,@c1)
a1
= str2bi(a1)
b1
= str2bi(b1)
c1
= str2bi(c1)
DO WHILE SECONDS
()-t1 < 10
ENDDO
*=INKEY(10)
t2
= SECONDS()
a2
= repl(CHR(0),8)
b2
= repl(CHR(0),8)
c2
= repl(CHR(0),8)
? GetSystemTimes(@a2,@b2,@c2)
a2
= str2bi(a2)
b2
= str2bi(b2)
c2
= str2bi(c2)
st
= (b2-b1)+(c2-c1)

? "Waiting period: ", t2-t1, "s"
? "CPU usage %: ", (st-(a2-a1))/st*100
*? a2-a1
*? b2-b1
*? c2-c1


PROCEDURE
Str2BI
LPARAMETERS lcString

LOCAL lnOut
, laPower256[8]
lnOut
= 0
laPower256
[1] = 1
laPower256
[2] = 256
laPower256
[3] = 256*256
laPower256
[4] = 256*256*256
laPower256
[5] = 256*256*256*256
laPower256
[6] = 256*256*256*256*256
laPower256
[7] = 256*256*256*256*256*256
laPower256
[8] = 256*256*256*256*256*256*256

FOR lnI
= 1 TO 8
  lnOut
= lnOut + ASC(SUBSTR(lcString, lnI, 1))*laPower256[lnI]
NEXT

RETURN lnOut
26/03/10 11:37 AM, ID: 28708040
Thank You
Much appreciated!
27/03/10 02:43 AM, ID: 28758529
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

27/03/10 03:30 AM, ID: 28760911
You could try ZOOM WINDOW mn1 MIN
or  _screen.WindowState = 2


 9/19/2011 12:18:58 PM
User is offlinemmarius28
139 posts
5th


Re: Evenimente mouse si tastatura
 (N/A)
 gavroche wrote
Site-ul ala iti cere sa te inregistrezi ca sa vezi raspunsurile, iar la inregistrare iti cere cardul de credit.
Daca tu ai cont acolo posteaza tu te rog raspunsul aici.
Multumesc.


Am vazut si eu ca daca intri direct pe link te pune sa te inregistrezi.
Eu am cautat pe google si am intrat de pe linkul de pe google.

 9/19/2011 3:10:52 PM
User is offlinegavroche
82 posts


Re: Evenimente mouse si tastatura
 (N/A)
Multumesc frumos.
Pe baza informatiilor oferite am reusit.
Pentru cine vrea codul simplificat:
===========================
Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii
=======================================
Iar intr-un timer event scrieti:
=======================================
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 = millisecunde de la pornirea calculatorului.
&&** iLast = millisecunde de la pornirea calculatorului si activitate pe tastatura sau mouse.
   minute = 5
    If (m.iTime - m.iLast) / 60000>= minute &&** Idle timeout in minute
      Wait window "Inactivitate detectata."
    Endif
  Visual FoxPro  Visual FoxPro in general  Evenimente mous...

Search  Forum Home         

 Google Ads Minimize

    

Copyright 2002-2010 Profox   Terms Of Use  Privacy Statement