How a #WPDev can identify whether shutter was pressed Half or Full?


If you are a Windows Phone app developer and building a Camera application, you might want to know whether the user pressed the shutter key half or full. In general pressing the shutter key half sets the focus to an object and pressing it completely captures the view.

 

In this short blog post, we will learn how to subscribe for the shutter key press events and identify whether the user pressed it half or full.

 

The Windows Phone SDK provides a static class named “CameraButtons” available in “Microsoft.Devices” namespace, which provides events to know whether the user triggered the device shutter button. The class available in “Microsoft.Phone.dll” exposes three events named:

    • ShutterKeyHalfPressed – Occurs when the camera shutter key button receives a half press event.
    • ShutterKeyPressed – Occurs when the camera shutter key button receives a full press event.
    • ShutterKeyReleased – Occurs when the camera shutter key button released after the ShutterKeyPressed event occurs.

As these are static events, you don’t need to create any instance of Camera object or CameraButtons object. You can directly register the events of the static class and write your business logic based on your requirement. Here is how you can use these events:

 

CameraButtons.ShutterKeyHalfPressed += (s, e) => UpdateHistory("Shutter Key Half Pressed");
CameraButtons.ShutterKeyPressed += (s, e) => UpdateHistory("Shutter Key Pressed");
CameraButtons.ShutterKeyReleased += (s, e) => UpdateHistory("Shutter Key Released");

 

In our sample demo, the UpdateHistory(…) method prints the Shutter Key press event log in the phone screen. Here is what you might notice (similar) when you press the shutter in half press, full press and/or release the full shutter press:

 

Shutter Key events in Windows Phone Camera

 

I hope this now gives you some basic idea to know the Camera Shutter Button events and based on that you can write your own logic to do various kinds of operations in your application. As I said above, generally when a user presses half shutter key, the camera view finder focuses the camera to a specific point. When the user presses full shutter key, it executes a command to capture the view and/or starts the video capture.

 

Don’t forget to read another blog post on Windows Phone Camera APIs (“How to check the supported Camera Type in Windows Phone?”). Subscribe to my blog to get updates on latest articles. I am available on Twitter and Facebook too. Connect with me and say a “Hi”. Happy Coding!!!

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top