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

📄 vkchengus101.cpp

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* 98 */                0,
/* 99 */                0,
/* 9A */                0,
/* 9B */                0,
/* 9C */                0,
/* 9D */                0,
/* 9E */                0,
/* 9F */                0,


/* A0 VK_LSHIFT     */  0,
/* A1 VK_RSHIFT     */  0,
/* A2 VK_LCONTROL   */  0,
/* A3 VK_RCONTROL   */  0,
/* A4 VK_LMENU      */  0,
/* A5 VK_RMENU      */  0,
/* A6 */                0,
/* A7 */                0,
/* A8 */                0,
/* A9 */                0,
/* AA */                0,
/* AB */                0,
/* AC */                0,
/* AD */                0,
/* AE */                0,
/* AF */                0,

/* B0 */                0,
/* B1 */                0,
/* B2 */                0,
/* B3 */                0,
/* B4 */                0,
/* B5 */                0,
/* B6 */                0,
/* B7 */                0,
/* B8 */                0,
/* B9 */                0,
/* BA VK_SEMICOLON  */  TEXT(':'),
/* BB VK_EQUAL      */  TEXT('+'),
/* BC VK_COMMA      */  TEXT('<'),
/* BD VK_HYPHEN     */  TEXT('_'),
/* BE VK_PERIOD     */  TEXT('>'),
/* BF VK_SLASH      */  TEXT('?'),


/* C0 VK_BACKQUOTE  */  TEXT('~'),
/* C1 */                0,
/* C2 */                0,
/* C3 */                0,
/* C4 */                0,
/* C5 */                0,
/* C6 */                0,
/* C7 */                0,
/* C8 */                0,
/* C9 */                0,
/* CA */                0,
/* CB */                0,
/* CC */                0,
/* CD */                0,
/* CE */                0,
/* CF */                0,


/* D0 */                0,
/* D1 */                0,
/* D2 */                0,
/* D3 */                0,
/* D4 */                0,
/* D5 */                0,
/* D6 */                0,
/* D7 */                0,
/* D8 */                0,
/* D9 */                0,
/* DA */                0,
/* DB VK_LBRACKET   */  TEXT('{'),
/* DC VK_BACKSLASH  */  TEXT('|'),
/* DD VK_RBRACKET   */  TEXT('}'),
/* DE VK_APOSTROPHE */  TEXT('"'),
/* DF VK_OFF        */  0,


/* E0 */                0,
/* E1 */                0,
/* E2 */                0,
/* E3 */                0,
/* E4 */                0,
/* E5 */                0,
/* E6 */                0,
/* E7 */                0,
/* E8 */                0,
/* E9 */                0,
/* EA */                0,
/* EB */                0,
/* EC */                0,
/* ED */                0,
/* EE */                0,
/* EF */                0,


/* F0 */                0,
/* F1 */                0,
/* F2 */                0,
/* F3 */                0,
/* F4 */                0,
/* F5 */                0,
/* F6 */                0,
/* F7 */                0,
/* F8 */                0,
/* F9 */                0,
/* FA */                0,
/* FB */                0,
/* FC */                0,
/* FD */                0,
/* FE */                0,
/* FF */                0


};




//  For all of the lookup tables, we could make them smaller
//  by using ranges but it is better to wait for a little while
//  and make sure that all of the characters are correct first.

static
UINT16
VKeyToUnicodeBase(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey < COUNT_VKEYS )
        {
        chRet = Column_Base[VKey];
        }

    return chRet;
}


static
UINT16
VKeyToUnicodeShift(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey < COUNT_VKEYS )
        {
        chRet = Column_Shift[VKey];
        }

    return chRet;
}



static
UINT16
VKeyToUnicodeControl(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey < COUNT_VKEYS )
        {
        chRet = Column_Control[VKey];
        }

    return chRet;
}


static
UINT16
VKeyToUnicodeCapsLock(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey < COUNT_VKEYS )
        {
        chRet = Column_CapsLock[VKey];
        }

    return chRet;
}



static
UINT16
VKeyToUnicodeShiftCapsLock(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey < COUNT_VKEYS )
        {
        chRet = Column_ShiftCapsLock[VKey];
        }

    return chRet;
}



static
UINT16
VKeyToUnicodeControlCapsLock(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey == VK_RETURN )
        {
        chRet = 0x0a;
        }
    else if ( VKey == VK_BACK )
        {
        chRet = 0x07f;
        }

    return chRet;
}



static
UINT16
VKeyToUnicodeControlShift(
    UINT32  VKey
    )
{
    UINT16  chRet = 0;

    if ( VKey == VK_6 )     //  On U.S. keyboard, shift+6 => ^ and ctrl+^ => 0x1e
        {
        chRet = 0x1e;
        }

    return chRet;
}







static
unsigned int
DetermineLookupColumn(
    KEY_STATE_FLAGS KeyStateFlags
    )
{
    unsigned int    uiColumn = 0;

    if ( KeyStateFlags & KeyShiftAnyShiftFlag )
        {
        uiColumn |= SHIFT_FLAG;
        }

    if ( KeyStateFlags & KeyShiftAnyCtrlFlag )
        {
        uiColumn |= CONTROL_FLAG;
        }

    if ( KeyStateFlags & KeyShiftCapitalFlag )
        {
        uiColumn |= CAPS_FLAG;
        }

    return uiColumn;
}



/*++

VKeyToUnicode:

Return Value:

Errors:

Notes:

--*/
int
VKeyToUnicode(
    UINT32          VirtualKey, //  Virtual Key causing the event.
    KEY_STATE_FLAGS ShiftFlags  //  State of Shift, control, caps and alt keys.
            )
{
    unsigned int    NewColumn;
    UINT16          ch = 0;

    //RETAILMSG(1,(TEXT("VKey: %x\r\n"), VirtualKey));

    NewColumn = DetermineLookupColumn(ShiftFlags);

    switch ( NewColumn )
        {
        case BASE_FLAG:
            ch = VKeyToUnicodeBase(VirtualKey);
            break;

        case CAPS_FLAG:
            ch = VKeyToUnicodeCapsLock(VirtualKey);
            break;

        case SHIFT_FLAG:
            ch = VKeyToUnicodeShift(VirtualKey);
            break;

        case SHIFT_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeShiftCapsLock(VirtualKey);
            break;


        //  Ignore Alt
        case ALT_FLAG:
            ch = VKeyToUnicodeBase(VirtualKey);
            break;

        //  Ignore Alt
        case ALT_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeCapsLock(VirtualKey);
            break;

        //  Ignore Alt
        case ALT_FLAG | SHIFT_FLAG:
            ch = VKeyToUnicodeShift(VirtualKey);
            break;

        //  Ignore Alt
        case ALT_FLAG | SHIFT_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeShiftCapsLock(VirtualKey);
            break;




        case CONTROL_FLAG:
            ch = VKeyToUnicodeControl(VirtualKey);
            break;

        //  Ignore Caps when Control
        case CONTROL_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeControl(VirtualKey);
            break;

        case CONTROL_FLAG | SHIFT_FLAG:
            ch = VKeyToUnicodeControlShift(VirtualKey);
            break;

        //  Ignore Caps when Control
        case CONTROL_FLAG | SHIFT_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeControlShift(VirtualKey);
            break;


        //  Ignore Alt
        case CONTROL_FLAG | ALT_FLAG:
            ch = VKeyToUnicodeControl(VirtualKey);
            break;

        //  Ignore Alt
        //  Ignore Caps when Control
        case CONTROL_FLAG | ALT_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeControl(VirtualKey);
            break;

        //  Ignore Alt
        case CONTROL_FLAG | ALT_FLAG | SHIFT_FLAG:
            ch = VKeyToUnicodeControlShift(VirtualKey);
            break;

        //  Ignore Alt
        //  Ignore Caps when Control
        case CONTROL_FLAG | ALT_FLAG | SHIFT_FLAG | CAPS_FLAG:
            ch = VKeyToUnicodeControlShift(VirtualKey);
            break;

        }

    return ch;
}













UINT32
KeybdDriverVKeyToUnicode(
    UINT32          VirtualKey,
    KEY_STATE_FLAGS KeyEvent,
    KEY_STATE       KeyState,
    void            *pKeybdDriverToUnicodeState,
    UINT32          cBufferSize,
    UINT32          *pcCharacters,
    KEY_STATE_FLAGS *pShiftStateBuffer,
    UINT32          *pCharacterBuffer)
{
    KEY_STATE_FLAGS ShiftFlags;
    UINT32          VKeyCommon;

    VirtualKey &= 0xff;

    //  Do special case for MapVirtualKey here.
    if ( KeyState == NULL )
        {
        if ( pCharacterBuffer )
            *pCharacterBuffer = towlower(VirtualKey);
        return ERROR_SUCCESS;
        }

    //  We have ToUnicodeState for demo, so check for it.
    if ( pKeybdDriverToUnicodeState == NULL )
        {
        SetLastError(ERROR_INVALID_PARAMETER);
        return ERROR_INVALID_PARAMETER;
        }

    if ( ( cBufferSize != MAX_TO_UNICODE_CHARACTERS ) ||
         ( pShiftStateBuffer == NULL ) ||
         ( pCharacterBuffer == NULL ) )
        {
        SetLastError(ERROR_INVALID_PARAMETER);
        return ERROR_INVALID_PARAMETER;
        }

    // Update the virtual key state.
    KeyState[VirtualKey] = NewKeyStateFlags(KeyState[VirtualKey], KeyEvent);

    // Now check the duplicate keys.
    VKeyCommon = MapLRVKeyToCommonVKey(VirtualKey);
    if ( VKeyCommon != VirtualKey )
        {
        KeyState[VKeyCommon] = NewKeyStateFlags(KeyState[VKeyCommon], KeyEvent);
        VirtualKey = VKeyCommon;
        }

    // Figure out the new shift state flags.
    KeybdDriverKeyStateToShiftFlags(KeyState, VirtualKey, &ShiftFlags);

    if ( ( VirtualKey == VK_CAPITAL ) ||
         ( VirtualKey == VK_NUMLOCK ) ||
         ( VirtualKey == 0 ))
        {
        KeybdPdd_ToggleKeyNotification(ShiftFlags);
        }

    // Always return the shift state which counts for one entry.
    *pcCharacters = 1;

    //  Note that ShiftFlags holds the current state of the keyboard when it is
    //  passed to the next routines.  They will look at the current state and
    //  possibly update it depending on whether or not they generate a character.
    if ( AltNumKeyEvent(
            VirtualKey,
            KeyEvent,
            (TO_UNICODE_STATE*)pKeybdDriverToUnicodeState,
            &ShiftFlags,
            pCharacterBuffer) )
        {
        //  If part of Alt+Num sequence, no more to do.
        }
    else if ( KeyEvent & KeyStateDownFlag )
        {
        *pCharacterBuffer = VKeyToUnicode(VirtualKey, ShiftFlags);
        if ( !*pCharacterBuffer )
            {
            ShiftFlags |= KeyShiftNoCharacterFlag;
            }
        }
    else
        {
        ShiftFlags |= KeyShiftNoCharacterFlag;
        }

    *pShiftStateBuffer = ShiftFlags;

    return ERROR_SUCCESS;
}


#ifdef DEBUG
PFN_KEYBD_DRIVER_VKEY_TO_UNICODE v_pfnVKeyToUnicodeTest = KeybdDriverVKeyToUnicode;
#endif



BOOL
KeybdDriverInitStates(
    INT         iKeybdId,
    KEY_STATE   KeyState,
    void        *pKeybdDeviceToUnicodeState
    )
{
    TO_UNICODE_STATE    *pDemoState = (TO_UNICODE_STATE*)pKeybdDeviceToUnicodeState;
    int i;

    //  We have some demo state, so check for it.  If we had no state,
    //  this parameter could be NULL with no error.
    if ( pDemoState == NULL )
        {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
        }

    for ( i = 0; i < COUNT_VKEYS; i++ )
        {
        KeyState[i] = 0;
        }

    return TRUE;
}

#ifdef DEBUG
PFN_KEYBD_DRIVER_INIT_STATES v_pfnInitStatesTest = KeybdDriverInitStates;
#endif



UINT32
KeybdDriverMapVirtualKey(
    UINT32  uCode,
    UINT32  uMapType
    )
{
    UINT32  uRet = 0;

    UINT32          VKeyBuf[16];
    UINT32          ScanCodeBuf[16];
    KEY_STATE_FLAGS KeyStateFlagsBuf[16];


    switch ( uMapType )
        {
        case 0:

            uCode = MapCommonVKeyToLVKey(uCode);
            uRet = VKeyToScanCode(uCode);
            uRet &= 0xff;
            break;

        case 1:
            ScanCodeToVKeyEx(uCode, 0, VKeyBuf, ScanCodeBuf, KeyStateFlagsBuf);
            uRet = MapLRVKeyToCommonVKey(VKeyBuf[0]);
            break;

        case 2:
            KeybdDriverVKeyToUnicode(uCode, 0, NULL, NULL, 0, NULL, NULL, &uRet);
            break;

        case 3:
            uRet = VKeyToScanCode(uCode);
            uRet &= 0xff;
            break;

        default:
            SetLastError(ERROR_INVALID_PARAMETER);
            break;
        }

    return uRet;
}

#ifdef DEBUG
PFN_KEYBD_DRIVER_MAP_VIRTUAL_KEY v_pfnMapVirtualKeyTest = KeybdDriverMapVirtualKey;
#endif




⌨️ 快捷键说明

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