Results 1 to 10 of 10

Thread: Detect Application Idle - KeyDown not functioning

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Detect Application Idle - KeyDown not functioning

    Hi all,

    I am implementing an idle function whereby if the application has no input for a few seconds, it will refresh the DataGridView table.

    To implement, if the app is idle, an IdleTimer will start.
    If the user moves mouse or press a key, the IdleTimer will stop, hence resetting the timeout.

    Application_Idle works
    Code:
    Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)
            IdleTimer.Start()
        End Sub
    MouseMove works
    Code:
    Private Sub adminViewForm_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
            MessageBox.Show("MouseMove")
            IdleTimer.Stop()
        End Sub
    KeyDown does not work. The MessageBox does not appear.
    Code:
    Private Sub adminViewForm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
            MessageBox.Show("KeyPress")
            IdleTimer.Stop()
        End Sub

    Refresh Table
    Code:
    Private Sub IdleTimer_Tick(sender As Object, e As EventArgs) Handles IdleTimer.Tick
            EVC_ProjectsDataSet.Clear()
            ProjectsTableAdapter.Fill(EVC_ProjectsDataSet.Projects)
            save_btn.BackColor = DefaultBackColor
            AddNew_btn.Enabled = True
    
        End Sub

    Any advise is appreciated.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Detect Application Idle - KeyDown not functioning

    By default the form will not receive keyboard events if a control has focus.

    To enable it, set the KeyPreview property of the form to True.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: Detect Application Idle - KeyDown not functioning

    Quote Originally Posted by si_the_geek View Post
    By default the form will not receive keyboard events if a control has focus.

    To enable it, set the KeyPreview property of the form to True.
    How do I do that?
    I added KeyPreview but nothing happened.
    Is this the correct way?

    Code:
    Private Sub adminViewForm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
            Me.KeyPreview = True
            MessageBox.Show("KeyPress")
            IdleTimer.Stop()
        End Sub

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Detect Application Idle - KeyDown not functioning

    it is a design time property of the form... you set it at design time so that it is set BEFORE your event... if you don't change the keypreview until after the event fires... but you need the property set before the event can fire.... not only have you put the cart before the horse, but the cart is in the next town ahead.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: Detect Application Idle - KeyDown not functioning

    So in short, I should add in Form_Load.

    Got it.

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Detect Application Idle - KeyDown not functioning

    you could... I wouldn't... I'd set it at design time...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: Detect Application Idle - KeyDown not functioning

    Quote Originally Posted by techgnome View Post
    you could... I wouldn't... I'd set it at design time...

    -tg
    Please elaborate what you mean by Design Time.

  8. #8
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Detect Application Idle - KeyDown not functioning

    When you are creating forms visually in Visual Studio by adding your form and dragging and dropping your controls e.t.c thats your design time or design mode.

    Select your form, go to the properties window, look for the property KeyPreview and change it from False to True
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Detect Application Idle - KeyDown not functioning

    you know.. at design time... when you're designing the form.. .as in not run-time, which is when your app is running.
    when you have the IDE open and the app isn't running, that's "design time" mode... where you "design" the forms and what nots.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    69

    Re: Detect Application Idle - KeyDown not functioning

    I see.

    Thanks. I didn't notice that the property was available.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width