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:
For instance, if you need to change the key combination to ALT + SPACE you need to define the ContextKey property like bellow:
With Expression1 .ContextKey = vbKeySpace + 256 * 2 End With
or
With Expression1 .ContextKey = 32 + 256 * 2 End With
since the code for SPACE key is 32. By default, the ContextKey property is 288.
If you need to have a combination like SHIFT + CTRL + F1 you need to define the ContextKey property like follows:
With Expression1 .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 Expression1_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