Say i wanted to make a msgbox come up when the user presses Ctrl + K (or any other keys for that matter)
Thx :afrog:
Printable View
Say i wanted to make a msgbox come up when the user presses Ctrl + K (or any other keys for that matter)
Thx :afrog:
Set the KeyPreview property of your Form to true. Then test for the desired keys in the Form_KeyDown or KeyUp event.
i still dont get what code is involved etc...
Thx anyway
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? :thumb:
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
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
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
Won't ever work!! KeyCode is an integer... and you're trying to assign a string value.Quote:
Originally Posted by Aaron Smith
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 :thumb:
harry
No, shift might not be equal to vbCtrlMask. It should be Shift And vbCtrlMask > 0.Quote:
Originally Posted by harishs