WRL/C++ 检测同时按下多个鼠标按钮
WRL/C++ Detect multiple mouse buttons pressed simultaneously
我正在用 C++ 编码,目标是 Windows UWP 的 WRL,我需要处理鼠标输入,有时需要同时按下 left/right 个按钮。
我的代码只接收按下第一个鼠标按钮和释放最后一个鼠标按钮的事件。因此,如果我按下右键,然后按下左键,则不会为左键触发 PointerPressed。同样,如果我释放右键然后释放左键,则不会为右键触发 PointerReleased。我订阅了以下活动:
void App::SetWindow(CoreWindow^ window)
{
window->PointerPressed += ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerPressed);
window->PointerReleased += ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerReleased);
}
void App::OnPointerPressed(CoreWindow ^sender, PointerEventArgs ^args)
{
}
void App::OnPointerReleased(CoreWindow ^sender, PointerEventArgs ^args)
{
}
如果我的代码需要在按钮 presses/releases 之间重置某些内容,或者我是否应该订阅其他一些事件,请告诉我。
谢谢
CoreWindow.PointerPressed event is fired for the first mouse button pressing detected in the interaction session, and the event is not fired for the second mouse button pressing before the interaction session ends up. Similarly, the CoreWindow.PointerReleased事件仅在最后一个鼠标按钮被释放时触发,即当您第一个按钮被释放而第二个按钮未被释放时不会触发该事件。
因此,您不能使用 CoreWindow.PointerPressed
和 CoreWindow.PointerReleased
事件来检测同时按下左右按钮。
您可以使用 CoreWindow.PointerMoved 事件来检测同时进行的两个鼠标操作。
例如,
Void App::SetWindow(CoreWindow^ window)
{
window->PointerMoved+=ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerMoved);
}
Void App::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
{
if (args->CurrentPoint->Properties->IsLeftButtonPressed)
{
pressed++; // pressed is an int variable whose initial value is 0, pressed is defind in App.xaml.h
}
if (args->CurrentPoint->Properties->IsRightButtonPressed)
{
released++; // released is an int variable whose initial value is 0, released is defind in App.xaml.h
}
if (pressed&&released)
{
pressed = 0;
released = 0;
//Here we know the right and left button of mouse is pressed
}
}
我正在用 C++ 编码,目标是 Windows UWP 的 WRL,我需要处理鼠标输入,有时需要同时按下 left/right 个按钮。
我的代码只接收按下第一个鼠标按钮和释放最后一个鼠标按钮的事件。因此,如果我按下右键,然后按下左键,则不会为左键触发 PointerPressed。同样,如果我释放右键然后释放左键,则不会为右键触发 PointerReleased。我订阅了以下活动:
void App::SetWindow(CoreWindow^ window)
{
window->PointerPressed += ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerPressed);
window->PointerReleased += ref new TypedEventHandler<CoreWindow ^, PointerEventArgs ^>(this, &App::OnPointerReleased);
}
void App::OnPointerPressed(CoreWindow ^sender, PointerEventArgs ^args)
{
}
void App::OnPointerReleased(CoreWindow ^sender, PointerEventArgs ^args)
{
}
如果我的代码需要在按钮 presses/releases 之间重置某些内容,或者我是否应该订阅其他一些事件,请告诉我。
谢谢
CoreWindow.PointerPressed event is fired for the first mouse button pressing detected in the interaction session, and the event is not fired for the second mouse button pressing before the interaction session ends up. Similarly, the CoreWindow.PointerReleased事件仅在最后一个鼠标按钮被释放时触发,即当您第一个按钮被释放而第二个按钮未被释放时不会触发该事件。
因此,您不能使用 CoreWindow.PointerPressed
和 CoreWindow.PointerReleased
事件来检测同时按下左右按钮。
您可以使用 CoreWindow.PointerMoved 事件来检测同时进行的两个鼠标操作。
例如,
Void App::SetWindow(CoreWindow^ window)
{
window->PointerMoved+=ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerMoved);
}
Void App::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
{
if (args->CurrentPoint->Properties->IsLeftButtonPressed)
{
pressed++; // pressed is an int variable whose initial value is 0, pressed is defind in App.xaml.h
}
if (args->CurrentPoint->Properties->IsRightButtonPressed)
{
released++; // released is an int variable whose initial value is 0, released is defind in App.xaml.h
}
if (pressed&&released)
{
pressed = 0;
released = 0;
//Here we know the right and left button of mouse is pressed
}
}