|
-
Aug 21st, 2007, 01:10 PM
#1
[RESOLVED] [2005] Form KeyUp Enter key beeping
I've got this code:
Code:
Private Sub APC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.Enter Then
Call ButtonGo()
End If
e.Handled = False
End Sub
I've got KEYPREVIEW set as true for the form - so that pressing the ENTER key will cause this event to fire and then process the same sub that clicking the GO button does as well.
I cannot get the ENTER key to stop beeping. I've tried the e.Handled=True and =False (the help says that Handled means different things to different UI objects.
At any rate - I do not want the ENTER key to make a beep.
Note that I'm on a pocket PC - but I don't think that will make a difference.
-
Aug 21st, 2007, 01:16 PM
#2
Re: [2005] Form KeyUp Enter key beeping
Does it still do it if you;
Code:
If e.KeyValue = Keys.Return Then
e.Handled = True
End If
-
Aug 21st, 2007, 01:17 PM
#3
Re: [2005] Form KeyUp Enter key beeping
Try
Code:
If Asc(e.KeyChar) = Keys.Enter Then
Thats what I use and I don't get any beeping.
However, I'm not on a pocket PC.
-
Aug 21st, 2007, 01:19 PM
#4
Re: [2005] Form KeyUp Enter key beeping
I changed it to this:
Code:
Private Sub APC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.Return Then
'Call ButtonGo()
e.Handled = True
End If
End Sub
and it still beeps.
Of course my button function isn't being called - but yes it is still beeping.
It does not beep if I type letters on the keyboard - it's just the ENTER/RETURN key that's doing it.
-
Aug 21st, 2007, 01:20 PM
#5
Re: [2005] Form KeyUp Enter key beeping
Maybe it is the pocket PC.
Do you run similiar code on a desktop or laptop?
-
Aug 21st, 2007, 01:20 PM
#6
Re: [2005] Form KeyUp Enter key beeping
 Originally Posted by Hack
Try
Code:
If Asc(e.KeyChar) = Keys.Enter Then
Thats what I use and I don't get any beeping.
However, I'm not on a pocket PC.
Either KEYCHAR is not part of the CF or it's not in the KEYUP event...
-
Aug 21st, 2007, 01:21 PM
#7
Re: [2005] Form KeyUp Enter key beeping
I didn't notice you were using KeyUP.
Try KeyPress instead.
-
Aug 21st, 2007, 01:26 PM
#8
Re: [2005] Form KeyUp Enter key beeping
Yeah - this did get rid of the beep:
Code:
Private Sub APC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If Microsoft.VisualBasic.Asc(e.KeyChar) = Keys.Enter Then
Call ButtonGo()
e.Handled = True
End If
End Sub
Using the KEYPRESS and making sure to have the HANDLED=TRUE
Why is this?
-
Aug 21st, 2007, 10:02 PM
#9
Re: [2005] Form KeyUp Enter key beeping
The beep occurs when the key is pressed. It's too late by the time the KeyUp event is raised. If you press and hold the Enter key you get one KeyDown event and multiple KeyPress events, which would lead to multiple beeps (I think, although I can't test because my work rig has no speakers). When you release the key you get one KeyUp event and no more beeps.
-
Aug 22nd, 2007, 07:01 AM
#10
Re: [2005] Form KeyUp Enter key beeping
This is the solution:
Code:
Private Sub APC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
e.Handled = False
If Microsoft.VisualBasic.Asc(e.KeyChar) = Keys.Enter Then e.Handled = True
End Sub
Private Sub APC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.Return Then
Call ButtonGo()
End If
End Sub
Handled has to be managed from the KeyPress event. This allows any key to still be entered on the keyboard (remember this is a ppc - but it still has a graphical keyboard image).
I personally am against firing functions and subs from KeyPress - as KeyPress cannot be trusted to only occur one time for a key being clicked.
So I'm processing my ButtonGo() function in the KeyUp event.
There is no beep with this logic.
And the ButtonGo() function is not fired until I take the pin off the PPC screen. As long as I'm still pushing the ENTER key with the pin nothing happens - it's when I let go.
Thanks for all for the info that got me to this point.
-
Aug 22nd, 2007, 07:12 AM
#11
Re: [RESOLVED] [2005] Form KeyUp Enter key beeping
Just yesterday I was wondering how you would use Microsoft.VisualBasic an lo and behold, and example appears.
Code:
If Microsoft.VisualBasic.Asc(e.KeyChar) = Keys.Enter Then e.Handled = True
In my KeyPress events I am just using
Code:
If Asc(e.KeyChar) = Keys.Enter Then
I'm curious as to why you prefaced your code with Microsoft.VisualBasic
-
Aug 22nd, 2007, 07:17 AM
#12
Re: [RESOLVED] [2005] Form KeyUp Enter key beeping
 Originally Posted by Hack
...I'm curious as to why you prefaced your code with Microsoft.VisualBasic
Otherwise I have to IMPORT the namespace at the top of the app - right? I'm new to this .Net...
Maybe someone can shed some light on the differences between IMPORT of the namespace and this long-name reference. Does the namespace get fully imported anyway?
I was against using the ASC() function at all - almost felt like simply building a constant of the value 13!
-
Aug 22nd, 2007, 07:30 AM
#13
Re: [RESOLVED] [2005] Form KeyUp Enter key beeping
The only imports I'm using are for Excel and SqlClient
-
Aug 22nd, 2007, 07:54 AM
#14
Re: [RESOLVED] [2005] Form KeyUp Enter key beeping
 Originally Posted by Hack
The only imports I'm using are for Excel and SqlClient
Then it's a pocket pc thing - the compact framework has much less girth - as the PPC is a small device.
-
Aug 22nd, 2007, 08:01 AM
#15
Re: [RESOLVED] [2005] Form KeyUp Enter key beeping
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
|