+/* FUNCTIONS *****************************************************************/
+
+/*** Statics used by TranslateMessage ***/
+
+static VOID STDCALL SetKeyState(DWORD key, BOOL down) {
+ if( key >= 'a' && key <= 'z' ) key += 'A' - 'a';
+ QueueKeyStateTable[key] = down;
+}
+
+static BOOL SetModKey( PKBDTABLES pkKT, WORD wVK, BOOL down ) {
+ int i;
+
+ for( i = 0; pkKT->pCharModifiers->pVkToBit[i].Vk; i++ ) {
+ DbgPrint( "vk[%d] = { %04x, %x }\n", i,
+ pkKT->pCharModifiers->pVkToBit[i].Vk,
+ pkKT->pCharModifiers->pVkToBit[i].ModBits );
+ if( pkKT->pCharModifiers->pVkToBit[i].Vk == wVK ) {
+ if( down ) ModBits |= pkKT->pCharModifiers->pVkToBit[i].ModBits;
+ else ModBits &= ~pkKT->pCharModifiers->pVkToBit[i].ModBits;
+ DbgPrint( "ModBits: %x\n", ModBits );
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static BOOL TryToTranslateChar( WORD wVirtKey,
+ PVK_TO_WCHAR_TABLE vtwTbl,
+ DWORD ModBits,
+ PBOOL pbDead,
+ PBOOL pbLigature,
+ PWCHAR pwcTranslatedChar ) {
+ int i,j;
+ size_t size_this_entry = vtwTbl->cbSize;
+ int nStates = vtwTbl->nModifications;
+ PVK_TO_WCHARS10 vkPtr;
+
+ for( i = 0;; i++ ) {
+ vkPtr = (PVK_TO_WCHARS10)
+ (((BYTE *)vtwTbl->pVkToWchars) + i * size_this_entry);
+
+ if( !vkPtr->VirtualKey ) return FALSE;
+ if( wVirtKey == vkPtr->VirtualKey ) {
+ for( j = 0; j < nStates; j++ ) {
+ if( j == (int) ModBits ) { /* OK, we found a wchar with the correct
+ shift state and vk */
+ *pbDead = vkPtr->wch[j] == WCH_DEAD;
+ *pbLigature = vkPtr->wch[j] == WCH_LGTR;
+ *pwcTranslatedChar = vkPtr->wch[j];
+ if( *pbDead ) {
+ i++;
+ vkPtr = (PVK_TO_WCHARS10)
+ (((BYTE *)vtwTbl->pVkToWchars) + i * size_this_entry);
+ if( vkPtr->VirtualKey != 0xff ) {
+ DPRINT( "Found dead key with no trailer in the table.\n" );
+ DPRINT( "VK: %04x, ADDR: %08x\n", wVirtKey, (int)vkPtr );
+ return FALSE;
+ }
+ *pwcTranslatedChar = vkPtr->wch[j];
+ }
+ return TRUE;
+ }
+ }
+ }
+ }
+}
+
+static