0

目前,我正在创建自己的函数 onPress 和 onRelease。但是,我的 onRelease 函数有问题。显然,即使我没有释放键盘,我的 onRelease 也会继续触发。

我怀疑这与 CPU 内部的周期数有关,但我不确定这个理论。不知何故,也许循环比我的帧慢,那为什么 PeerMessage 返回 false?因为没有触发任何事件。

解决方案: **在 WinProc 函数下创建一个名为 WM_KEYUP 的新案例。一旦用户离开按钮,此事件将触发。它有助于解决CPU内部发出的周期数。**

*注意:我已经更新了我的代码细节。

描述。窗口编程我有两个存储我的键盘数据的 std::array 1) InputCurr 2) InputPrev

std::array<char, 256> inputPrev;
std::array<char, 256> inputCurr;

While(TRUE) {
    std::copy(InputCurr.begin(), InputCurr.end(), InputPrev.begin());
    inputCurr.fill(0);

    while(PeekMessage (&uMsg, NULL, 0, 0, PM_REMOVE))
    {
        TranslateMessage (&uMsg);
        DispatchMessage (&uMsg);
    }

    if(onReleased(x030))  //Button 0
    //do something
}

char onReleased(char key)
{
    return (inputCurr[key] && !inputPrev[key])? 1 : 0;
}

void VEInputMessage(WPARAM key)
{
    inputCurr[key]= 1;  //Set to true of the keyboard key
}

LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{
    HDC dc;           /* device context */
    PAINTSTRUCT ps;   /* the paint struct */
    RECT rect;

    UNREFERENCED_PARAMETER(rect);

    switch (msg)
    {
    /* when the window is created */
    case WM_CREATE:
        break;

    /* when the rectangle is drawn */
    case WM_LBUTTONDOWN:
            break;

    case WM_MOUSEMOVE:
        break;

    case WM_PAINT:
        dc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
        break;

    /* When it's time for the window to be closed and removed */
    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    case WM_KEYDOWN:
        VEINPUT::VEInputMessage(wParam);  //Updated the input key 
        if(wParam == AEVK_ESCAPE)
            PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0;
}
4

0 回答 0