LEADTOOLS Multimedia (Leadtools.Multimedia assembly)
LEAD Technologies, Inc

KeyUp Event (PlayCtrl)

Example 





Occurs when the control has detected a KeyUp event.
Syntax
public new event KeyUpEventHandler KeyUp
'Declaration
 
Public Shadows Event KeyUp As KeyUpEventHandler
'Usage
 
Dim instance As PlayCtrl
Dim handler As KeyUpEventHandler
 
AddHandler instance.KeyUp, handler
public new event KeyUpEventHandler KeyUp
add_KeyUp(function(sender, e))
remove_KeyUp(function(sender, e))

public:
new event KeyUpEventHandler^ KeyUp
Remarks
The event handler is passed a KeyUpEventArgs object containing the related keycode information.
Example
Copy CodeCopy 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 175\Media";
End Class
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 175\Media";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PlayCtrl Class
PlayCtrl Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Multimedia requires a Multimedia or Multimedia Suite license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features