|
-
Apr 25th, 2005, 10:20 AM
#1
Thread Starter
Addicted Member
Certain Keys Pressed??
Say i wanted to make a msgbox come up when the user presses Ctrl + K (or any other keys for that matter)
Thx
Nothing is Impossible you say?......Try slamming a revolving door!
-
Apr 25th, 2005, 10:22 AM
#2
Re: Certain Keys Pressed??
Set the KeyPreview property of your Form to true. Then test for the desired keys in the Form_KeyDown or KeyUp event.
"It's cold gin time again ..."
Check out my website here.
-
Apr 25th, 2005, 10:31 AM
#3
Thread Starter
Addicted Member
Re: Certain Keys Pressed??
i still dont get what code is involved etc...
Thx anyway
Nothing is Impossible you say?......Try slamming a revolving door!
-
Apr 25th, 2005, 10:45 AM
#4
Thread Starter
Addicted Member
Re: Certain Keys Pressed??
ok i have fidled around with that and iv got
VB Code:
KeyCode = "5"
msgbox "Wee"
as i guessed since keycode is integer but hwo would you do the above with letters?
Nothing is Impossible you say?......Try slamming a revolving door!
-
Apr 25th, 2005, 10:47 AM
#5
Lively Member
Re: Certain Keys Pressed??
Dont know if this will help
It doesnt work with letter but it will work with numbers
VB Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
KeyCode = "k"
MsgBox "maw"
End Sub
There u go
-
Apr 25th, 2005, 11:01 AM
#6
Need-a-life Member
Re: Certain Keys Pressed??
Try this:
VB Code:
Option Explicit
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyK Then
If Shift And vbCtrlMask > 0 Then
MsgBox "Ctrl+K was pressed"
End If
End If
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 25th, 2005, 11:02 AM
#7
Addicted Member
Re: Certain Keys Pressed??
VB Code:
If KeyCode = vbKeyK Then 'If the "K" key is pressed.
If Shift and vbCtrlMask Then 'If Control is held down
Msgbox "Hello"
EndIf
EndIf
-
Apr 25th, 2005, 11:02 AM
#8
Need-a-life Member
Re: Certain Keys Pressed??
 Originally Posted by Aaron Smith
Dont know if this will help
It doesnt work with letter but it will work with numbers
VB Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
KeyCode = "k"
MsgBox "maw"
End Sub
There u go
Won't ever work!! KeyCode is an integer... and you're trying to assign a string value.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 20th, 2005, 08:53 AM
#9
-
Jul 20th, 2005, 01:11 PM
#10
Need-a-life Member
Re: Certain Keys Pressed??
 Originally Posted by harishs
try out this 1
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyK And Shift = vbCtrlMask Then
MsgBox "Got Ctrl + K"
End If
End Sub
Happy Coding
harry
No, shift might not be equal to vbCtrlMask. It should be Shift And vbCtrlMask > 0.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
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
|