Ignore:
Timestamp:
Mar 26, 2001, 12:41:50 AM (24 years ago)
Author:
sandervl
Message:

MN: keyboard translation fixes

File:
1 edited

Legend:

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

    r5236 r5382  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.41 2001-02-21 20:51:06 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.42 2001-03-25 22:41:50 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    3636#include "dbglocal.h"
    3737
    38 //Used for key translation while processing WM_CHAR message
    39 USHORT virtualKeyTable [66] = {
    40                0x00,    //   OS/2 VK         Win32 VK,    Entry 0 is not used
    41                0x01,    // VK_BUTTON1       VK_LBUTTON
    42                0x02,    // VK_BUTTON2       VK_RBUTTON
    43                0x04,    // VK_BUTTON3       VK_MBUTTON
    44                0x03,    // VK_BREAK         VK_CANCEL
    45                0x08,    // VK_BACKSPACE     VK_BACK
    46                0x09,    // VK_TAB           VK_TAB
    47                0x00,    // VK_BACKTAB       No equivalent!
    48                0x0D,    // VK_NEWLINE       VK_RETURN
    49                0x10,    // VK_SHIFT         VK_SHIFT
    50                0x11,    // VK_CTRL          VK_CONTROL
    51                0x12,    // VK_ALT           VK_MENU, best match I guess
    52                0x12,    // VK_ALTGRAF       VK_MENU, best match I guess
    53                0x13,    // VK_PAUSE         VK_PAUSE
    54                0x14,    // VK_CAPSLOCK      VK_CAPITAL
    55                0x1B,    // VK_ESC           VK_ESCAPE
    56                0x20,    // VK_SPACE         VK_SPACE
    57                0x21,    // VK_PAGEUP        VK_PRIOR
    58                0x22,    // VK_PAGEDOWN      VK_NEXT
    59                0x23,    // VK_END           VK_END
    60                0x24,    // VK_HOME          VK_HOME
    61                0x25,    // VK_LEFT          VK_LEFT
    62                0x26,    // VK_UP            VK_UP
    63                0x27,    // VK_RIGHT         VK_RIGHT
    64                0x28,    // VK_DOWN          VK_DOWN
    65                0x2C,    // VK_PRINTSCRN     VK_SNAPSHOT
    66                0x2D,    // VK_INSERT        VK_INSERT
    67                0x2E,    // VK_DELETE        VK_DELETE
    68                0x91,    // VK_SCRLLOCK      VK_SCROLL
    69                0x90,    // VK_NUMLOCK       VK_NUMLOCK
    70                0x0D,    // VK_ENTER         VK_RETURN
    71                0x00,    // VK_SYSRQ         No equivalent!
    72                0x70,    // VK_F1            VK_F1
    73                0x71,    // VK_F2            VK_F2
    74                0x72,    // VK_F3            VK_F3
    75                0x73,    // VK_F4            VK_F4
    76                0x74,    // VK_F5            VK_F5
    77                0x75,    // VK_F6            VK_F6
    78                0x76,    // VK_F7            VK_F7
    79                0x77,    // VK_F8            VK_F8
    80                0x78,    // VK_F9            VK_F9
    81                0x79,    // VK_F10           VK_F10
    82                0x7A,    // VK_F11           VK_F11
    83                0x7B,    // VK_F12           VK_F12
    84                0x7C,    // VK_F13           VK_F13
    85                0x7D,    // VK_F14           VK_F14
    86                0x7E,    // VK_F15           VK_F15
    87                0x7F,    // VK_F16           VK_F16
    88                0x80,    // VK_F17           VK_F17
    89                0x81,    // VK_F18           VK_F18
    90                0x82,    // VK_F19           VK_F19
    91                0x83,    // VK_F20           VK_F20
    92                0x84,    // VK_F21           VK_F21
    93                0x85,    // VK_F22           VK_F22
    94                0x86,    // VK_F23           VK_F23
    95                0x87,    // VK_F24           VK_F24
    96                0x00,    // VK_ENDDRAG       No equivalent!
    97                0x0C,    // VK_CLEAR         VK_CLEAR
    98                0xF9,    // VK_EREOF         VK_EREOF
    99                0xFD,    // VK_PA1           VK_PA1
    100                0xF6,    // VK_ATTN          VK_ATTN
    101                0xF7,    // VK_CRSEL         VK_CRSEL
    102                0xF8,    // VK_EXSEL         VK_EXSEL
    103                0x00,    // VK_COPY          No equivalent!
    104                0x00,    // VK_BLK1          No equivalent!
    105                0x00};   // VK_BLK2          No equivalent!
     38// Formerly used method of translation based on OS/2 VKEY value didn't work
     39// right. We need to take a look at the scan code we get from PM and derive
     40// the Win32 VKEY and scancode from that because sometimes even the scancode
     41// used in Win32 is different from the PM scancode!
     42// The format is:
     43// Win VKEY, Win scancode, (PM scancode) (key description)
     44USHORT pmscan2winkey [][2] = {
     45    0, 0,           // 0x00
     46    0x1B, 0x01,     // 0x01 Esc
     47    0x31, 0x02,     // 0x02 1
     48    0x32, 0x03,     // 0x03 2
     49    0x33, 0x04,     // 0x04 3
     50    0x34, 0x05,     // 0x05 4
     51    0x35, 0x06,     // 0x06 5
     52    0x36, 0x07,     // 0x07 6
     53    0x37, 0x08,     // 0x08 7
     54    0x38, 0x09,     // 0x09 8
     55    0x39, 0x0A,     // 0x0A 9
     56    0x30, 0x0B,     // 0x0B 0
     57    0xBD, 0x0C,     // 0x0C -
     58    0xBB, 0x0D,     // 0x0D =
     59    0x08, 0x0E,     // 0x0E Bksp
     60    0x09, 0x0F,     // 0x0F Tab
     61    0x51, 0x10,     // 0x10 q
     62    0x57, 0x11,     // 0x11 w
     63    0x45, 0x12,     // 0x12 e
     64    0x52, 0x13,     // 0x13 r
     65    0x54, 0x14,     // 0x14 t
     66    0x59, 0x15,     // 0x15 y
     67    0x55, 0x16,     // 0x16 u
     68    0x49, 0x17,     // 0x17 i
     69    0x4F, 0x18,     // 0x18 o
     70    0x50, 0x19,     // 0x19 p
     71    0xDB, 0x1A,     // 0x1A [
     72    0xDD, 0x1B,     // 0x1B ]
     73    0x0D, 0x1C,     // 0x1C Enter
     74    0x11, 0x1D,     // 0x1D LCtrl
     75    0x41, 0x1E,     // 0x1E a
     76    0x53, 0x1F,     // 0x1F s
     77    0x44, 0x20,     // 0x20 d
     78    0x46, 0x21,     // 0x21 f
     79    0x47, 0x22,     // 0x22 g
     80    0x48, 0x23,     // 0x23 h
     81    0x4A, 0x24,     // 0x24 j
     82    0x4B, 0x25,     // 0x25 k
     83    0x4C, 0x26,     // 0x26 l
     84    0xBA, 0x27,     // 0x27 ;
     85    0xDE, 0x28,     // 0x28 '
     86    0xC0, 0x29,     // 0x29 `
     87    0x10, 0x2A,     // 0x2A LShift
     88    0xDC, 0x2B,     // 0x2B Bkslsh
     89    0x5A, 0x2C,     // 0x2C z
     90    0x58, 0x2D,     // 0x2D x
     91    0x43, 0x2E,     // 0x2E c
     92    0x56, 0x2F,     // 0x2F v
     93    0x42, 0x30,     // 0x30 b
     94    0x4E, 0x31,     // 0x31 n
     95    0x4D, 0x32,     // 0x32 m
     96    0xBC, 0x33,     // 0x33 ,
     97    0xBE, 0x34,     // 0x34 .
     98    0xBF, 0x35,     // 0x35 /
     99    0x10, 0x36,     // 0x36 RShift
     100    0x6A, 0x37,     // 0x37 * Pad
     101    0x12, 0x38,     // 0x38 LAlt
     102    0x20, 0x39,     // 0x39 Space
     103    0x14, 0x3A,     // 0x3A CapsLk
     104    0x70, 0x3B,     // 0x3B F1
     105    0x71, 0x3C,     // 0x3C F2
     106    0x72, 0x3D,     // 0x3D F3
     107    0x73, 0x3E,     // 0x3E F4
     108    0x74, 0x3F,     // 0x3F F5
     109    0x75, 0x40,     // 0x40 F6
     110    0x76, 0x41,     // 0x41 F7
     111    0x77, 0x42,     // 0x42 F8
     112    0x78, 0x43,     // 0x43 F9
     113    0x79, 0x44,     // 0x44 F10 (?)
     114    0x90, 0x145,    // 0x45 NumLk
     115    0x91, 0x46,     // 0x46 ScrLk
     116    0x24, 0x47,     // 0x47 7 Pad
     117    0x26, 0x48,     // 0x48 8 Pad
     118    0x21, 0x49,     // 0x49 9 Pad
     119    0x6D, 0x4A,     // 0x4A - Pad
     120    0x25, 0x4B,     // 0x4B 4 Pad
     121    0x0C, 0x4C,     // 0x4C 5 Pad
     122    0x27, 0x4D,     // 0x4D 6 Pad
     123    0x6B, 0x4E,     // 0x4E + Pad
     124    0x23, 0x4F,     // 0x4F 1 Pad
     125    0x28, 0x50,     // 0x50 2 Pad
     126    0x22, 0x51,     // 0x51 3 Pad
     127    0x2D, 0x52,     // 0x52 0 Pad
     128    0x2E, 0x53,     // 0x53 . Pad
     129    0, 0,           // 0x54
     130    0, 0,           // 0x55
     131    0, 0,           // 0x56
     132    0x7A, 0x57,     // 0x57 F11
     133    0x7B, 0x58,     // 0x58 F12
     134    0, 0,           // 0x59
     135    0x0D, 0x11C,    // 0x5A Enter Pad
     136    0x11, 0x11D,    // 0x5B RCtrl
     137    0x6F, 0x135,    // 0x5C / Pad
     138    0x2D, 0x152,    // 0x5D PrtSc
     139    0x12, 0x5E,     // 0x5E RAlt
     140    0x13, 0x45,     // 0x5F Pause
     141    0, 0,           // 0x60
     142    0, 0,           // 0x61
     143    0, 0,           // 0x62
     144    0, 0,           // 0x63
     145    0, 0,           // 0x64
     146    0, 0,           // 0x65
     147    0, 0,           // 0x66
     148    0, 0,           // 0x67
     149    0, 0,           // 0x68
     150    0, 0,           // 0x69
     151    0, 0,           // 0x6A
     152    0, 0,           // 0x6B
     153    0x5D, 0x15D,    // 0x6C RWin (PM scan 0x7C)
     154    0, 0,           // 0x6D
     155    0x5B, 0x15B,    // 0x6E LWin (PM scan 0x7E)
     156    0x5C, 0x15C     // 0x6F RMenu? (PM scan 0x7F)
     157};
    106158
    107159//******************************************************************************
     
    233285        }
    234286        if(win32wnd->getParent()) {
    235               OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
     287              OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
    236288                                     win32wnd->getParent()->getClientRectPtr()->left,
    237289                                     win32wnd->getParent()->getClientRectPtr()->top,
    238290                                     win32wnd->getOS2WindowHandle());
    239         } 
     291        }
    240292        else  OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, win32wnd->getOS2WindowHandle());
    241293
     
    251303                        Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
    252304                        if(wndAfter)
    253                               teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
    254                         else  teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
     305                              teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
     306                        else  teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
    255307                }
    256308        }
     
    266318
    267319        hwndActivate = OS2ToWin32Handle(hwndActivate);
    268         if(hwndActivate == 0) {
     320        if(hwndActivate == 0) {
    269321                //another (non-win32) application's window
    270322                //set to desktop window handle
    271                 hwndActivate = windowDesktop->getWindowHandle();
    272         }
     323                hwndActivate = windowDesktop->getWindowHandle();
     324        }
    273325
    274326        if(win32wnd->getStyle() & WS_MINIMIZE_W)
     
    313365      winMsg->lParam  = MAKELONG(winMsg->pt.x,winMsg->pt.y);
    314366      if(!win32wnd->IsWindowEnabled()) {
    315                 if(win32wnd->getParent()) {
    316                         winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
    317                 }
    318                 else    goto dummymessage; //don't send mouse messages to disabled windows
     367                if(win32wnd->getParent()) {
     368                        winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
     369                }
     370                else    goto dummymessage; //don't send mouse messages to disabled windows
    319371      }
    320372      break;
     
    332384
    333385#ifdef ODIN_HITTEST
    334         //Send WM_HITTEST message
     386        //Send WM_HITTEST message
    335387        win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
    336388#endif
    337389        win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
    338390
    339         //if a window is disabled, it's parent receives the mouse messages
    340         if(!win32wnd->IsWindowEnabled()) {
    341                 if(win32wnd->getParent()) {
    342                         win32wnd = win32wnd->getParent();
    343                 }
    344                 fWasDisabled = TRUE;
    345         }
     391        //if a window is disabled, it's parent receives the mouse messages
     392        if(!win32wnd->IsWindowEnabled()) {
     393                if(win32wnd->getParent()) {
     394                        win32wnd = win32wnd->getParent();
     395                }
     396                fWasDisabled = TRUE;
     397        }
    346398
    347399        if(IsNCMouseMsg(win32wnd)) {
     
    367419        }
    368420
    369         if(fWasDisabled) {
    370                 if(win32wnd) {
    371                         winMsg->hwnd = win32wnd->getWindowHandle();
    372                 }
    373                 else    goto dummymessage; //don't send mouse messages to disabled windows
    374         }
     421        if(fWasDisabled) {
     422                if(win32wnd) {
     423                        winMsg->hwnd = win32wnd->getWindowHandle();
     424                }
     425                else    goto dummymessage; //don't send mouse messages to disabled windows
     426        }
    375427        break;
    376428
     
    395447
    396448#ifdef ODIN_HITTEST
    397         //Send WM_HITTEST message
     449        //Send WM_HITTEST message
    398450        win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
    399451#endif
    400452
    401         //if a window is disabled, it's parent receives the mouse messages
    402         if(!win32wnd->IsWindowEnabled()) {
    403                 if(win32wnd->getParent()) {
    404                         win32wnd = win32wnd->getParent();
    405                 }
    406                 fWasDisabled = TRUE;
    407         }
     453        //if a window is disabled, it's parent receives the mouse messages
     454        if(!win32wnd->IsWindowEnabled()) {
     455                if(win32wnd->getParent()) {
     456                        win32wnd = win32wnd->getParent();
     457                }
     458                fWasDisabled = TRUE;
     459        }
    408460        if(IsNCMouseMsg(win32wnd))
    409461        {
     
    429481            }
    430482        }
    431         if(fWasDisabled) {
    432                 if(win32wnd) {
    433                         winMsg->hwnd = win32wnd->getWindowHandle();
    434                 }
    435                 else    goto dummymessage; //don't send mouse messages to disabled windows
    436         }
     483        if(fWasDisabled) {
     484                if(win32wnd) {
     485                        winMsg->hwnd = win32wnd->getWindowHandle();
     486                }
     487                else    goto dummymessage; //don't send mouse messages to disabled windows
     488        }
    437489        //OS/2 Window coordinates -> Win32 Window coordinates
    438490        break;
     
    497549        ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
    498550        ULONG flags = SHORT1FROMMP(os2Msg->mp1);
    499         BOOL keyWasPressed;
     551        BOOL keyWasPressed, isExtended = FALSE;
    500552        char c;
    501553
     
    512564        {
    513565            // an extended key ( arrows, ins, del and so on )
    514             // get "virtual" scancode from character code cause
     566            // get "virtual" scancode from character code because
    515567            // for "regular" keys they are equal
    516568            scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
     569            isExtended = TRUE;
    517570        }
    518571        // vitali add end
     
    541594        }
    542595
    543         // convert OS/2 virtual keys to Win32 virtual key
    544         if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
    545             virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
    546 
    547596VirtualKeyFound:
    548         dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
    549 
    550         winMsg->wParam  = virtualKey;
     597//        dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
     598
     599        // Adjust PM scancodes for Win* keys
     600        if (scanCode >= 0x70)
     601            scanCode -= 0x10;
     602        winMsg->wParam  = pmscan2winkey[scanCode][0];
    551603        winMsg->lParam  = repeatCount & 0x0FFFF;                 // bit 0-15, repeatcount
    552         winMsg->lParam |= (scanCode & 0x0FF) << 16;              // bit 16-23, scancode
    553 
    554         //TODO: Is this correct and complete? (how does PM differentiate between
    555         //      i.e numeric pad pgdn & 'normal' pgdn??)
    556         //Check if it's an extended key
    557         switch(virtualKey) {
    558         case VK_RETURN_W:
    559                 //The enter key on the numeric keypad is an extended key
    560                 if(SHORT2FROMMP(os2Msg->mp2) != VK_NEWLINE)
    561                         break;
    562                 //no break
    563         case VK_LEFT_W:
    564         case VK_RIGHT_W:
    565         case VK_DOWN_W:
    566         case VK_UP_W:
    567         case VK_PRIOR_W:
    568         case VK_NEXT_W:
    569         case VK_END_W:
    570         case VK_DIVIDE_W:
    571         case VK_DELETE_W:
    572         case VK_HOME_W:
    573         case VK_INSERT_W:
    574         case VK_RCONTROL_W:
    575         case VK_RMENU_W: //is this the right alt???
    576                 winMsg->lParam = winMsg->lParam | (1<<24);
    577                 break;
    578         }
    579 
    580         if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
     604        winMsg->lParam |= (pmscan2winkey[scanCode][1] & 0x1FF) << 16;  // bit 16-23, scancode + bit 15 extended
     605
     606        // Adjust VKEY value for pad digits if NumLock is on
     607        if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
     608            (virtualKey >= 0x30) && (virtualKey >= 39))
     609            winMsg->wParam = virtualKey + 0x30;
     610
     611        // Set the extended bit when appropriate
     612        if (isExtended)
     613            winMsg->lParam = winMsg->lParam | (1<<24);
     614
     615        if (!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
    581616        {
    582617            //
     
    614649                    winMsg->lParam |= 1 << 30;                          // bit 30, previous state, 1 means key was pressed
    615650            }
    616             if(winMsg->wParam == VK_MENU_W) {
     651            if(winMsg->wParam == VK_MENU_W) {
    617652                winMsg->message = 0; //WM_SYS* already implies Alt
    618653            }
    619654        }
    620         if(ISKDB_CAPTURED())
    621         {
    622             if(DInputKeyBoardHandler(winMsg)) {
     655        if (ISKDB_CAPTURED())
     656        {
     657            if (DInputKeyBoardHandler(winMsg)) {
    623658                goto dummymessage; //dinput swallowed message
    624659            }
     
    763798
    764799            if(fl & KC_VIRTUALKEY) {
    765                 if(msg->wParam)
     800                if(msg->wParam) {
     801                    if ((msg->wParam >= VK_NUMPAD0_W) && (msg->wParam <= VK_NUMPAD9_W))
     802                        extramsg.wParam = msg->wParam - 0x30;
     803                    else
    766804                        extramsg.wParam = msg->wParam;
     805                }
    767806                else    extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
    768807            }
Note: See TracChangeset for help on using the changeset viewer.