触发音量按钮拍照 UWP

Trigger volume buttons to take picture UWP

我尝试使用自拍杆,但是由于windows10相机应用程序没有提供用它拍照和录制视频的可能性,我想知道是否可以触发和处理什么时候用户按下 UWP 应用程序

中的音量增大 and/or 减小按钮

有人能做到吗?

I was wondering if there is a possibility to trigger and handle when the user presses the volume up and/or down button inside an UWP app

不行,硬件音量控制需要特殊权限才能开发,如果你是普通开发者是无法访问这些硬件控制的,可以参考Start, Back, Search, Power, and Volume control behavior.

I try to use a selfie stick, but as windows 10 camera app does not provide the possibility to take picture and record video with it.

我不知道为什么自拍杆不支持拍照和录像,有些windows手机没有相机硬件按钮,比如Lumia 640。但是对于Lumia 950这样的设备,有一个相机硬件按钮,可以在 UWP 应用程序中访问相机硬件按钮。从官方Basic camera app sample可以看出,它是这样注册Camera硬件按钮的事件处理程序的:

if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
    HardwareButtons.CameraPressed += HardwareButtons_CameraPressed;
}

使用此API时,您需要在您的项目中引用适用于通用应用平台的Microsoft Mobile Extension SDK。

如果访问相机硬件按钮对您来说还不够,我的建议是您可以通过Windows反馈工具提交请求添加此新功能以进行开发。

有解决办法。当我测试硬件按钮的功能时,它触发了 CoreWindow_KeyDownVirtualKey 为 174(降低音量)和 175(提高)。

//in ctor
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
//

void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
    if ((int)args.VirtualKey == 175 || (int)args.VirtualKey == 174))
    {
     //take a picture
    }
}