Solved

Close program after period of inactivity

Posted on 2012-04-10
8
1,185 Views
Last Modified: 2012-06-21
In my business i potentially have instances of my program open on various networked computers.  I would like to have the instances "Time out" if there was no keyboard or mouse activity after a certain period of time, say 15 or 30 minutes and return the program back to the login screen.  Keep in mind i need it as simple as possible (i'm a still a bit of a newbie).

Unfortunately i don't like the new experts exchange website and find it hard to search for just foxpro solutions. (Maybe someone can also clue me in on how to do that more easily).

Sincerely,
Dean
0
Comment
Question by:phantomcom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 37829774
Bryan_123 posted a piece of code (http://www.experts-exchange.com/Microsoft/Applications/FoxPro/Q_21053578.html) which you can use in a timer to determine the last user input and do appropriate action:
CLEAR

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

DO WHILE .t.
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))

TotTime=(m.iTime - m.iLast) / 1000

*? m.iTime, m.iLast, totTime
? "Inactivity TIME:", totTime, "s"

lcKey=INKEY(0.5)
IF lcKey = 27  && Esc key
  EXIT
ENDIF

ENDDO

Open in new window

0
 
LVL 42

Expert Comment

by:pcelba
ID: 37829779
To answer your second question: use Google to search EE.
0
 

Author Comment

by:phantomcom
ID: 37829958
Should i place the above code on the click event of my login form?

Dean
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Expert Comment

by:pcelba
ID: 37830015
No, not at all. The code is just an example how the idle time is calculated and you may use this code in Command window.

To incorporate the main part of the code (without the DO WHILE loop) into your application you should find the right place where you may define e.g. the timer.

You should check the inactivity time in the Timer event and if the inactive time is long enough then you should log the user out and display the login form.

The timer should be created on a form which is still active or visible or exists at least. It can even be the main FoxPro window referenced by _screen variable.

Implementation details depend on your app architecture.
0
 

Author Comment

by:phantomcom
ID: 37832476
i added the timer object to the most appropriate form. I changed the interval within the timer object to 20000 milliseconds just for testing purposes. Do i now place the above code in the timer procedure? (Remember i'm a bit of a newbie still).

Here's what i added under the timer procedure:

CLEAR

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

TotTime=(m.iTime - m.iLast) / 20000

*? m.iTime, m.iLast, totTime
? "Inactivity TIME:", totTime, "s"

lcKey=INKEY(0.5)
IF lcKey = 27  && Esc key
  EXIT
ENDIF

Pretty much the same as the above code. After 20 seconds the cursor disappears but nothing else happens. If i move the mouse the cursor reappears.

What's next to get this to work.

Dean
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 37833626
You are closer now.

The declaration part should be executed just once so you should place the following commands into your app startup part:

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

Timer event should contain following code:
Local iTime As Integer, iLast As Integer
Local plii As String, cLast As String, totTime

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

TotTime=(m.iTime - m.iLast) / 1000  && this constant must remain 1000

IF m.totTime > 20  && test for 20 secs 
  *-- Actions when the code waits longer than 20 sec
  THIS.Enabled = .F.  && Disable the Timer
  WAIT WINDOW "Inactive longer than 20 sec ... QUIT in 3 secs" TIME 3
  QUIT
ELSE
  WAIT WINDOW "Inactive " + TRANSFORM(m.totTime) + " sec" NOWAIT
ENDIF

Open in new window


To better see what's hapenning you may set the Timer.Interval to 1000 ms. You have to write your own code in at the end of the above code sample. The interval in the real application can be e.g. 5 minutes - no need to check inactivity every minute.

The Timer can remain disabled when no user is logged in. If the user logs in then you may enable the Timer by setting its Enabled property to .T.:

YourForm.YourTimer.Enabled = .T.
YourForm.YourTimer.Interval = ...
0
 

Author Comment

by:phantomcom
ID: 37835526
Horray! It appears to work. Just to make sure i understand correctly the "IF m.totTime > 20" the 20 is seconds so at this point if i want it to wait 15 minutes before timeout i would set it for 900 seconds.

Currently the code shuts down (quits) the whole program. How can i get it to close the current form and return to the login screen which is login.scx.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 37836327
Yes, 900 is 15 minutes.
To answer your question how to display the login screen is more difficult because it depends on your app architecture. You'll probably need to log the current user off, so you have to call the routine used for log-off process. Then you may display the log-in form as you do when the application starts. The simplest command is "DO FORM login" but each application handles the form creation in a different way so you will need to study your code a bit.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question