📄 vkchengus1.cpp
字号:
/* 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];
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeBase: %08x VKey %08x\r\n"), chRet,VKey));
return chRet;
}
static
UINT16
VKeyToUnicodeShift(
UINT32 VKey
)
{
UINT16 chRet = 0;
if ( VKey < COUNT_VKEYS )
{
chRet = Column_Shift[VKey];
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeShift: %08x\r\n"), chRet));
return chRet;
}
static
UINT16
VKeyToUnicodeControl(
UINT32 VKey
)
{
UINT16 chRet = 0;
if ( VKey < COUNT_VKEYS )
{
chRet = Column_Control[VKey];
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeControl: %08x\r\n"), chRet));
return chRet;
}
static
UINT16
VKeyToUnicodeCapsLock(
UINT32 VKey
)
{
UINT16 chRet = 0;
if ( VKey < COUNT_VKEYS )
{
chRet = Column_CapsLock[VKey];
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeCapsLock: %08x\r\n"), chRet));
return chRet;
}
static
UINT16
VKeyToUnicodeShiftCapsLock(
UINT32 VKey
)
{
UINT16 chRet = 0;
if ( VKey < COUNT_VKEYS )
{
chRet = Column_ShiftCapsLock[VKey];
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeShiftCapsLock: %08x\r\n"), chRet));
return chRet;
}
static
UINT16
VKeyToUnicodeControlCapsLock(
UINT32 VKey
)
{
UINT16 chRet = 0;
if ( VKey == VK_RETURN )
{
chRet = 0x0a;
}
else if ( VKey == VK_BACK )
{
chRet = 0x07f;
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeControlCapsLock: %08x\r\n"), chRet));
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;
}
// RETAILMSG(1,(TEXT("VKeyToUnicodeControlShift: %08x\r\n"), chRet));
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;
}
// RETAILMSG(1,(TEXT("DetermineLookupColumn: %08x\r\n"), uiColumn));
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;
NewColumn = DetermineLookupColumn(ShiftFlags);
// RETAILMSG(1,(TEXT("VKeyToUnicode: %08x VirtualKey %08x\r\n"), NewColumn,VirtualKey));
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);
// RETAILMSG(1,(TEXT("KeybdDriverVKeyToUnicode: %08x\r\n"), VKeyCommon));
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 ))
{
KeypdPdd_ToggleKeyNotification(ShiftFlags);
}
// Always return the shift state which counts for one entry.
*pcCharacters = 1;
// setting up the @ and > symbol for the fasttap keypad
switch(VirtualKey)
{
case VK_NUMPAD1: // key !
VirtualKey = 0x31; // this represents key '1'
if (ShiftFlags & (1<<27))
VirtualKey = VK_BACKQUOTE;
ShiftFlags=KeyShiftAnyShiftFlag;
break;
case VK_NUMPAD2: // key @
VirtualKey = 0x32; // this represents key '2'
if (ShiftFlags & (1<<27))
VirtualKey = VK_COMMA;
ShiftFlags=KeyShiftAnyShiftFlag;
break;
case VK_NUMPAD3: // key ?
VirtualKey = VK_SLASH; // this represents key '2'
if (ShiftFlags & (1<<27))
VirtualKey = VK_BACKSLASH;
ShiftFlags=KeyShiftAnyShiftFlag;
break;
case VK_NUMPAD4: // key $
VirtualKey = 0x34; // this represents key '4'
if (ShiftFlags & (1<<27))
VirtualKey = 0x36; // this represents key '6'
ShiftFlags=KeyShiftAnyShiftFlag;
break;
case VK_NUMPAD6: // key # for PPC
VirtualKey = 0x33; // this represents key '3'
ShiftFlags=KeyShiftAnyShiftFlag;
break;
case VK_NUMPAD7: // key &
VirtualKey = 0x37; // this represents key '7'
if (ShiftFlags & (1<<27))
VirtualKey = VK_HYPHEN;
ShiftFlags=KeyShiftAnyShiftFlag;
break;
case VK_ADD: // key :
if (!(ShiftFlags & (1<<27)))
{
VirtualKey = VK_SEMICOLON;
ShiftFlags=KeyShiftAnyShiftFlag;
}
break;
case VK_SEMICOLON: // key ;
if (ShiftFlags & (1<<27))
{
VirtualKey = VK_SUBTRACT;
ShiftFlags=0;
}
break;
case VK_COMMA: //key ,
if (ShiftFlags & (1<<27))
{
VirtualKey = 0x35; // this represents key '5'
ShiftFlags=KeyShiftAnyShiftFlag;
}
break;
case VK_NEXT: // key tab
case VK_TAB: // key tab
if (ShiftFlags & (1<<27))
{
VirtualKey = VK_EQUAL;
ShiftFlags=0;
}
break;
case VK_LBRACKET: // key (
if (!(ShiftFlags & (1<<27)))
{
VirtualKey = 0x39; // this represents key '9'
ShiftFlags=KeyShiftAnyShiftFlag;
}
break;
case VK_RBRACKET: // key )
if (!(ShiftFlags & (1<<27)))
{
VirtualKey = 0x30; // this represents key '0'
ShiftFlags=KeyShiftAnyShiftFlag;
}
break;
}
// RETAILMSG(1,(TEXT("VirtualKey: %08x ShiftFlags %08x\r\n"),VirtualKey, ShiftFlags));
// 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;
}
// RETAILMSG(1,(TEXT("KeybdDriverMapVirtualKey: %08x\r\n"), uRet));
return uRet;
}
#ifdef DEBUG
PFN_KEYBD_DRIVER_MAP_VIRTUAL_KEY v_pfnMapVirtualKeyTest = KeybdDriverMapVirtualKey;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -