PowerTCP Emulation for .NET CF
KeyDown Event
See Also  Example Send comments on this topic.
Dart.Emulation Namespace > Vt Class : KeyDown Event




Raised when the user presses a key.

Syntax

Visual Basic (Declaration) 
Public Shadows Event KeyDown As KeyDownHandler
Visual Basic (Usage)Copy Code
Dim instance As Vt
Dim handler As KeyDownHandler
 
AddHandler instance.KeyDown, handler
C# 
public new event KeyDownHandler KeyDown
Managed Extensions for C++ 
public: new __event KeyDownHandler* KeyDown
C++/CLI 
public:
new event KeyDownHandler^ KeyDown

Event Data

The event handler receives an argument of type VtKeyEventArgs containing data related to this event. The following VtKeyEventArgs properties provide information specific to this event.

PropertyDescription
Alt (Inherited from System.Windows.Forms.KeyEventArgs) 
Control (Inherited from System.Windows.Forms.KeyEventArgs) 
Extended Returns true when the generating key is on an extended part of the keyboard.
Handled (Inherited from System.Windows.Forms.KeyEventArgs) 
KeyCode (Inherited from System.Windows.Forms.KeyEventArgs) 
KeyData (Inherited from System.Windows.Forms.KeyEventArgs) 
KeyValue (Inherited from System.Windows.Forms.KeyEventArgs) 
Modifiers (Inherited from System.Windows.Forms.KeyEventArgs) 
Shift (Inherited from System.Windows.Forms.KeyEventArgs) 
SuppressKeyPress (Inherited from System.Windows.Forms.KeyEventArgs) 

Example

In the following example, the string "Hello World!" is mapped to Ctrl-H.
C#Copy Code
private void vt1_KeyDown(object sender, Dart.Emulation.VtKeyEventArgs e)
{
    //If there is a telnet connection
    if (telnet1.State != Dart.Common.ConnectionState.Closed)
    {
        //Send substitute string when Control-H pressed
        if (e.Control && e.KeyCode == Keys.H)
        {
            e.Handled = true; //prevent other key events
            telnet1.Write("Hello World!");
        }
    }
}
Visual BasicCopy Code
Private Sub vt1_KeyDown(ByVal sender As Object, ByVal e As Dart.Emulation.VtKeyEventArgs)
    'If there is a telnet connection
    If telnet1.State <> Dart.Common.ConnectionState.Closed Then
        'Send substitute string when Control-H pressed
        If e.Control AndAlso e.KeyCode = Keys.H Then
            e.Handled = True 'prevent other key events
            telnet1.Write("Hello World!")
        End If
    End If
End Sub

Remarks

The KeyDown event is raised when a key is pressed and before the KeyPress event is raised. This event is useful for performing keymapping (mapping individual keys to any arbitrary character sequence). To do this, simply set e.Handled to true (notifying the Vt control that the key press was handled so the Vt control does not raise the KeyDown event) and send your own substituted character sequence.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.