Ignore:
Timestamp:
Feb 16, 2003, 4:31:12 PM (23 years ago)
Author:
sandervl
Message:

ToAscii, GetKeyState, GetAsyncKeyState & GetKeyboardState fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/winkeyboard.cpp

    r9689 r9810  
    1 /* $Id: winkeyboard.cpp,v 1.38 2003-01-17 16:35:38 sandervl Exp $ */
     1/* $Id: winkeyboard.cpp,v 1.39 2003-02-16 15:31:12 sandervl Exp $ */
    22/*
    33 * Win32 <-> PM key translation
     
    1717#include <stdio.h>
    1818#include <winkeyboard.h>
    19 #include "oslibwin.h"
     19#include "oslibkbd.h"
    2020#include <heapstring.h>
    2121#include <pmscan.h>
     
    415415/* 0x55 VK_U              */ , PMSCAN_U               , "U"
    416416/* 0x56 VK_V              */ , PMSCAN_V               , "V"
    417 /* 0x57 VK                */ , PMSCAN_W               , "W"
     417/* 0x57 VK_W              */ , PMSCAN_W               , "W"
    418418/* 0x58 VK_X              */ , PMSCAN_X               , "X"
    419419/* 0x59 VK_Y              */ , PMSCAN_Y               , "Y"
     
    861861                                     int nrkeys)
    862862{
     863   int pmvkey;
     864
     865#ifdef DEBUG
     866   for(int j=1;j<nrkeys;j++) {
     867       if(pmkey[j])
     868           dprintf2(("PM vkey %x state %x", j, pmkey[j]));
     869   }
     870#endif
     871
    863872   for(int i=1;i<nrkeys;i++) {
    864873       if(abWinVKeyToPMScan[i].bPMScanCode) {
    865             winkey[i] = pmkey[OSLibWinTranslateChar(abWinVKeyToPMScan[i].bPMScanCode, TC_SCANCODETOVIRTUALKEY, 0)];
     874            pmvkey = OSLibWinTranslateChar(abWinVKeyToPMScan[i].bPMScanCode, TC_SCANCODETOVIRTUALKEY, 0);
     875            if(pmvkey == 0) {
     876                dprintf2(("WinTranslateChar %x (%x) FAILED!!", i, abWinVKeyToPMScan[i].bPMScanCode));
     877            }
     878            winkey[i] = pmkey[pmvkey];
    866879       }
     880       else dprintf2(("key %x has no PM scancode", i));
    867881   }
    868882   winkey[VK_SHIFT]   = winkey[VK_LSHIFT] | winkey[VK_RSHIFT];
     
    970984BOOL WIN32API GetKeyboardState(PBYTE lpKeyState)
    971985{
     986#if 1
     987   int state;
     988   for(int i=0;i<256;i++) {
     989       state = GetKeyState(i);
     990       lpKeyState[i] = ((state & 0x8000) >> 8) | (state & 1);
     991       if(lpKeyState[i] & 0x80) {
     992           dprintf2(("Win key 0x%0x = %x", i, lpKeyState[i]));
     993       }
     994   }
     995   return TRUE;
     996#if 1
     997#else
     998   BYTE PMScanState[256];
     999   BOOL rc;
     1000   int  state;
     1001
     1002   memset(PMScanState, 0, sizeof(PMScanState));
     1003   memset(lpKeyState, 0, 256);
     1004
     1005   //
     1006   //OSLibWinGetKeyboardStateTable returns the state of PM virtual keys only and
     1007   //there are far fewer PM vkeys. (e.g. 0-9, A-Z are not included)
     1008   //So we need to use OSLibWinGetScanStateTable (WinSetScanState)
     1009   //
     1010   rc = OSLibWinGetScanStateTable((PBYTE)&PMScanState[0] );
     1011   if(!rc) {
     1012//       DebugInt3();
     1013       dprintf(("OSLibWinGetScanStateTable FAILED"));
     1014       return FALSE;
     1015   }
     1016   for(int i=0;i<256;i++) {
     1017       if(abWinVKeyToPMScan[i].bPMScanCode) {
     1018           lpKeyState[i] = PMScanState[abWinVKeyToPMScan[i].bPMScanCode];
     1019       }
     1020       if(lpKeyState[i] & 0x80) {
     1021           dprintf2(("Win key 0x%0x = %x", i, lpKeyState[i]));
     1022       }
     1023   }
     1024   //now process the mouse buttons (left, middle, right)
     1025   state = GetKeyState(VK_LBUTTON);
     1026   lpKeyState[VK_LBUTTON] = ((state & 0x8000) >> 8) | (state & 1);
     1027   state = GetKeyState(VK_MBUTTON);
     1028   lpKeyState[VK_MBUTTON] = ((state & 0x8000) >> 8) | (state & 1);
     1029   state = GetKeyState(VK_RBUTTON);
     1030   lpKeyState[VK_RBUTTON] = ((state & 0x8000) >> 8) | (state & 1);
     1031#ifdef DEBUG
     1032   if(lpKeyState[VK_LBUTTON]) {
     1033      dprintf2(("Win key 0x%0x = %x", VK_LBUTTON, lpKeyState[VK_LBUTTON]));
     1034   }
     1035   if(lpKeyState[VK_MBUTTON]) {
     1036      dprintf2(("Win key 0x%0x = %x", VK_MBUTTON, lpKeyState[VK_MBUTTON]));
     1037   }
     1038   if(lpKeyState[VK_RBUTTON]) {
     1039      dprintf2(("Win key 0x%0x = %x", VK_RBUTTON, lpKeyState[VK_RBUTTON]));
     1040   }
     1041#endif
     1042   return TRUE;
     1043#endif
     1044#else
    9721045 BYTE   PMKeyState[256];
    9731046 BOOL   rc;
     
    9991072  }
    10001073  return FALSE;
     1074#endif
    10011075}
    10021076//******************************************************************************
     
    11521226       if(lpbKeyState[VK_LSHIFT]   & 0x80) shiftstate |= TCF_LSHIFT;
    11531227       if(lpbKeyState[VK_RSHIFT]   & 0x80) shiftstate |= TCF_RSHIFT;
    1154        if(lpbKeyState[VK_SHIFT]    & 0x80) shiftstate |= TCF_SHIFT;
    11551228       if(lpbKeyState[VK_LCONTROL] & 0x80) shiftstate |= TCF_LCONTROL;
    11561229       if(lpbKeyState[VK_RCONTROL] & 0x80) shiftstate |= TCF_RCONTROL;
    1157        if(lpbKeyState[VK_CONTROL]  & 0x80) shiftstate |= TCF_CONTROL;
    11581230       if(lpbKeyState[VK_LMENU]    & 0x80) shiftstate |= TCF_ALT;
    11591231       if(lpbKeyState[VK_RMENU]    & 0x80) shiftstate |= TCF_ALTGR;
    1160        if(lpbKeyState[VK_MENU]     & 0x80) shiftstate |= TCF_ALT;
    11611232       if(lpbKeyState[VK_CAPITAL]  & 1)    shiftstate |= TCF_CAPSLOCK;
    11621233       if(lpbKeyState[VK_NUMLOCK]  & 1)    shiftstate |= TCF_NUMLOCK;
     
    13971468      return 0x0000;
    13981469  }
    1399   if (nVirtKey == VK_MENU)  return O32_GetKeyState(VK_LMENU) | O32_GetKeyState(VK_RMENU);
     1470
     1471  //If there's a PM scancode for this virtual key, then call WinGetScanState
     1472  //O32_GetKeyState converts windows virtual keys to PM virtual keys and there
     1473  //are far fewer PM vkeys. (e.g. 0-9, A-Z will fail)
     1474  if(nVirtKey < 256 && abWinVKeyToPMScan[nVirtKey].bPMScanCode)
     1475  {
     1476      INT  nVirtKey2 = 0;
     1477      WORD result;
     1478
     1479      if (nVirtKey == VK_MENU)  {
     1480          nVirtKey  = VK_LMENU;
     1481          nVirtKey2 = VK_RMENU;
     1482      }
     1483      else
     1484      if (nVirtKey == VK_CONTROL) {
     1485          nVirtKey  = VK_LCONTROL;
     1486          nVirtKey2 = VK_RCONTROL;
     1487      }
     1488      else
     1489      if (nVirtKey == VK_SHIFT) {
     1490          nVirtKey  = VK_LSHIFT;
     1491          nVirtKey2 = VK_RSHIFT;
     1492      }
     1493      result = OSLibWinGetScanState(abWinVKeyToPMScan[nVirtKey].bPMScanCode);
     1494      if(nVirtKey2) {
     1495          result |= OSLibWinGetScanState(abWinVKeyToPMScan[nVirtKey2].bPMScanCode);
     1496      }
     1497      return result;
     1498  }
     1499 
    14001500  return O32_GetKeyState(nVirtKey);
    14011501}
     
    14191519      return 0x0000;
    14201520  }
    1421   if (nVirtKey == VK_MENU)  return O32_GetAsyncKeyState(VK_LMENU) | O32_GetAsyncKeyState(VK_RMENU);
     1521
     1522  //If there's a PM scancode for this virtual key, then call WinGetPhysKeyState
     1523  //O32_GetAsyncKeyState converts windows virtual keys to PM virtual keys and there
     1524  //are far fewer PM vkeys. (e.g. 0-9, A-Z will fail)
     1525  if(nVirtKey < 256 && abWinVKeyToPMScan[nVirtKey].bPMScanCode)
     1526  {
     1527      INT  nVirtKey2 = 0;
     1528      WORD result;
     1529
     1530      if (nVirtKey == VK_MENU)  {
     1531          nVirtKey  = VK_LMENU;
     1532          nVirtKey2 = VK_RMENU;
     1533      }
     1534      else
     1535      if (nVirtKey == VK_CONTROL) {
     1536          nVirtKey  = VK_LCONTROL;
     1537          nVirtKey2 = VK_RCONTROL;
     1538      }
     1539      else
     1540      if (nVirtKey == VK_SHIFT) {
     1541          nVirtKey  = VK_LSHIFT;
     1542          nVirtKey2 = VK_RSHIFT;
     1543      }
     1544
     1545      result = OSLibWinGetPhysKeyState(abWinVKeyToPMScan[nVirtKey].bPMScanCode);
     1546      if(nVirtKey2) {
     1547          result |= OSLibWinGetPhysKeyState(abWinVKeyToPMScan[nVirtKey2].bPMScanCode);
     1548      }
     1549      return result;
     1550  }
     1551
    14221552  return O32_GetAsyncKeyState(nVirtKey);
    14231553}
     
    14261556UINT WIN32API MapVirtualKeyA(UINT uCode,  UINT uMapType)
    14271557{
    1428   dprintf(("imcompletely implemented"));
     1558  dprintf(("incompletely implemented"));
    14291559 
    14301560  /* A quick fix for Commandos, very incomplete */
     
    14511581UINT WIN32API MapVirtualKeyW(UINT uCode, UINT uMapType)
    14521582{
    1453   dprintf(("incorrectly implemented\n"));
     1583  dprintf(("incorrectly implemented"));
    14541584 
    14551585  // NOTE: This will not work as is (needs UNICODE support)
    1456   return O32_MapVirtualKey(uCode,uMapType);
     1586  return MapVirtualKeyA(uCode,uMapType);
    14571587}
    14581588/*****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.