⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kbdist.cpp

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 CPP
📖 第 1 页 / 共 2 页
字号:
we power on, we could (and probably will) come back from the wait with a
wait timeout status.  In this case, we do nothing and come back around to
wait again with the proper timeout.  */

        if ( v_AutoRepeatState == AR_WAIT_FOR_ANY )
            ;   //  do nothing
        else if ( v_AutoRepeatState == AR_INITIAL_DELAY )
        {
            fSendAutoRepeatKey = TRUE;
            v_AutoRepeatState = AR_AUTOREPEATING;
        }
        else if ( v_AutoRepeatState == AR_AUTO_PARTIAL )
        {
            fSendAutoRepeatKey = TRUE;
            v_AutoRepeatState = AR_AUTOREPEATING;
        }
        else
        {
            fSendAutoRepeatKey = TRUE;
        }
    }
    else
    {
        //  We got a keyboard interrupt but there may or may not be key events.
        cKeyEvents = KeybdPdd_GetEventEx(VKeyBuf, ScanCodeBuf, KeyStateFlagsBuf);
        if ( cKeyEvents )
        {
            for ( iKeyEventIdx = 0; iKeyEventIdx < cKeyEvents; iKeyEventIdx++ )
            {
                if ( KeyStateIsDown(KeyStateFlagsBuf[iKeyEventIdx]) )
                {
                    MRKeyTimeForPolling = GetTickCount();
                    v_AutoRepeatState = AR_INITIAL_DELAY;
                    v_AutoRepeatVKey = VKeyBuf[iKeyEventIdx];
                    v_AutoRepeatScanCode = ScanCodeBuf[iKeyEventIdx];
                    v_AutoRepeatKeyStateFlags = KeyStateFlagsBuf[iKeyEventIdx];

                    cRemapEvents = KeybdDriverRemapVKeyDownEx(
                            VKeyBuf[iKeyEventIdx],
                            ScanCodeBuf[iKeyEventIdx],
                            KeyStateFlagsBuf[iKeyEventIdx],
                            RemapVKeyBuf,
                            RemapScanCodeBuf,
                            RemapKeyStateFlagsBuf
                            );

                    for ( iRemapIdx = 0; iRemapIdx < cRemapEvents; iRemapIdx++ )
                    {
///                     RETAILMSG(1,
///                         (TEXT("D0 %d %x %x\r\n"),
//                              iRemapIdx, RemapVKeyBuf[iRemapIdx], RemapKeyStateFlagsBuf[iRemapIdx]));
                        if ( v_pfnKeybdEventCallbackEx )
                        {
                            (*v_pfnKeybdEventCallbackEx)(
                                RemapVKeyBuf[iRemapIdx],
                                RemapScanCodeBuf[iRemapIdx],
                                RemapKeyStateFlagsBuf[iRemapIdx]);
                        }
                    }
                }
                else
                {
                    v_AutoRepeatState = AR_WAIT_FOR_ANY;
                    cRemapEvents = KeybdDriverRemapVKeyUpEx(
                            VKeyBuf[iKeyEventIdx],
                            ScanCodeBuf[iKeyEventIdx],
                            KeyStateFlagsBuf[iKeyEventIdx],
                            RemapVKeyBuf,
                            RemapScanCodeBuf,
                            RemapKeyStateFlagsBuf
                            );

                    for ( iRemapIdx = 0; iRemapIdx < cRemapEvents; iRemapIdx++ )
                    {
//                  RETAILMSG(1, (TEXT("U %d %x %x\r\n"), iRemapIdx, RemapVKeyBuf[iRemapIdx], RemapKeyStateFlagsBuf[iRemapIdx]));
                        if ( v_pfnKeybdEventCallbackEx )
                        {
                            (*v_pfnKeybdEventCallbackEx)(
                                RemapVKeyBuf[iRemapIdx],
                                RemapScanCodeBuf[iRemapIdx],
                                RemapKeyStateFlagsBuf[iRemapIdx]);
                        }
                    }
                }
            }
        }
        else
        {
            //  We did not get a timeout from the wait or key events.  We must be periodically polling.
            //  This means that we will need to do the timing here.
            if ( ( v_AutoRepeatState == AR_INITIAL_DELAY ) ||
                 ( v_AutoRepeatState == AR_AUTO_PARTIAL ) ||
                 ( v_AutoRepeatState == AR_AUTOREPEATING ) )
            {
                    v_AutoRepeatState = AR_AUTO_PARTIAL;
            }
        }
        InterruptDone(dwSysIntrPs2Ch1);

    }

    if ( fSendAutoRepeatKey )
    {
        cRemapEvents = KeybdDriverRemapVKeyDownEx(
                            v_AutoRepeatVKey,
                            v_AutoRepeatScanCode,
                            v_AutoRepeatKeyStateFlags,
                            RemapVKeyBuf,
                            RemapScanCodeBuf,
                            RemapKeyStateFlagsBuf
                            );

        for ( iRemapIdx = 0; iRemapIdx < cRemapEvents; iRemapIdx++ )
        {
///         RETAILMSG(1,
///             (TEXT("D1 %d %x %x\r\n"),
///                 iRemapIdx, RemapVKeyBuf[iRemapIdx], RemapKeyStateFlagsBuf[iRemapIdx]));
            if ( v_pfnKeybdEventCallbackEx )
            {
                (*v_pfnKeybdEventCallbackEx)(
                    RemapVKeyBuf[iRemapIdx],
                    RemapScanCodeBuf[iRemapIdx],
                    RemapKeyStateFlagsBuf[iRemapIdx]);
            }
        }
    }

    goto wait_for_keybd_interrupt;

    ERRORMSG(1, (TEXT("Keyboard driver thread terminating.\r\n")));
    return 0;
}




/*++

KeybdDriverThread:

Keyboard driver Suspend interrupt service thread.


Return Value:

Never returns.

--*/
BOOL
KeybdIstSuspendLoop(
    HANDLE  hevSuspend
    )
{
    UINT32          VKeyBuf[16];            //  hardcoded w/ PDD.
    UINT32          ScanCodeBuf[16];        //  hardcoded w/ PDD.
    KEY_STATE_FLAGS KeyStateFlagsBuf[16];   //  hardcoded w/ PDD.

    UINT32          RemapVKeyBuf[16];
    UINT32          RemapScanCodeBuf[16];
    KEY_STATE_FLAGS RemapKeyStateFlagsBuf[16];

    int             cKeyEvents;
    int             iKeyEventIdx;

    int             cRemapEvents;
    int             iRemapIdx;

    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);


wait_for_suspend_interrupt:

    if ( WaitForSingleObject(hevSuspend, INFINITE) == WAIT_TIMEOUT )
    {
        ERRORMSG(1, (TEXT("hevSuspend timeout error.\r\n")));
    }
    else
    {
        //  We got a keyboard interrupt but there may or may not be key events.
        cKeyEvents = KeybdPdd_GetEventEx(VKeyBuf, ScanCodeBuf, KeyStateFlagsBuf);
        if ( cKeyEvents )
        {
            for ( iKeyEventIdx = 0; iKeyEventIdx < cKeyEvents; iKeyEventIdx++ )
            {
                if ( KeyStateIsDown(KeyStateFlagsBuf[iKeyEventIdx]) )
                {
                    cRemapEvents = KeybdDriverRemapVKeyDownEx(
                            VKeyBuf[iKeyEventIdx],
                            ScanCodeBuf[iKeyEventIdx],
                            KeyStateFlagsBuf[iKeyEventIdx],
                            RemapVKeyBuf,
                            RemapScanCodeBuf,
                            RemapKeyStateFlagsBuf
                            );

                    for ( iRemapIdx = 0; iRemapIdx < cRemapEvents; iRemapIdx++ )
                    {
//                      RETAILMSG(1,
//                          (TEXT("D0 %d %x %x\r\n"),
//                              iRemapIdx, RemapVKeyBuf[iRemapIdx], RemapKeyStateFlagsBuf[iRemapIdx]));
                        if ( v_pfnKeybdEventCallbackEx )
                        {
                            (*v_pfnKeybdEventCallbackEx)(
                                RemapVKeyBuf[iRemapIdx],
                                RemapScanCodeBuf[iRemapIdx],
                                RemapKeyStateFlagsBuf[iRemapIdx]);
                        }
                    }
                }
                else
                {
                    v_AutoRepeatState = AR_WAIT_FOR_ANY;
                    cRemapEvents = KeybdDriverRemapVKeyUpEx(
                            VKeyBuf[iKeyEventIdx],
                            ScanCodeBuf[iKeyEventIdx],
                            KeyStateFlagsBuf[iKeyEventIdx],
                            RemapVKeyBuf,
                            RemapScanCodeBuf,
                            RemapKeyStateFlagsBuf
                            );

                    for ( iRemapIdx = 0; iRemapIdx < cRemapEvents; iRemapIdx++ )
                    {
//                  RETAILMSG(1, (TEXT("U %d %x %x\r\n"), iRemapIdx, RemapVKeyBuf[iRemapIdx], RemapKeyStateFlagsBuf[iRemapIdx]));
                        if ( v_pfnKeybdEventCallbackEx )
                        {
                            (*v_pfnKeybdEventCallbackEx)(
                                RemapVKeyBuf[iRemapIdx],
                                RemapScanCodeBuf[iRemapIdx],
                                RemapKeyStateFlagsBuf[iRemapIdx]);
                        }
                    }
                }
            }
        }
        InterruptDone(dwSysIntrKeyboard);

    }

    goto wait_for_suspend_interrupt;

    return 0;
}




extern "C"
/*++

@doc EXTERNAL DRIVERS

@func

System power state change notification.

@comm This routine is called in a kernel context and may not make any
system calls whatsoever.  It may read and write its own memory and that's
about it.

@comm Resets the auto-repeat state and calls the <f KeybdPdd_PowerHandler> routine.

--*/
void KeybdDriverPowerHandler(
    BOOL    bOff    // @parm TRUE, the system is powering off; FALSE, the system is powering up.
    )
{
    v_AutoRepeatState = AR_WAIT_FOR_ANY;
    KeybdPdd_PowerHandler(bOff);
    return;
}

#ifdef DEBUG
PFN_KEYBD_DRIVER_POWER_HANDLER v_pfnPowerHandler = KeybdDriverPowerHandler;
#endif



extern "C"
//  @doc EXTERNAL DRIVERS
/*  @func Do one time only keyboard driver initialization.

@rdesc If the function succeeds the return value is TRUE, otherwise, it is
FALSE.  Extended error information is available via the GetLastError
function.

@comm Calls <f KeybdPdd_InitializeDriver> then starts driver interrupt
service thread.

--*/
void KeybdDriverInitializeEx(
    PFN_KEYBD_EVENT_CALLBACK_EX pfnKeybdEventCallbackEx // @parm The callback into the input system.
    )
{
    v_pfnKeybdEventCallbackEx = pfnKeybdEventCallbackEx;

    KeybdPdd_InitializeDriverEx(pfnKeybdEventCallbackEx);

    (*pfnKeybdEventCallbackEx)(KEYBD_DEVICE_CONNECT, 0, 0);

    return;
}
#ifdef DEBUG
PFN_KEYBD_DRIVER_INITIALIZE_EX v_pfnDriverInitializeTestEx = KeybdDriverInitializeEx;
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -