KeyDownEventHandler Delegate

Summary

Represents the method that will handle an event that has received KeyDownEventArgs data.

Syntax
C#
VB
C++
public delegate void KeyDownEventHandler( 
   object sender, 
   KeyDownEventArgs e 
) 
Public Delegate Sub KeyDownEventHandler( _ 
   ByVal sender As Object, _ 
   ByVal e As KeyDownEventArgs _ 
)  
public delegate void KeyDownEventHandler(  
   Object^ sender, 
   KeyDownEventArgs^ e 
) 

Parameters

sender
The source of the event.

e
A KeyDownEventArgs object that contains the event data.

Remarks

Represents the method that will handle an event that has received KeyDownEventArgs data. When the KeyDownEvent event is raised in a toolkit object, any subscribed event handlers in your code will be called. See the Microsoft documentation on .NET Events and Delegates for more information about .NET delegates and events.

Example
C#
VB
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
public bool _result = false; 
public bool _exit = false; 
public CaptureCtrlForm _form = new CaptureCtrlForm(); 
 
public void KeyPressesExample() 
{ 
   CaptureCtrl capturectrl = _form.CaptureCtrl; 
   string outFile = Path.Combine(LEAD_VARS.MediaDir, "CaptureCtrl_KeyPressesExample.avi"); 
 
   try 
   { 
      // set a video device, use the name of your device here 
      if (capturectrl.VideoDevices["Analog"] == null) 
         throw new Exception("No Analog capture device available"); 
 
      capturectrl.VideoDevices["Analog"].Selected = true; 
 
      // select the MPEG4 video compressor 
      capturectrl.VideoCompressors.Mpeg4.Selected = true; 
 
      // set an audio device, use the name of your device here 
      capturectrl.AudioDevices["USB"].Selected = true; 
 
      // enable preview 
      capturectrl.Preview = true; 
 
      // enable CC 
      capturectrl.ClosedCaptioning = true; 
 
      // set the target output file 
      capturectrl.TargetFile = outFile; 
 
      // subscribe to the key events 
      capturectrl.KeyDown += KeyDown_Helper; 
      capturectrl.KeyUp += KeyUp_Helper; 
      capturectrl.KeyPress += KeyPress_Helper; 
 
      // capture it now! 
      capturectrl.StartCapture(CaptureMode.AutoFramesAndAudio); 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
 
   // we'll loop on the state and pump messages for this example. 
   // but you should not need to if running from a Windows Forms application. 
   while (_exit == false) 
      Application.DoEvents(); 
 
   // clean up event handlers 
   capturectrl.KeyDown -= KeyDown_Helper; 
   capturectrl.KeyUp -= KeyUp_Helper; 
   capturectrl.KeyPress -= KeyPress_Helper; 
} 
 
void KeyPress_Helper(object sender, Leadtools.Multimedia.KeyPressEventArgs e) 
{ 
   switch ((char)e.keyAscii) 
   { 
      case 'p': 
         // toggle preview mode 
         _form.CaptureCtrl.TogglePreview(); 
         break; 
      case 'f': 
         // toggle full screen mode 
         _form.CaptureCtrl.ToggleFullScreenMode(); 
         break; 
      case 'c': 
         // toggle closed captioning 
         _form.CaptureCtrl.ToggleClosedCaptioning(); 
         break; 
      case 's': 
         // stop the capture and exit 
         _form.CaptureCtrl.StopCapture(); 
         _exit = true; 
         break; 
   } 
 
   // set result 
   _result = true; 
} 
 
void KeyUp_Helper(object sender, KeyUpEventArgs e) 
{ 
   // set result 
   _result = true; 
} 
 
public void KeyDown_Helper(object sender, KeyDownEventArgs e) 
{ 
   // set result 
   _result = true; 
} 
 
static class LEAD_VARS 
{ 
   public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 20\Media"; 
} 
Imports Leadtools 
Imports Leadtools.Multimedia 
Imports LeadtoolsMultimediaExamples.Fixtures 
 
Public _result As Boolean = False 
Public _exit As Boolean = False 
Public _form As CaptureCtrlForm = New CaptureCtrlForm() 
 
Public Sub KeyPressesExample() 
   Dim capturectrl As CaptureCtrl = _form.CaptureCtrl 
   Dim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "CaptureCtrl_KeyPressesExample.avi") 
 
   Try 
      ' set a video device, use the name of your device here 
      If capturectrl.VideoDevices("Analog") Is Nothing Then 
         Throw New Exception("No Analog capture device available") 
      End If 
 
      capturectrl.VideoDevices("Analog").Selected = True 
 
      ' select the MPEG4 video compressor 
      capturectrl.VideoCompressors.Mpeg4.Selected = True 
 
      ' set an audio device, use the name of your device here 
      capturectrl.AudioDevices("USB").Selected = True 
 
      ' enable preview 
      capturectrl.Preview = True 
 
      ' enable CC 
      capturectrl.ClosedCaptioning = True 
 
      ' set the target output file 
      capturectrl.TargetFile = outFile 
 
      ' subscribe to the key events 
      AddHandler capturectrl.KeyDown, AddressOf KeyDown_Helper 
      AddHandler capturectrl.KeyUp, AddressOf KeyUp_Helper 
      AddHandler capturectrl.KeyPress, AddressOf KeyPress_Helper 
 
      ' capture it now! 
      capturectrl.StartCapture(CaptureMode.AutoFramesAndAudio) 
   Catch e1 As Exception 
      _result = False 
   End Try 
 
   ' we'll loop on the state and pump messages for this example. 
   ' but you should not need to if running from a Windows Forms application. 
   Do While _exit = False 
      Application.DoEvents() 
   Loop 
 
   ' clean up event handlers 
   RemoveHandler capturectrl.KeyDown, AddressOf KeyDown_Helper 
   RemoveHandler capturectrl.KeyUp, AddressOf KeyUp_Helper 
   RemoveHandler capturectrl.KeyPress, AddressOf KeyPress_Helper 
End Sub 
 
Private Sub KeyPress_Helper(ByVal sender As Object, ByVal e As Leadtools.Multimedia.KeyPressEventArgs) 
   Select Case e.keyAscii 
      Case CShort("p") 
         ' toggle preview mode 
         _form.CaptureCtrl.TogglePreview() 
      Case CShort("f") 
         ' toggle full screen mode 
         _form.CaptureCtrl.ToggleFullScreenMode() 
      Case CShort("c") 
         ' toggle closed captioning 
         _form.CaptureCtrl.ToggleClosedCaptioning() 
      Case CShort("s") 
         ' stop the capture and exit 
         _form.CaptureCtrl.StopCapture() 
         _exit = True 
   End Select 
 
   ' set result 
   _result = True 
End Sub 
 
Private Sub KeyUp_Helper(ByVal sender As Object, ByVal e As KeyUpEventArgs) 
   ' set result 
   _result = True 
End Sub 
 
Public Sub KeyDown_Helper(ByVal sender As Object, ByVal e As KeyDownEventArgs) 
   ' set result 
   _result = True 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 20\Media" 
End Class 

Requirements

Target Platforms

See Also

Reference

KeyDownEventHandler Members

Leadtools.Multimedia Namespace

Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Multimedia Assembly