Click to See Complete Forum and Search --> : How do you use KeyPress event to capture "Enter" key?
billwagnon
Nov 8th, 1999, 07:45 AM
that's it! :)
QWERTY
Nov 8th, 1999, 07:52 AM
Try this:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
'do whatever you want
End If
End Sub
------------------
Visual Basic Programmer (at least I want to be one)
------------------
PolComSoft
You will hear a lot about it.
[This message has been edited by QWERTY (edited 11-08-1999).]
billwagnon
Nov 8th, 1999, 07:58 AM
thanks!
webdeveloper
Mar 21st, 2002, 01:23 AM
The ENTER key is never detected on my system through AScii vbKey Return. I have even tried toggling the keyPreview option of the form.
I have also tried the following code but the ENTER key does not return anything. Others work well.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1: MsgBox "F1 is your friend."
Case vbKeyDelete: MsgBox "F2 could copy text."
Case vbKeyReturn: MsgBox "F3 could paste text."
Case vbKeyF4: MsgBox "F4 could format text."
End Select
End Sub
Please reply on my email address.
macai
Mar 21st, 2002, 03:14 AM
Simple.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MsgBox "Enter was pressed!"
End If
End SubDoes this help?
webdeveloper
Mar 21st, 2002, 03:27 AM
Dear Members thanks a lot for such quick response.I am thrilled. Mr Ram's observation regarding change in focus is perhaps what I am experiencing.
Mr mcai has suggested putting the code in the Text sub. It works there.
I am making a Windows like calculator where bith mouse and keyboard inputs are acceptable even if the user enters half the math expression with mouse and then decides to use keyboard .
Is there any method where I can put the detailed ( e.g Equals formula for +,-,/,sqr) code in the button's click sub routine and then call this routine in the button's KeyPress routine, thus reducing file size.
macai
Mar 21st, 2002, 03:34 AM
Excuse me, but are you saying that your program is an advanced
calculation program? A program that you can enter "5^2+(2^3)"
and it will return 33 ? If that it what you mean, this program
sounds very useful. :)
webdeveloper
Mar 21st, 2002, 03:52 AM
Well I don't say that my simple Math calculator is an advanced program at the moment. But it needs to mimic the Windows calculator which does not mind which part of an expression is comming from mouse click and which by keyboard. At the same time I need to keep the program size small i.e by avoiding repeating the code for click and keypress events.
hope I am able to convey my message.
I am really impressed by your quick responses. My friend is with me and finding it unbelievable.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.