1 Replies - 4331 Views - Last Post: 09 October 2012 - 08:32 AM Rate Topic: -----

#1 kjsupe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-October 12

User inactivity and returning to the main form

Posted 09 October 2012 - 08:14 AM

Hopefully this is an easy problem for some of you code gurus out there. I am by no means an expert coder, far from it actually. I am writing a Kiosk interface for a rewards program at my work and I just need a simple snippet of code that will return to the main form after 30 seconds of no user activity. I would like to monitor globally and not just in my program. It is a touch screen system, so I don't need to detect keystrokes, only mouse movements. I have 5 different forms and if any of the 2-5 forms are open with no user input for more than 30 seconds, I would like to close them and return to form1. Here is what I have used (thanks to a member in another forum) but it seems to only work on some of my forms and not all. Is there a way to not use wndproc and instead use something else? I think that is the root of the problem with it working sporadically.

'inactivity timer code
    Dim inActivity As New Stopwatch

    Protected Overrides Sub WndProc(ByRef m As Message)
        'Listen for operating system messages to the application. If the form to expire is moved, mousemove detected, keydown detected it will stay open
        'When no message is sent from the OS within 30 seconds the form will expire.
    End Sub
    Private Sub loadevent(ByVal sender As Object, ByVal e As System.EventArgs)
        formtimeout.Interval = 1 * 1000 'check every 1 second for new messages from the OS
    End Sub
    Public Sub resetActivity()
    End Sub

    Private ReadOnly maxInactivity As New TimeSpan(0, 0, 15) '15 second timeout - integer (Hours, Minutes, Seconds) in your case (0 hours, 0 minutes, 30 seconds)

    Private Sub form_timeout(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles formtimeout.Tick

        If inActivity.Elapsed > maxInactivity Then
            Dim Formhome As New Form1
        End If

    End Sub

Thanks in advance for any assistance on this if anyone has a better way of doing this.

Is This A Good Question/Topic? 0
  • +

Replies To: User inactivity and returning to the main form

#2 modi123_1   User is online

  • Suitor #2
  • member icon

Reputation: 14092
  • View blog
  • Posts: 56,461
  • Joined: 12-June 08

Re: User inactivity and returning to the main form

Posted 09 October 2012 - 08:32 AM

I would think it would be as straight forward as slapping a timer down on the form and when the mouse 'hovers' kick off the timer.... the timer's interval then triggers at what ever time you want.. when that happens it stops the timer and brings the other form 'to top' and 'focused'.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1