Changeset 7216 for trunk/src


Ignore:
Timestamp:
Oct 26, 2001, 2:46:17 PM (24 years ago)
Author:
phaller
Message:

AltGr fix

Location:
trunk/src/user32
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/HOOK.CPP

    r7212 r7216  
    1 /* $Id: HOOK.CPP,v 1.31 2001-10-26 10:03:33 phaller Exp $ */
     1/* $Id: HOOK.CPP,v 1.32 2001-10-26 12:46:16 phaller Exp $ */
    22
    33/*
     
    4545#include <wprocess.h>
    4646#include "menu.h"
     47#include <winscan.h>
    4748
    4849#include "win32wbase.h"
     
    825826 
    826827    // this undoc (don't care) bit isn't passed through to this hook
    827     DWORD lParam = msg->lParam & ~0x02000000;
     828    // DWORD lParam = msg->lParam & ~0x02000000;
     829    msg->lParam &= ~0x02000000;
    828830 
    829831    return (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
    830                              LOWORD (msg->wParam), lParam )
     832                             LOWORD (msg->wParam), msg->lParam )
    831833                             ? TRUE : FALSE);
    832834}
     
    843845BOOL ProcessKbdHookLL(LPMSG msg, BOOL flagRemove, BOOL flagInjected )
    844846{
    845   // @@@PH
    846847  // format KBDLLHOOKSTRUCT and pass it in as msg->lParam
    847848  KBDLLHOOKSTRUCT kbhs;
    848849 
     850  kbhs.vkCode      = msg->wParam;
     851 
     852  // Note: the "extended" bit seems to be filtered
     853  kbhs.scanCode    = ( (msg->lParam & 0x02ff0000) >> 16);
     854 
     855  BOOL fKeyUp      = (msg->message == WM_KEYUP) ||
     856                     (msg->message == WM_SYSKEYUP);
     857 
    849858  // check if alt is currently pressed
    850859  // Note: ALT seems to stick sometimes
    851   // BOOL fAltDown = GetKeyState(VK_LMENU);
    852   BOOL fAltDown = GetAsyncKeyState(VK_LMENU);
    853  
    854   kbhs.vkCode      = msg->wParam;
    855   kbhs.scanCode    = ( (msg->lParam & 0x03ff0000) >> 16);
    856  
    857   BOOL fKeyUp      = (msg->message == WM_KEYUP) ||
    858                      (msg->message == WM_SYSKEYUP);
     860  // Note: ALTGR can't be queried
     861  BOOL fAltDown; // = GetAsyncKeyState(VK_LMENU);
     862 
     863  // this bit indicates if ALT was held
     864  fAltDown = msg->lParam & 0x20000000;
     865 
    859866  kbhs.flags       = fKeyUp ? LLKHF_UP : 0;
    860867 
    861   // @@@PH seems not to work properly
    862868  kbhs.flags      |= fAltDown ? LLKHF_ALTDOWN : 0;
    863869  kbhs.flags      |= flagInjected ? LLKHF_INJECTED : 0;
    864870  kbhs.flags      |= (msg->lParam & (1 << 24)) ? LLKHF_EXTENDED : 0;
    865  
    866 /*
    867   kbhs.flags       = ( (msg->lParam & (1 << 24)) ? LLKHF_EXTENDED : 0 ) |
    868                      ( flagInjected ? LLKHF_INJECTED : 0) |
    869                      fAltDown ? LLKHF_ALTDOWN : 0 |
    870                      ( (msg->lParam & (1 << 31)) ? LLKHF_UP : 0);
    871                      */
    872871  kbhs.time        = msg->time;
    873872  kbhs.dwExtraInfo = 0; // @@@PH not supported?
  • trunk/src/user32/oslibmsgtranslate.cpp

    r7213 r7216  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.71 2001-10-26 10:11:50 phaller Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.72 2001-10-26 12:46:16 phaller Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    4545static MSG  doubleClickMsg = {0};
    4646
    47 
    48 // Note:
    49 // For a "lonekey"-press of AltGr, we only receive WM_KEYUP
    50 // messages. If the key is pressed longer and starts to repeat,
    51 // WM_KEYDOWN messages come in properly.
    52 static BOOL fKeyAltGrDown = FALSE;
    53 
    5447//******************************************************************************
    5548//******************************************************************************
     
    584577        }
    585578        // vitali add end
    586 
     579     
    587580        // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
    588581        // given the OS/2 virtual key and OS/2 character
     
    622615        BYTE  bWinVKey;
    623616        WORD  wWinScan;
    624        
     617
    625618        // Note: Numlock-state currently ignored, see below
    626619        KeyTranslatePMScanToWinVKey(scanCode,
     
    642635            (virtualKey >= 0x30) && (virtualKey >= 39))
    643636            winMsg->wParam = virtualKey + 0x30;
    644 
    645 
     637     
     638     
     639        #define WIN_KEY_EXTENDED   0x01000000
     640        #define WIN_KEY_DONTCARE   0x02000000
     641        #define WIN_KEY_ALTHELD    0x20000000
     642        #define WIN_KEY_PREVSTATE  0x40000000
     643
     644        if (scanCode == PMSCAN_ALTRIGHT)
     645        {
     646          // Turn message into CTRL-event
     647          // The original PM message is still saved inside
     648          // the TEB, the next call to TranslateMessage()
     649          // will then generate the required additional message
     650          // for the ALTGR-event.
     651          winMsg->wParam = VK_LCONTROL_W;
     652          winMsg->lParam = repeatCount & 0x0FFFF;
     653          winMsg->lParam |= WINSCAN_CTRLLEFT << 16
     654                            |  WIN_KEY_DONTCARE;
     655         
     656          if (flags & KC_KEYUP)
     657          {
     658            winMsg->message = WINWM_SYSKEYUP;
     659            winMsg->lParam |= 1 << 29;                              // bit 29, alt was pressed
     660            winMsg->lParam |= 1 << 30;                              // bit 30, previous state, always 1 for a WM_KEYUP message
     661            winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
     662          }
     663          else
     664          {
     665            winMsg->lParam |= WIN_KEY_ALTHELD;
     666            if (keyWasPressed)
     667              winMsg->lParam |= 1 << 30;                          // bit 30, previous state, 1 means key was pressed
     668            winMsg->message = WINWM_KEYDOWN;
     669          }
     670         
     671          break;
     672        }
     673     
     674     
    646675        if (!(flags & KC_ALT))
    647676        {
     
    704733          }
    705734        }
    706      
    707         // ------------------------------------------------
    708         // check if additional messages have to be recorded
    709         // ------------------------------------------------
    710 #if 0
    711         {
    712           MSG extramsg;
    713           extramsg.hwnd = winMsg->hwnd;
    714           extramsg.time = winMsg->time;
    715           extramsg.pt   = winMsg->pt;
    716          
    717           switch (scanCode)
    718           {
    719             case PMSCAN_PRINT:
    720               // Note: PRINT generates a WM_KEYUP under Windows
    721               // also only call the standard kbd hook for the WM_KEYUP msg,
    722               // the low-level hook is called twice
    723               // mb->putWinMsg(hwndWin32, WM_CHAR, VK_PRINT_W, ... )
    724               // WM_CHAR(0x0000002ch, c1370001h)
    725               extramsg.message = WINWM_KEYUP;
    726               extramsg.wParam  = VK_PRINT_W;
    727               extramsg.lParam  = winMsg->lParam;
    728               setThreadQueueExtraCharMessage(teb, &extramsg);
    729               break;
    730            
    731             #define WIN_KEY_EXTENDED   0x01000000
    732             #define WIN_KEY_DONTCARE   0x02000000
    733             #define WIN_KEY_ALTHELD    0x20000000
    734             #define WIN_KEY_PREVSTATE  0x40000000
    735             case PMSCAN_ALTRIGHT:
    736             {
    737               // we need very special treatment here for the
    738               // poor, crippled AltGr key
    739               // Note: see fKeyAltGrDown above!
    740              
    741               if ( (keyWasPressed) || (fKeyAltGrDown == FALSE) )
    742               {
    743                 fKeyAltGrDown = TRUE;
    744                
    745                 // 1 - generate a virtual LCONTROL-keypress
    746                 // 2 - send LMENU-keypress (NT emulates ALtGr w/ Ctrl-AltGr!)
    747                 // 0xfe000000: mask out extended-key, scancode, repeatcount
    748                 // Note: Win sends a WINWM_SYSKEYDOWN to the hooks,
    749                 // the queue gets a WM_KEYDOWN only! (wrong impl. here)
    750                 extramsg.message = WINWM_KEYDOWN;
    751                 extramsg.wParam  = VK_RMENU_W;
    752                 extramsg.lParam  = (winMsg->lParam & 0xfe000000)
    753                                    | WIN_KEY_EXTENDED
    754                                    | (keyWasPressed ? WIN_KEY_PREVSTATE : 0)
    755                                    | WIN_KEY_ALTHELD
    756                                    | repeatCount
    757                                    | (WINSCAN_ALTRIGHT << 16);
    758                 winMsg->message  = WINWM_KEYDOWN;
    759                 winMsg->wParam   = VK_LCONTROL_W;
    760                 winMsg->lParam   = (winMsg->lParam & 0xfe000000)
    761                                    | WIN_KEY_DONTCARE
    762                                    | (keyWasPressed ? WIN_KEY_PREVSTATE : 0)
    763                                    | WIN_KEY_ALTHELD
    764                                    | repeatCount
    765                                    | (WINSCAN_CTRLLEFT << 16);
    766               }
    767               else
    768               {
    769                 // OK, now we can release it!
    770                 fKeyAltGrDown = FALSE;
    771                
    772                 // key up
    773                 // 1 - generate a virtual LCONTROL-keypress
    774                 // 2 - send LMENU-keypress (NT emulates ALtGr w/ Ctrl-Alt!)
    775                 extramsg.message = WINWM_KEYUP;
    776                 extramsg.wParam  = VK_RMENU_W;
    777                 extramsg.lParam  = (winMsg->lParam & 0xfe000000)
    778                                    | WIN_KEY_EXTENDED
    779                                    | repeatCount
    780                                    | (WINSCAN_ALTRIGHT << 16);
    781                 winMsg->message  = WINWM_SYSKEYUP;
    782                 winMsg->wParam   = VK_LCONTROL_W;
    783                 winMsg->lParam   = (winMsg->lParam & 0xfe000000)
    784                                    | WIN_KEY_ALTHELD
    785                                    | repeatCount
    786                                    | (WINSCAN_CTRLLEFT << 16);
    787               }
    788              
    789               // @@@PH
    790               // unknown: this leads to an infinite loop
    791               // because the OS/2 WM_CHAR_SPECIAL message is never
    792               // removed from the queue?!
    793               setThreadQueueExtraCharMessage(teb, &extramsg);
    794              
    795               if ( (keyWasPressed) || (fKeyAltGrDown == FALSE) )
    796               {
    797                 fKeyAltGrDown = TRUE;
    798                
    799                 // 1 - generate a virtual LCONTROL-keypress
    800                 // 2 - send LMENU-keypress (NT emulates ALtGr w/ Ctrl-AltGr!)
    801                 // 0xfe000000: mask out extended-key, scancode, repeatcount
    802                 // Note: Win sends a WINWM_SYSKEYDOWN to the hooks,
    803                 // the queue gets a WM_KEYDOWN only! (wrong impl. here)
    804                 winMsg->message = WINWM_KEYDOWN;
    805                 winMsg->wParam  = VK_RMENU_W;
    806                 winMsg->lParam  = (winMsg->lParam & 0xfe000000)
    807                                    | WIN_KEY_EXTENDED
    808                                    | (keyWasPressed ? WIN_KEY_PREVSTATE : 0)
    809                                    | WIN_KEY_ALTHELD
    810                                    | repeatCount
    811                                    | (WINSCAN_ALTRIGHT << 16);
    812               }
    813               else
    814               {
    815                 // OK, now we can release it!
    816                 fKeyAltGrDown = FALSE;
    817                
    818                 // key up
    819                 // 1 - generate a virtual LCONTROL-keypress
    820                 // 2 - send LMENU-keypress (NT emulates ALtGr w/ Ctrl-Alt!)
    821                 winMsg->message = WINWM_KEYUP;
    822                 winMsg->wParam  = VK_RMENU_W;
    823                 winMsg->lParam  = (winMsg->lParam & 0xfe000000)
    824                                    | WIN_KEY_EXTENDED
    825                                    | repeatCount
    826                                    | (WINSCAN_ALTRIGHT << 16);
    827               }
    828             }
    829             break;
    830           } /* switch */
    831         }
    832 #endif
    833      
     735
    834736        if (ISKDB_CAPTURED())
    835737        {
     
    983885BOOL OSLibWinTranslateMessage(MSG *msg)
    984886{
    985  TEB *teb;
    986 
    987     teb = GetThreadTEB();
    988     if(!teb) {
    989         return FALSE;
    990     }
     887  TEB *teb;
     888  MSG extramsg;
     889
     890  teb = GetThreadTEB();
     891  if(!teb)
     892    return FALSE;
     893
     894  UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
     895  ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
     896 
     897 
     898  // special ALTRIGHT treatment:
     899  // we try to insert another WM_KEYDOWN or WM_KEYUP instead of
     900  // the usual WM_CHAR which is expected here.
     901  // -> experimental
     902  if (ucPMScanCode == PMSCAN_ALTRIGHT)
     903  {
     904    // it's really an OS/2-style WM_CHAR message?
     905    // and not previously translated?
     906    if ( ( (teb->o.odin.os2msg.msg != WM_CHAR) &&
     907           (teb->o.odin.os2msg.msg != WM_CHAR_SPECIAL) ) ||
     908         (teb->o.odin.fTranslated) )
     909      return FALSE;
     910   
     911    memcpy(&extramsg, msg, sizeof(MSG));
     912   
     913    // AltGr is not released with WINWM_SYSKEYUP, but WINWM_KEYUP
     914    if (fl & KC_KEYUP)
     915      extramsg.message = WINWM_KEYUP;
     916   
     917    extramsg.wParam = VK_RMENU_W;
     918   
     919    // mask out message bits and scan code
     920    extramsg.lParam &= (0xDC00FFFF);
     921    extramsg.lParam |= (WINSCAN_ALTRIGHT & 0x1FF) << 16;
     922    extramsg.lParam |= WIN_KEY_EXTENDED;
     923   
     924    // insert message into the queue
     925    setThreadQueueExtraCharMessage(teb, &extramsg);
     926    return TRUE;
     927  }
     928 
    991929    //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
    992930    //      the newly generated WM_CHAR message.
    993     if(!teb->o.odin.fTranslated && teb->o.odin.os2msg.msg == WM_CHAR && !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
     931    if(!teb->o.odin.fTranslated &&
     932       teb->o.odin.os2msg.msg == WM_CHAR &&
     933       !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
    994934    {
    995935      //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
    996       ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
    997       MSG extramsg;
    998 
    999936      memcpy(&extramsg, msg, sizeof(MSG));
    1000937      extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
     
    1003940      // ESCAPE generates a WM_CHAR under windows, so take
    1004941      // special care for this here.
    1005       UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
    1006942      switch (ucPMScanCode)
    1007943      {
  • trunk/src/user32/pmwindow.cpp

    r7211 r7216  
    1 /* $Id: pmwindow.cpp,v 1.159 2001-10-26 09:10:12 phaller Exp $ */
     1/* $Id: pmwindow.cpp,v 1.160 2001-10-26 12:46:16 phaller Exp $ */
    22/*
    33 * Win32 Window Managment Code for OS/2
     
    4646#include "menu.h"
    4747#include <pmkbdhk.h>
     48#include <pmscan.h>
     49#include <winscan.h>
    4850
    4951#define DBG_LOCALLOG    DBG_pmwindow
     
    6466static PFNWP pfnFrameWndProc = NULL;
    6567static HWND  hwndFocusChange = 0;
     68
     69// Note:
     70// For a "lonekey"-press of AltGr, we only receive WM_KEYUP
     71// messages. If the key is pressed longer and starts to repeat,
     72// WM_KEYDOWN messages come in properly.
     73static BOOL fKeyAltGrDown = FALSE;
     74
     75
    6676
    6777MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  • trunk/src/user32/winkeyboard.cpp

    r7212 r7216  
    1 /* $Id: winkeyboard.cpp,v 1.23 2001-10-26 10:03:34 phaller Exp $ */
     1/* $Id: winkeyboard.cpp,v 1.24 2001-10-26 12:46:17 phaller Exp $ */
    22/*
    33 * Win32 <-> PM key translation
     
    144144/* 0x5B PMSCAN_CTRLRIGHT    */ , VK_RCONTROL                ,TRUE
    145145/* 0x5C PMSCAN_PADSLASH     */ , VK_DIVIDE                  ,TRUE
    146 /* 0x5D PMSCAN_PRINT        */ , VK_PRINT                   ,TRUE
     146/* 0x5D PMSCAN_PRINT        */ , VK_SNAPSHOT                ,TRUE
    147147/* 0x5E PMSCAN_ALTRIGHT     */ , VK_RMENU                   ,TRUE
    148148/* 0x5F PMSCAN_PAUSE        */ , VK_PAUSE                   ,FALSE
     
    362362/* 0x28 VK_DOWN           */ , PMSCAN_DOWN            , "Down"
    363363/* 0x29 VK_SELECT         */ , 0x00                   , NULL
    364 /* 0x2A VK_PRINT          */ , PMSCAN_PRINT           , "Print"
     364/* 0x2A VK_PRINT          */ , 0x00                   , NULL
    365365/* 0x2B VK_EXECUTE        */ , 0x00                   , NULL
    366366/* 0x2C VK_SNAPSHOT       */ , PMSCAN_PRINT           , "Print"  // NT4SP6: appears to be printscreen!
Note: See TracChangeset for help on using the changeset viewer.