.NET Framework Class Library
ControlProcessCmdKey Method

Processes a command key.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Syntax
<[%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_0%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_1%].LinkDemand, Flags := [%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_2%].UnmanagedCode)> _
<[%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_3%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_4%].InheritanceDemand, Flags := [%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_5%].UnmanagedCode)> _
Protected Overridable Function ProcessCmdKey ( _
	ByRef msg As [%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_6%], _
	keyData As [%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_7%] _
) As [%$TOPIC/zask62fx_en-us_VS_110_1_0_0_0_8%]
[[%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_0%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_1%].LinkDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_2%].UnmanagedCode)]
[[%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_3%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_4%].InheritanceDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_5%].UnmanagedCode)]
protected virtual [%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_6%] ProcessCmdKey(
	ref [%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_7%] msg,
	[%$TOPIC/zask62fx_en-us_VS_110_1_0_1_0_8%] keyData
)
[[%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_0%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_1%]::LinkDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_2%]::UnmanagedCode)]
[[%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_3%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_4%]::InheritanceDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_5%]::UnmanagedCode)]
protected:
virtual [%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_6%] ProcessCmdKey(
	[%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_7%]% msg, 
	[%$TOPIC/zask62fx_en-us_VS_110_1_0_2_0_8%] keyData
)
[<[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_0%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_1%].LinkDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_2%].UnmanagedCode)>]
[<[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_3%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_4%].InheritanceDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_5%].UnmanagedCode)>]
abstract ProcessCmdKey : 
        msg:[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_6%] byref * 
        keyData:[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_7%] -> [%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_8%] 
[<[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_9%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_10%].LinkDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_11%].UnmanagedCode)>]
[<[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_12%]([%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_13%].InheritanceDemand, Flags = [%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_14%].UnmanagedCode)>]
override ProcessCmdKey : 
        msg:[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_15%] byref * 
        keyData:[%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_16%] -> [%$TOPIC/zask62fx_en-us_VS_110_1_0_3_0_17%]
protected function ProcessCmdKey(
	msg : [%$TOPIC/zask62fx_en-us_VS_110_1_0_4_0_0%], 
	keyData : [%$TOPIC/zask62fx_en-us_VS_110_1_0_4_0_1%]
) : [%$TOPIC/zask62fx_en-us_VS_110_1_0_4_0_2%]

Parameters

msg
Type: System.Windows.FormsMessage

A Message, passed by reference, that represents the window message to process.

keyData
Type: System.Windows.FormsKeys

One of the Keys values that represents the key to process.

Return Value

Type: SystemBoolean
true if the character was processed by the control; otherwise, false.
Remarks

This method is called during message preprocessing to handle command keys. Command keys are keys that always take precedence over regular input keys. Examples of command keys include accelerators and menu shortcuts. The method must return true to indicate that it has processed the command key, or false to indicate that the key is not a command key. This method is only called when the control is hosted in a Windows Forms application or as an ActiveX control.

The ProcessCmdKey method first determines whether the control has a ContextMenu, and if so, enables the ContextMenu to process the command key. If the command key is not a menu shortcut and the control has a parent, the key is passed to the parent's ProcessCmdKey method. The net effect is that command keys are "bubbled" up the control hierarchy. In addition to the key the user pressed, the key data also indicates which, if any, modifier keys were pressed at the same time as the key. Modifier keys include the SHIFT, CTRL, and ALT keys.

Notes to Inheritors

When overriding the ProcessCmdKey method in a derived class, a control should return true to indicate that it has processed the key. For keys that are not processed by the control, the result of calling the base class's ProcessCmdKey method should be returned. Controls will seldom, if ever, need to override this method.

Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
.NET Framework Security