User inactivity and returning to main form vb.net

Discussion in 'Mixed Languages' started by kjsupe, Sep 30, 2012.

  1. kjsupe

    kjsupe MDL Novice

    Sep 30, 2012
    3
    0
    0
    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. This is really the last piece I need to complete this project. Many thanks in advance!
     
  2. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,097
    120
    Maybe you can make an timer that stores every second the mouse pointer location and if is equals on a time period, closes the form and back to the main again.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    Just experimenting with something now. I'll post the project if it goes ok.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    #4 QuantumBug, Sep 30, 2012
    Last edited: Oct 1, 2012
    Ok, here you go, it's working well for me.

    Using wndproc the second form will close if no message is sent to the form e.i, no mousemove, no keydown, no form move, etc. I wrote it with Visual Studio 2010 so you can study the source closely.

    http://www.mediafire.com/?6awu6cp2u96vm12

    Edit: If you need more help, please feel free to ask.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. kjsupe

    kjsupe MDL Novice

    Sep 30, 2012
    3
    0
    0
    Thank a million, this worked great. The one issue I am seeing is that it will not work on one of my forms however. Its really no big deal as it works great on the others. The form it is not working on just has a text box that gets focus as soon as the form loads (so it has a blinking cursor). Not sure what all Wndproc looks for, but I can't figure out why it won't return from that screen. Any ideas?
     
  6. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,438
    3,578
    120
    Not sure how you would do it in VB.net, but I would think that you have to subclass the edit controls' WndProc, look at its' messages and respond to the ones that you want to work with.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    #7 QuantumBug, Oct 2, 2012
    Last edited: Oct 2, 2012
    Well, the reason the form may not be closing is because wndproc will be waiting for a reply as the cursor is blinking, or possibly the blinking cursor may be detected as activity.

    Maybe set the textbox to lose focus after 5 seconds if no text is typed and set the form timeout from (0, 0, 30) to (0, 0, 25).

    EDIT: If you have no luck solving this, I can always update the source with a solution asap.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...