
| Type | Description | |||
| Long | A long expression that defines the key combination to open the control's context window. |
The following formula should be used to specify a key combination:
ContextKey = (KeyCode) + (256 * ( 1 * Ctrl + 2 * Alt + 4 * Shift) )
where:
The following VB sample shows how to set the ContextKey property to ALT + SPACE:
With Edit1
.ContextKey = vbKeySpace + 256 * 2
End With
or
With Edit1
.ContextKey = 32 + 256 * 2
End With
since the code for SPACE key is 32. By default, the ContextKey property is 288.
The following VB sample shows how to set the ContextKey property to SHIFT + CTRL + F1:
With Edit1
.ContextKey = vbKeyF1 + 256 * (1 + 4)
End With
How can I find the key code? The easiest way to find out the code for a key is to add a handler for KeyDown event like follows:
Private Sub Edit1_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print KeyCode
End Sub
Important to notice is that the control's context window is not the control's context menu. The control's context window is shown when user presses the ContextKey combination, instead the control's context menu is displayed when user does a right click