LEADTOOLS Multimedia (Leadtools.Multimedia assembly) Send comments on this topic. | Back to Introduction | Help Version 17.0.3.22
KeyUp Event
See Also 
Leadtools.Multimedia Namespace > PlayCtrl Class : KeyUp Event



Occurs when the control has detected a KeyUp event.

Syntax

Visual Basic (Declaration) 
Public Shadows Event KeyUp As KeyUpEventHandler
Visual Basic (Usage)Copy Code
Dim instance As PlayCtrl
Dim handler As KeyUpEventHandler
 
AddHandler instance.KeyUp, handler
C# 
public new event KeyUpEventHandler KeyUp
C++/CLI 
public:
new event KeyUpEventHandler^ KeyUp

Example

Visual BasicCopy Code
Public _result As Boolean = False
      Public _form As PlayCtrlForm = New PlayCtrlForm()
      Public Sub KeyPressesExample()
         Dim playctrl As PlayCtrl = _form.PlayCtrl
         Dim inFile As String = Path.Combine(LEAD_VARS.MediaDir, "PlayCtrl_Source.avi")

         Try
            ' turn off autostart
            playctrl.AutoStart = False

            ' set the source media file
            playctrl.SourceFile = inFile

            ' subscribe to the key events
            AddHandler playctrl.KeyDown, AddressOf KeyDown_Helper
            AddHandler playctrl.KeyUp, AddressOf KeyUp_Helper
            AddHandler playctrl.KeyPress, AddressOf KeyPress_Helper

            ' play it now!
            playctrl.Run()
         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 playctrl.State = PlayState.Running OrElse playctrl.State = PlayState.Paused
            Application.DoEvents()
         Loop

         ' clean up event handlers
         RemoveHandler playctrl.KeyDown, AddressOf KeyDown_Helper
         RemoveHandler playctrl.KeyUp, AddressOf KeyUp_Helper
         RemoveHandler playctrl.KeyPress, AddressOf KeyPress_Helper
      End Sub

      Private Sub KeyPress_Helper(ByVal sender As Object, ByVal e As Leadtools.Multimedia.KeyPressEventArgs)
         ' pause if running
         If e.keyAscii = CShort("p") AndAlso _form.PlayCtrl.State = PlayState.Running Then
            ' pause playback
            _form.PlayCtrl.Pause()

            ' set result
            _result = True
         Else ' run if paused
            If e.keyAscii = CShort("r") AndAlso _form.PlayCtrl.State = PlayState.Paused Then
               ' resume playback
               _form.PlayCtrl.Run()

               ' set result
               _result = True
            Else ' run if paused
               If e.keyAscii = CShort("s") AndAlso (_form.PlayCtrl.State = PlayState.Paused OrElse _form.PlayCtrl.State = PlayState.Running) Then
                  ' resume playback
                  _form.PlayCtrl.Stop()

                  ' set result
                  _result = True
               End If
            End If
         End If
      End Sub

      Private Sub KeyUp_Helper(ByVal sender As Object, ByVal e As KeyUpEventArgs)
         ' do something for key up
      End Sub

      Public Sub KeyDown_Helper(ByVal sender As Object, ByVal e As KeyDownEventArgs)
         ' do something for key down
      End Sub

Public NotInheritable Class LEAD_VARS
   Public Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 17\Media"
End Class
C#Copy Code
public bool _result = false;
      public PlayCtrlForm _form = new PlayCtrlForm();
      public void KeyPressesExample()
      {
         PlayCtrl playctrl = _form.PlayCtrl;
         string inFile =Path.Combine(LEAD_VARS.MediaDir,"PlayCtrl_Source.avi");

         try
         {
            // turn off autostart
            playctrl.AutoStart = false;

            // set the source media file
            playctrl.SourceFile = inFile;

            // subscribe to the key events
            playctrl.KeyDown += KeyDown_Helper;
            playctrl.KeyUp += KeyUp_Helper;
            playctrl.KeyPress += KeyPress_Helper;

            // play it now!
            playctrl.Run();
         }
         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 (playctrl.State == PlayState.Running || playctrl.State == PlayState.Paused)
            Application.DoEvents();

         // clean up event handlers
         playctrl.KeyDown -= KeyDown_Helper;
         playctrl.KeyUp -= KeyUp_Helper;
         playctrl.KeyPress -= KeyPress_Helper;
      }

      void KeyPress_Helper(object sender, Leadtools.Multimedia.KeyPressEventArgs e)
      {
         // pause if running
         if (e.keyAscii == 'p' && _form.PlayCtrl.State == PlayState.Running)
         {
            // pause playback
            _form.PlayCtrl.Pause();

            // set result
            _result = true;
         }
         else // run if paused
            if (e.keyAscii == 'r' && _form.PlayCtrl.State == PlayState.Paused)
            {
               // resume playback
               _form.PlayCtrl.Run();

               // set result
               _result = true;
            }
            else // run if paused
               if (e.keyAscii == 's' && (_form.PlayCtrl.State == PlayState.Paused || _form.PlayCtrl.State == PlayState.Running))
               {
                  // resume playback
                  _form.PlayCtrl.Stop();

                  // set result
                  _result = true;
               }
      }

      void KeyUp_Helper(object sender, KeyUpEventArgs e)
      {
         // do something for key up
      }

      public void KeyDown_Helper(object sender, KeyDownEventArgs e)
      {
         // do something for key down
      }

static class LEAD_VARS
{
   public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 17\Media";
}

Remarks

The event handler is passed a KeyUpEventArgs object containing the related keycode information.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Reference

PlayCtrl Class
PlayCtrl Members