ハードウェアのカメラボタンの押下イベントを拾います。それぞれのイベントにイベントハンドラを指定してください。
// The event is fired when the shutter button receives a half press. CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress; // The event is fired when the shutter button receives a full press. CameraButtons.ShutterKeyPressed += OnButtonFullPress; // The event is fired when the shutter button is released. CameraButtons.ShutterKeyReleased += OnButtonRelease;
シャッターボタンの半押しを検知する
// Provide auto-focus with a half button press using the hardware shutter button. private void OnButtonHalfPress(object sender, EventArgs e) { if (cam != null) { // Focus when a capture is not in progress. try { this.Dispatcher.BeginInvoke(delegate() { txtDebug.Text = "Half Button Press: Auto Focus"; }); cam.Focus(); } catch (Exception focusError) { // Cannot focus when a capture is in progress. this.Dispatcher.BeginInvoke(delegate() { txtDebug.Text = focusError.Message; }); } } }
シャッターボタンが押されたのを検知する
// Capture the image with a full button press using the hardware shutter button. private void OnButtonFullPress(object sender, EventArgs e) { if (cam != null) { cam.CaptureImage(); } }
シャッターボタンが離されたのを検知する
// Cancel the focus if the half button press is released using the hardware shutter button. private void OnButtonRelease(object sender, EventArgs e) { if (cam != null) { cam.CancelFocus(); } }