|
-
Oct 18th, 2016, 11:00 PM
#1
Thread Starter
Lively Member
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.
-
Oct 19th, 2016, 02:19 AM
#2
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.
-
Oct 19th, 2016, 07:58 AM
#3
Thread Starter
Lively Member
Re: Detect Application Idle - KeyDown not functioning
 Originally Posted by si_the_geek
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
-
Oct 19th, 2016, 08:30 AM
#4
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
-
Oct 19th, 2016, 09:01 AM
#5
Thread Starter
Lively Member
Re: Detect Application Idle - KeyDown not functioning
So in short, I should add in Form_Load.
Got it.
-
Oct 19th, 2016, 09:10 AM
#6
Re: Detect Application Idle - KeyDown not functioning
you could... I wouldn't... I'd set it at design time...
-tg
-
Oct 19th, 2016, 09:48 AM
#7
Thread Starter
Lively Member
Re: Detect Application Idle - KeyDown not functioning
 Originally Posted by techgnome
you could... I wouldn't... I'd set it at design time...
-tg
Please elaborate what you mean by Design Time.
-
Oct 19th, 2016, 10:06 AM
#8
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
-
Oct 19th, 2016, 10:10 AM
#9
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
-
Oct 19th, 2016, 10:46 PM
#10
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|