Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Close program after period of inactivity

Posted on 2012-04-10
8
Medium Priority
?
1,311 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 43

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 43

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 43

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 43

Accepted Solution

by:
pcelba earned 2000 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 43

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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