C++ 在windows 8应用商店应用程序中,使用窗口->按键事件设置多个按键。C

C++ 在windows 8应用商店应用程序中,使用窗口->按键事件设置多个按键。C,c++,windows,events,key,C++,Windows,Events,Key,我一直在尝试设置一个事件,检查windows 8应用商店应用程序中按下的多个键,但运气不佳 下面是我的一次尝试,但没有取得成果 //When key is pressed down void KeyDown(CoreWindow^ Window, KeyEventArgs^ Args) { //if both up and left are pressed if ((Args->VirtualKey == VirtualKey::Up) && (Args-

我一直在尝试设置一个事件,检查windows 8应用商店应用程序中按下的多个键,但运气不佳

下面是我的一次尝试,但没有取得成果

//When key is pressed down
void KeyDown(CoreWindow^ Window, KeyEventArgs^ Args)
{ 
    //if both up and left are pressed
    if ((Args->VirtualKey == VirtualKey::Up) && (Args->VirtualKey == VirtualKey::Left)) {
        MessageDialog Dialog("Up and left pressed!", "It's working!");
        Dialog.ShowAsync();
    }

目前,如果我按下两个按钮,它只会记录我第二次按下的那个按钮。如有任何帮助,将不胜感激=我所看到的多次按键的方法适用于较旧的操作系统。

已解决:在cplusplus.com论坛的帮助下,用户“NTR”

他的解决办法是:

由于缺少windows 8,我还没有尝试过制作windows 8应用商店应用程序,但这个概念应该与旧版本相当相似

您是否尝试过在按键时存储一组布尔值,然后测试keypress和keyrelease对象以关闭和打开值

e、 g.根据您的代码:

bool keyDownArray[256] = {false};  // keys array
// OR, if the keys aren't stored as numerical values anymore...
bool leftKey = false;
bool upKey = false;
// ...


Window->KeyDown += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>
    (this, &App::KeyDown);
Window->KeyUp += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>
    (this, &App::KeyUp);

void KeyDown(CoreWindow^ Window, KeyEventArgs^ Args) {
    // either
    keyDownArray[Args->VirtualKey] = true;
    // or
    if (Args->VirtualKey == VirtualKey::Up)
        upKey = true;
    if (Args->VirtualKey == VirtualKey::Left)
        leftKey = true;
}

void KeyUp(CoreWindow^ Window, KeyEventArgs^ Args) {
    // either
    keyDownArray[Args->VirtualKey] = false;
    // or
    if (Args->VirtualKey == VirtualKey::Up)
        upKey = false;
    if (Args->VirtualKey == VirtualKey::Left)
        leftKey = false;
}

// ....

if (keyDownArray[VirtualKey::Up] && keyDownArray[VirtualKey::Left]) {
    MessageDialog Dialog("Up and left pressed!", "It's working!");
    Dialog.ShowAsync();
}

// OR

if (keyLeft && keyUp) {
    MessageDialog Dialog("Up and left pressed!", "It's working!");
    Dialog.ShowAsync()
}
正如我所说,我以前没有做过任何Windows8商店应用程序,所以这可能是完全错误的,但希望它能为您提供一个可以实现的可能解决方案的想法

全归功于他