public class KeyPressEventArgs : EventArgs Public Class KeyPressEventArgsInherits System.EventArgs
public ref class KeyPressEventArgs : public System.EventArgs
The KeyPressEvent event occurs when a key is pressed and a multimedia control has focus. This class is the event argument passed to the related event handler.
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 hereif (capturectrl.VideoDevices["Analog"] == null)throw new Exception("No Analog capture device available");capturectrl.VideoDevices["Analog"].Selected = true;// select the MPEG4 video compressorcapturectrl.VideoCompressors.Mpeg4.Selected = true;// set an audio device, use the name of your device herecapturectrl.AudioDevices["USB"].Selected = true;// enable previewcapturectrl.Preview = true;// enable CCcapturectrl.ClosedCaptioning = true;// set the target output filecapturectrl.TargetFile = outFile;// subscribe to the key eventscapturectrl.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 handlerscapturectrl.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 LeadtoolsImports Leadtools.MultimediaImports LeadtoolsMultimediaExamples.FixturesPublic _result As Boolean = FalsePublic _exit As Boolean = FalsePublic _form As CaptureCtrlForm = New CaptureCtrlForm()Public Sub KeyPressesExample()Dim capturectrl As CaptureCtrl = _form.CaptureCtrlDim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "CaptureCtrl_KeyPressesExample.avi")Try' set a video device, use the name of your device hereIf capturectrl.VideoDevices("Analog") Is Nothing ThenThrow New Exception("No Analog capture device available")End Ifcapturectrl.VideoDevices("Analog").Selected = True' select the MPEG4 video compressorcapturectrl.VideoCompressors.Mpeg4.Selected = True' set an audio device, use the name of your device herecapturectrl.AudioDevices("USB").Selected = True' enable previewcapturectrl.Preview = True' enable CCcapturectrl.ClosedCaptioning = True' set the target output filecapturectrl.TargetFile = outFile' subscribe to the key eventsAddHandler capturectrl.KeyDown, AddressOf KeyDown_HelperAddHandler capturectrl.KeyUp, AddressOf KeyUp_HelperAddHandler capturectrl.KeyPress, AddressOf KeyPress_Helper' capture it now!capturectrl.StartCapture(CaptureMode.AutoFramesAndAudio)Catch e1 As Exception_result = FalseEnd 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 = FalseApplication.DoEvents()Loop' clean up event handlersRemoveHandler capturectrl.KeyDown, AddressOf KeyDown_HelperRemoveHandler capturectrl.KeyUp, AddressOf KeyUp_HelperRemoveHandler capturectrl.KeyPress, AddressOf KeyPress_HelperEnd SubPrivate Sub KeyPress_Helper(ByVal sender As Object, ByVal e As Leadtools.Multimedia.KeyPressEventArgs)Select Case e.keyAsciiCase 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 = TrueEnd Select' set result_result = TrueEnd SubPrivate Sub KeyUp_Helper(ByVal sender As Object, ByVal e As KeyUpEventArgs)' set result_result = TrueEnd SubPublic Sub KeyDown_Helper(ByVal sender As Object, ByVal e As KeyDownEventArgs)' set result_result = TrueEnd SubPublic NotInheritable Class LEAD_VARSPublic Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 20\Media"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
