Click to See Complete Forum and Search --> : Catching vbReturn results in a BEEP sound, why??
Uwe Reimann
May 21st, 1999, 12:50 PM
Hi there,
this one will hunt me for the rest of my life I fear! Already in my MFC applications I encountered the problem that when I try to catch the "Return" (enter) keycode in the keydown event, the system still
plays a beeping sound to indicated something is wrong (aka wrong key is pressed).
Here what I am doing:
private Sub CtrlEdit_KeyDown(KeyCode as Integer, Shift as Integer)
Dim ShiftDown as Boolean
Dim AltDown as Boolean
Dim CtrlDown as Boolean
Dim AnyDown as Boolean
ShiftDown = (Shift And vbShiftMask) > 0
AltDown = (Shift And vbAltMask) > 0
CtrlDown = (Shift And vbCtrlMask) > 0
AnyDown = ShiftDown Or AltDown Or CtrlDown
If AnyDown then
Exit Sub
End If
Select Case KeyCode
Case vbKeyReturn', vbKeyExecute
' some stuff here
'KeyCode = 0 ' already tried this to mark this key-event as done
end select
Any hints how to get rid of this annoying sound?
(btw: same happens for tab and escape character)
Crazy D
May 22nd, 1999, 03:55 PM
Hi
It surprises me that the enter key beeps with youre code. The code with Keycode = 0 not as comment that is... I use pretty the same thing, although the first thing I do when the enter is pressed, is setting the keycode to 0, and then I do some other stuff.
Maybe that's why it doesn't beep here and it does with you.
Crazy D :-)
Gordito Supreme
May 22nd, 1999, 06:25 PM
All you do is set the keycode to 0 like you commented out in your code and it gets rid of the annoying beep.
Gordito
Ravi Kiran
May 23rd, 1999, 10:17 PM
Hi,
I guess you are using single line Text box.
You might have to 'eat' away the key stroke in KeyPress event also.
Take a look at the following code, and the trace output that follows: (A form with a text box):
private Sub Text1_KeyDown(KeyCode as Integer, Shift as Integer)
Debug.print "KeyDown : Before altering: keycode = " & Str(KeyCode)
If KeyCode = vbKeyReturn then KeyCode = 0
Debug.print "KeyDown : After altering: keycode = " & Str(KeyCode)
End Sub
private Sub Text1_KeyPress(KeyAscii as Integer)
Debug.print "KeyPress : Before altering: keyAscii = " & Str(KeyAscii)
If KeyAscii = vbKeyReturn then KeyAscii = 0
Debug.print "KeyPress : After altering: keyAscii = " & Str(KeyAscii)
End Sub
and the trace output is like this:
KeyDown : Before altering: keycode = 13
KeyDown : After altering: keycode = 0
KeyPress : Before altering: keyAscii = 13
KeyPress : After altering: keyAscii = 0
So, it is clear that VB still generates a KeyPress event with KeyAscii = 13 (enter key) even though you set the keycode to 0 in keydown.
Probably the way Keydown is connected internally to keypress in not all that straight forward!!.
and single line text box doesnt like enter in KeyPress so beeps.
Comment out the code in KeyPress and it still beeps.
Ravi
citems
December 13th, 2006, 11:27 PM
Private Sub TreeView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TreeView1.KeyDown
'''''TRY ADDING THESE TWO'''''''''
e.Handled = True
e.SuppressKeyPress = True
'''''TRY ADDING THESE TWO'''''''''
If Not Me.TreeView1.SelectedNode Is Nothing Then
If e.Control = True Then
Select Case e.KeyCode
Case Keys.R
Me.cmnuRename_Click(Nothing, Nothing)
End Select
End If
End If
End Sub
LET ME KNOW!!!
From,
CITEMS
HanneSThEGreaT
December 14th, 2006, 12:18 AM
Citems, that's VB.NET code :p
moa
December 14th, 2006, 01:44 AM
If you use the Keydown event for certain purposes (other keys), you should at the same time use the keypress event for certain keys :
Try this in a not multiline textbox (so that an ENTER sould provoque a beep)
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Keycode = 0
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
No beep !
Note : it would not be necessary to use the keydown event at all, of course
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.