property Edit.ContextKey as Long
Specifies the key combination that opens the control's context window.

 TypeDescription 
   Long A long expression that defines the key combination to open the control's context window.    
The ContextKey property specifies the key combination to display the control's context window. By default, the key combination to open the control's context window is CTRL + SPACE. The low byte of the ContextKey property specifies the code of the key, and the high byte of the lowest word of the ContextKey property is a bit combination of the CTRL, SHIFT and ALT keys state. Use the Context property to access the control's context collection. Use the Add method to add new items to the context collection. The ShowContext method shows programmatically the control's context, as the user would press the CTRL + SPACE key. The ChangeOnKey property specifies the code of the last key that alters the control's text.

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 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.

If you need to have a combination like SHIFT + CTRL +  F1 you need to define the ContextKey property like follows:

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


Send comments on this topic.
1999-2016 Exontrol.COM, Software. All rights reserved.