[WP7] Quick Tip – How to know when user press the buttons of the camera ?

November 8th, 2011 | Posted by Tom in .NET | Windows Phone | Read: 3,004

In Windows Phone 7.1, there are 3 new events that can be used by developers to know when users press the buttons of the camera:

  1. CameraButtons.ShutterKeyHalfPressed
  2. CameraButtons.ShutterKeyPressed
  3. CameraButtons.ShutterKeyReleased

Using this events is really simple, as you can see in the following code:

private PhotoCamera _camera;

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;
    CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;
    CameraButtons.ShutterKeyReleased += CameraButtons_ShutterKeyReleased;
}

private void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)
{
    if (_camera != null)
    {
        _camera.Focus();
    }
}

private void CameraButtons_ShutterKeyPressed(object sender, EventArgs e)
{
    if (_camera != null)
    {
        _camera.CaptureImage();
    }
}

private void CameraButtons_ShutterKeyReleased(object sender, EventArgs e)
{
    if (_camera != null)
    {
        _camera.CancelFocus();
    }
}

Simple but very useful !

 

Happy coding!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

One Response

Add Comment Register



Leave a Reply