-
Hello,
Here is my problem.
When the user is on my form and if he / she hits ctrl + enter at the same time, I want certain text from a text box to move to another text box.
So im thinking I would do this is a form1_keypressevent??
enter key is chr(13) but what is the ctrl key?
Any help.
Thanks.
-
Instead of using the KeyPress event, use the KeyDown event (or KeyUp, but try down first). That way, you can check Shift to see if shift, control, or alt was pressed when the event was fired.
-
As Kaverin said. Shift will return 2 if ctrl was pressed.
-
you have to trap keycode
You have to write the code either in keyDown or keyUp not in keyascii.Since keyascii cannot trap the ctrl key whereas keycode traps it.
So the keycode for ctrl key is 17.
When you want to trap the code of function keys and the keys like ctrl,alt etc then you have to use keycode.
Hope iam clear
regards
-
I understand it now anilgoje. Thanks for all of your help people.
-
This will work...
This code will capture the "Ctrl + Enter" keys and display a message box when they are pressed.
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyReturn) And (Shift = vbCtrlMask) Then
MsgBox "You pressed Ctrl + Enter"
End If
End Sub
[Edited by seaweed on 11-06-2000 at 02:20 PM]
-
hmmm
I have tried both ways and It is still not working.
First way.
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if chr(13) and chr(17) then
msgbox"working?"
end if
End Sub
'// second way
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyReturn) And (Shift = vbCtrlMask) Then
MsgBox "You pressed Ctrl + Enter"
End If
End Sub
Any ideas?
-
um....
I think its not working because the first way has
Code:
MsgBox"working"
'and not
MsgBox "working"
If not then i dont know
-
No that isnt the problem. I am only putting msgbox's up there so I can see if it works before I put in the rest of my code. :)
I have also tried keyup as well as keydown events.