Changeset 2765


Ignore:
Timestamp:
Aug 14, 2006, 6:55:06 AM (19 years ago)
Author:
bird
Message:

hacking on keyboard stuff.

Location:
trunk/synergy/lib/platform
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/platform/CMSWindowsKeyState.h

    r2749 r2765  
    22 * synergy -- mouse and keyboard sharing utility
    33 * Copyright (C) 2003 Chris Schoeneman
    4  * 
     4 *
    55 * This package is free software; you can redistribute it and/or
    66 * modify it under the terms of the GNU General Public License
    77 * found in the file COPYING that should have accompanied this file.
    8  * 
     8 *
    99 * This package is distributed in the hope that it will be useful,
    1010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     
    186186        CEventQueueTimer*       m_fixTimer;
    187187
     188#if 0
    188189        // the groups (keyboard layouts)
    189190        GroupList                       m_groups;
    190191        GroupMap                        m_groupMap;
     192#endif
    191193
    192194        // the last button that we generated a key down event for.  this
  • trunk/synergy/lib/platform/CPMKeyState.cpp

    r2763 r2765  
    1919#include "CLog.h"
    2020#include "CStringUtil.h"
     21#include "CPMUtil.h"
    2122#include "IEventQueue.h"
    2223#include "TMethodEventJob.h"
     
    111112};
    112113
    113 CPMKeyState::CPMKeyState(void* eventTarget) :
     114CPMKeyState::CPMKeyState(void* eventTarget, FakeMsgFunc fakeMsg) :
    114115        m_eventTarget(eventTarget),
     116        m_fakeMsg(fakeMsg),
     117    m_lastButton(0),
    115118        m_fixTimer(NULL),
    116119        m_lastDown(kKeyNone),
     
    119122        m_originalSavedModifiers(0)
    120123{
    121 
     124    LOG((CLOG_DEBUG "CPMKeyState:"));
    122125}
    123126
    124127CPMKeyState::~CPMKeyState()
    125128{
     129    LOG((CLOG_DEBUG "~CPMKeyState:"));
    126130        disable();
    127131}
     
    130134CPMKeyState::disable()
    131135{
     136    LOG((CLOG_DEBUG "disable:"));
    132137        if (m_fixTimer != NULL) {
    133138                EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
     
    141146CPMKeyState::virtualKeyToButton(ULONG virtualKey) const
    142147{
     148    LOG((CLOG_DEBUG "virtualKeyToButton:"));
    143149        return m_virtualKeyToButton[virtualKey & 0xffu];
    144150}
     
    147153CPMKeyState::testAutoRepeat(bool press, bool isRepeat, KeyButton button)
    148154{
     155    LOG((CLOG_DEBUG "testAutoRepeat:"));
    149156        if (!isRepeat)
    150157                isRepeat = press && button == m_lastDown && button != kKeyNone;
     
    156163CPMKeyState::saveModifiers()
    157164{
     165    LOG((CLOG_DEBUG "saveModifiers:"));
    158166        m_savedModifiers         = getActiveModifiers();
    159167        m_originalSavedModifiers = m_savedModifiers;
     
    163171CPMKeyState::useSavedModifiers(bool enable)
    164172{
     173    LOG((CLOG_DEBUG "useSavedModifiers:"));
    165174        if (enable != m_useSavedModifiers) {
    166175                m_useSavedModifiers = enable;
     
    176185CPMKeyState::mapKeyFromEvent(USHORT fsFlags, UCHAR ucRepeat, UCHAR ucScanCode, USHORT usch, USHORT usvk, KeyModifierMask* maskOut) const
    177186{
     187    LOG((CLOG_DEBUG "mapKeyFromEvent:"));
    178188#if 0 /** @todo */
    179189        static const KeyModifierMask s_controlAlt = KeyModifierControl | KeyModifierAlt;
     
    231241CPMKeyState::mapKeyToVirtualKey(KeyID key) const
    232242{
     243    LOG((CLOG_DEBUG "mapKeyToVirtualKey:"));
    233244        if (key == kKeyNone)
    234245                return 0;
     
    245256                                                        SInt32 count, KeyButton button)
    246257{
     258    LOG((CLOG_DEBUG "sendKeyEvent:"));
    247259        if (press || isAutoRepeat) {
    248260                // send key
     
    266278CPMKeyState::fakeKeyDown(KeyID id, KeyModifierMask mask, KeyButton button)
    267279{
     280    LOG((CLOG_DEBUG "fakeKeyDown: id=%#x mask=%#x button=%#x", id, mask, button));
    268281        CKeyState::fakeKeyDown(id, mask, button);
    269282}
     
    272285CPMKeyState::fakeKeyRepeat(KeyID id, KeyModifierMask mask, SInt32 count, KeyButton button)
    273286{
     287    LOG((CLOG_DEBUG "fakeKeyRepeat: id=%#x mask=%#x count=%d button=%#x", id, mask, count, button));
    274288        CKeyState::fakeKeyRepeat(id, mask, count, button);
    275289}
     
    278292CPMKeyState::fakeCtrlAltDel()
    279293{
     294    LOG((CLOG_DEBUG "fakeCtrlAltDel:"));
    280295    fakeKeyDown(kKeyDelete, KeyModifierControl | KeyModifierAlt, virtualKeyToButton(VK_DELETE));
    281296}
     
    284299CPMKeyState::pollActiveModifiers() const
    285300{
     301    LOG((CLOG_DEBUG "pollActiveModifiers:"));
    286302        KeyModifierMask state = 0;
    287303
     
    307323CPMKeyState::pollActiveGroup() const
    308324{
     325    LOG((CLOG_DEBUG "pollActiveGroup:"));
    309326#if 0
    310327        HKL hkl            = GetKeyboardLayout(targetThread);
     
    320337#else
    321338    return 0;
    322 #endif 
     339#endif
    323340}
    324341
     
    326343CPMKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
    327344{
     345    LOG((CLOG_DEBUG "pollPressedKeys:"));
    328346        BYTE keyState[256];
    329347    if (WinSetKeyboardStateTable(HWND_DESKTOP, keyState, FALSE)) {
     
    339357CPMKeyState::getKeyMap(CKeyMap& keyMap)
    340358{
     359    LOG((CLOG_DEBUG "getKeyMap:"));
    341360#if 0
    342361        // update keyboard groups
     
    349368        }
    350369        HKL activeLayout = GetKeyboardLayout(0);
     370#endif
    351371
    352372        // clear table
     
    355375
    356376        CKeyMap::KeyItem item;
    357         SInt32 numGroups = (SInt32)m_groups.size();
    358         for (SInt32 g = 0; g < numGroups; ++g) {
     377//      SInt32 numGroups = (SInt32)m_groups.size();
     378//      for (SInt32 g = 0; g < numGroups; ++g) {
     379        for (SInt32 g = 0; g < 1; ++g) {
    359380                item.m_group = g;
    360                 ActivateKeyboardLayout(m_groups[g], 0);
     381//              ActivateKeyboardLayout(m_groups[g], 0);
    361382
    362383                // clear tables
    363384                memset(m_buttonToVK, 0, sizeof(m_buttonToVK));
    364                 memset(m_buttonToNumpadVK, 0, sizeof(m_buttonToNumpadVK));
    365385
    366386                // map buttons (scancodes) to virtual keys
    367387                for (KeyButton i = 1; i < 256; ++i) {
    368                         ULONG vk = MapVirtualKey(i, 1);
    369                         if (vk == 0) {
    370                                 // unmapped
    371                                 continue;
    372                         }
    373 
    374                         // deal with certain virtual keys specially
    375                         switch (vk) {
    376                         case VK_SHIFT:
    377                                 if (MapVirtualKey(VK_RSHIFT, 0) == i) {
    378                                         vk = VK_RSHIFT;
    379                                 }
    380                                 else {
    381                                         vk = VK_LSHIFT;
    382                                 }
    383                                 break;
    384 
    385                         case VK_CONTROL:
    386                                 vk = VK_LCONTROL;
    387                                 break;
    388 
    389                         case VK_MENU:
    390                                 vk = VK_LMENU;
    391                                 break;
    392 
    393                         case VK_NUMLOCK:
    394                                 vk = VK_PAUSE;
    395                                 break;
    396 
    397                         case VK_NUMPAD0:
    398                         case VK_NUMPAD1:
    399                         case VK_NUMPAD2:
    400                         case VK_NUMPAD3:
    401                         case VK_NUMPAD4:
    402                         case VK_NUMPAD5:
    403                         case VK_NUMPAD6:
    404                         case VK_NUMPAD7:
    405                         case VK_NUMPAD8:
    406                         case VK_NUMPAD9:
    407                         case VK_DECIMAL:
    408                                 // numpad keys are saved in their own table
    409                                 m_buttonToNumpadVK[i] = vk;
    410                                 continue;
    411 
    412                         case VK_LWIN:
    413                         case VK_RWIN:
    414                                 // add extended key only for these on 95 family
    415                                 if (m_is95Family) {
    416                                         m_buttonToVK[i | 0x100u] = vk;
    417                                         continue;
    418                                 }
    419                                 break;
    420 
    421                         case VK_RETURN:
    422                         case VK_PRIOR:
    423                         case VK_NEXT:
    424                         case VK_END:
    425                         case VK_HOME:
    426                         case VK_LEFT:
    427                         case VK_UP:
    428                         case VK_RIGHT:
    429                         case VK_DOWN:
    430                         case VK_INSERT:
    431                         case VK_DELETE:
    432                                 // also add extended key for these
    433                                 m_buttonToVK[i | 0x100u] = vk;
    434                                 break;
    435                         }
    436 
    437                         if (m_buttonToVK[i] == 0) {
    438                                 m_buttonToVK[i] = vk;
     388            USHORT usVirtualKey = i;
     389            USHORT fShiftState = 0;
     390                        WinTranslateChar2(0, &usVirtualKey, NULL, TC_SCANCODETOVIRTUALKEY, &fShiftState);
     391                        if (    usVirtualKey != 0
     392                &&  m_buttonToVK[i] == 0) {
     393                m_buttonToVK[i] = usVirtualKey;
    439394                        }
    440395                }
     
    448403                        // skip virtual keys we don't want
    449404                        switch (i) {
    450                         case VK_LBUTTON:
    451                         case VK_RBUTTON:
    452                         case VK_MBUTTON:
    453                         case VK_XBUTTON1:
    454                         case VK_XBUTTON2:
     405                        case VK_BUTTON1:
     406                        case VK_BUTTON2:
     407                        case VK_BUTTON3:
    455408                        case VK_SHIFT:
    456                         case VK_CONTROL:
     409                        case VK_CTRL:
    457410                        case VK_MENU:
    458411                                continue;
     
    460413
    461414                        // get the button
    462                         KeyButton button = static_cast<KeyButton>(MapVirtualKey(i, 0));
    463                         if (button == 0) {
    464                                 continue;
    465                         }
    466 
    467                         // deal with certain virtual keys specially
    468                         switch (i) {
    469                         case VK_NUMPAD0:
    470                         case VK_NUMPAD1:
    471                         case VK_NUMPAD2:
    472                         case VK_NUMPAD3:
    473                         case VK_NUMPAD4:
    474                         case VK_NUMPAD5:
    475                         case VK_NUMPAD6:
    476                         case VK_NUMPAD7:
    477                         case VK_NUMPAD8:
    478                         case VK_NUMPAD9:
    479                         case VK_DECIMAL:
    480                                 m_buttonToNumpadVK[button] = i;
    481                                 break;
    482 
    483                         default:
    484                                 // add extended key if virtual keys don't match
    485                                 if (m_buttonToVK[button] != i) {
    486                                         m_buttonToVK[button | 0x100u] = i;
    487                                 }
    488                                 break;
    489                         }
    490                 }
    491 
    492                 // add alt+printscreen
    493                 if (m_buttonToVK[0x54u] == 0) {
    494                         m_buttonToVK[0x54u] = VK_SNAPSHOT;
    495                 }
     415            USHORT usButton = i;
     416            USHORT fShiftState = 0;
     417            WinTranslateChar2(0, &usButton, NULL, TC_VIRTUALKEYTOSCANCODE, &fShiftState);
     418
     419            // add extended key if virtual keys don't match
     420                        if (    usButton != 0
     421                &&  m_buttonToVK[usButton] != i) {
     422                m_buttonToVK[usButton | 0x100u] = i;
     423                        }
     424                }
     425
     426/// @todo?
     427//              // add alt+printscreen
     428//              if (m_buttonToVK[0x54u] == 0) {
     429//                      m_buttonToVK[0x54u] = VK_SNAPSHOT;
     430//              }
    496431
    497432                // set virtual key to button table
    498                 if (GetKeyboardLayout(0) == m_groups[g]) {
     433//              if (GetKeyboardLayout(0) == m_groups[g]) {
    499434                        for (KeyButton i = 0; i < 512; ++i) {
    500435                                if (m_buttonToVK[i] != 0) {
     
    503438                                        }
    504439                                }
    505                                 if (m_buttonToNumpadVK[i] != 0) {
    506                                         if (m_virtualKeyToButton[m_buttonToNumpadVK[i]] == 0) {
    507                                                 m_virtualKeyToButton[m_buttonToNumpadVK[i]] = i;
    508                                         }
    509                                 }
    510                         }
    511                 }
    512 
    513                 // add numpad keys
    514                 for (KeyButton i = 0; i < 512; ++i) {
    515                         if (m_buttonToNumpadVK[i] != 0) {
    516                                 item.m_id        = getKeyID(m_buttonToNumpadVK[i], i);
    517                                 item.m_button    = i;
    518                                 item.m_required  = KeyModifierNumLock;
    519                                 item.m_sensitive = KeyModifierNumLock | KeyModifierShift;
    520                                 item.m_generates = 0;
    521                                 item.m_client    = m_buttonToNumpadVK[i];
    522                                 addKeyEntry(keyMap, item);
    523                         }
    524                 }
    525 
    526                 // add other keys
     440                        }
     441//              }
     442
     443                // add the keys to the map.
    527444                BYTE keys[256];
    528445                memset(keys, 0, sizeof(keys));
    529446                for (KeyButton i = 0; i < 512; ++i) {
    530                         if (m_buttonToVK[i] != 0) {
     447            USHORT usChar = i;
     448            USHORT fCharShiftState = 0;
     449            USHORT fCharKCFlags = WinTranslateChar2(0, &usChar, NULL, TC_SCANCODETOVIRTUALKEY, &fCharShiftState);
     450                        if (    usChar
     451                ||  m_buttonToVK[i]) {
    531452                                // initialize item
    532453                                item.m_id        = getKeyID(m_buttonToVK[i], i);
     
    534455                                item.m_required  = 0;
    535456                                item.m_sensitive = 0;
    536                                 item.m_client    = m_buttonToVK[i];
     457                                item.m_client    = (m_buttonToVK[i] & 0xff) //  0-7 : virtual key.
     458                                 | (i << 8)                 //  8-15: scancode
     459                                 | (usChar & 0x3fff)        // 16-29: PM char
     460                                 | (0 << 30)                //    30: KC_DEADKEY ??
     461                                 | (0 << 31);               //    31: KC_COMPOSITE ??
    537462
    538463                                // get flags for modifier keys
     
    540465
    541466                                if (item.m_id == 0) {
     467#if 0
    542468                                        // translate virtual key to a character with and without
    543469                                        // shift, caps lock, and AltGr.
     
    551477                                                { VK_SHIFT,   VK_SHIFT,   0x80u, KeyModifierShift    },
    552478                                                { VK_CAPITAL, VK_CAPITAL, 0x01u, KeyModifierCapsLock },
    553                                                 { VK_CONTROL, VK_MENU,    0x80u, KeyModifierControl |
    554                                                                                                                  KeyModifierAlt      }
     479                                                { VK_CONTROL, VK_MENU,    0x80u, KeyModifierControl | KeyModifierAlt }
    555480                                        };
    556                                         static const size_t s_numModifiers =
    557                                                 sizeof(modifiers) / sizeof(modifiers[0]);
     481                                        static const size_t s_numModifiers = sizeof(modifiers) / sizeof(modifiers[0]);
    558482                                        static const size_t s_numCombinations = 1 << s_numModifiers;
    559483                                        KeyID id[s_numCombinations];
     
    572496                                                        }
    573497                                                }
    574                                                 id[j] = getIDForKey(item, button,
    575                                                                                 m_buttonToVK[i], keys, m_groups[g]);
     498                                                id[j] = getIDForKey(item, button, m_buttonToVK[i], keys, m_groups[g]);
    576499                                                if (id[j] != 0) {
    577500                                                        anyFound = true;
     
    607530                                                }
    608531                                        }
    609                                 }
    610                                 else {
    611                                         // found in table
     532#endif
     533                                } else {
     534                                        // found in table - adjust modifiers and add it.
    612535                                        switch (m_buttonToVK[i]) {
    613                                         case VK_TAB:
    614                                                 // add kKeyLeftTab, too
    615                                                 item.m_id         = kKeyLeftTab;
     536                                        case VK_BACKTAB:
    616537                                                item.m_required  |= KeyModifierShift;
    617538                                                item.m_sensitive |= KeyModifierShift;
    618                                                 addKeyEntry(keyMap, item);
    619                                                 item.m_id         = kKeyTab;
    620                                                 item.m_required  &= ~KeyModifierShift;
    621                                                 break;
    622 
    623                                         case VK_CANCEL:
    624                                                 item.m_required  |= KeyModifierControl;
    625                                                 item.m_sensitive |= KeyModifierControl;
    626                                                 break;
    627 
    628                                         case VK_SNAPSHOT:
    629                                                 item.m_sensitive |= KeyModifierAlt;
    630                                                 if ((i & 0x100u) == 0) {
    631                                                         // non-extended snapshot key requires alt
    632                                                         item.m_required |= KeyModifierAlt;
    633                                                 }
    634539                                                break;
    635540                                        }
     
    637542                                }
    638543                        }
    639                 }
    640         }
    641 
     544                } // for buttons 0 thru 511
     545        }
     546
     547#if 0
    642548        // restore keyboard layout
    643549        ActivateKeyboardLayout(activeLayout, 0);
     
    648554CPMKeyState::fakeKey(const Keystroke& keystroke)
    649555{
     556    LOG((CLOG_DEBUG "fakeKey:"));
    650557        switch (keystroke.m_type) {
    651558        case Keystroke::kButton: {
    652                 LOG((CLOG_DEBUG1 "  %03x (%08x) %s%s", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client, 
     559                LOG((CLOG_DEBUG1 "  %03x (%08x) %s%s", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client,
    653560             keystroke.m_data.m_button.m_press ? "down" : "up", keystroke.m_data.m_button.m_repeat ? " repeate" : ""));
    654561                KeyButton button = keystroke.m_data.m_button.m_button;
    655562
    656                 // windows doesn't send key ups for key repeats
     563                // OS/2 doesn't send key ups for key repeats
    657564                if (keystroke.m_data.m_button.m_repeat &&
    658565                        !keystroke.m_data.m_button.m_press) {
    659                         LOG((CLOG_DEBUG1 "  discard key repeat release"));
     566                        LOG((CLOG_DEBUG "  discard key repeat release"));
    660567                        break;
    661568                }
    662569
    663                 // get the virtual key for the button
    664                 ULONG vk = keystroke.m_data.m_button.m_client;
    665 
    666         // synthesize event
    667 #if 0///fixme!
    668                 m_desks->fakeKeyEvent(button, vk,
    669                                                                 keystroke.m_data.m_button.m_press,
    670                                                                 keystroke.m_data.m_button.m_repeat);
    671 #endif
     570                // unpack the m_client packet.
     571                USHORT virtualKey = 0;//keystroke.m_data.m_button.m_client & 0xff;
     572        UCHAR  scanCode = (keystroke.m_data.m_button.m_client >> 8) & 0xff;
     573        USHORT pmChar = 0;//(keystroke.m_data.m_button.m_client >> 16) & 0xff;
     574        bool   fKC_DEADKEY = (keystroke.m_data.m_button.m_client >> 30) & 1;
     575        bool   fKC_COMPOSITE = (keystroke.m_data.m_button.m_client >> 31) & 1;
     576
     577        // synthesize message
     578        HAB hab = CPMUtil::getHAB();/// @todo fix this
     579        QMSG qmsg;
     580        qmsg.hwnd = NULLHANDLE;
     581        qmsg.msg = WM_CHAR;
     582        qmsg.ptl.x = 0;
     583        qmsg.ptl.y = 0;
     584        qmsg.time = WinGetCurrentTime(hab);
     585        qmsg.reserved = 0;
     586
     587        // mp2
     588        if (!keystroke.m_data.m_button.m_press) {
     589            pmChar |= 0x0e00; /// @todo figure out what's going on here...
     590        }
     591        qmsg.mp2 = MPFROM2SHORT(pmChar, virtualKey);
     592
     593        // mp1
     594        USHORT fFlags = 0;
     595        if (!keystroke.m_data.m_button.m_press) {
     596            fFlags |= KC_KEYUP;
     597            /// @todo KC_LONEKEY and KC_TOGGLE, or will PM take care of that?
     598        }
     599        /// @todo check that PM does KC_CTRL, KC_ALT and KC_SHIFT.
     600        /// @todo check that PM does KC_INVALIDCOMP
     601        if (fKC_DEADKEY)    fFlags |= KC_DEADKEY;
     602        if (fKC_COMPOSITE)  fFlags |= KC_COMPOSITE;
     603//        if (virtualKey)     fFlags |= KC_VIRTUALKEY;
     604//        if (keystroke.m_data.m_button.m_press && pmChar)
     605//                            fFlags |= KC_CHAR;
     606        if (scanCode)       fFlags |= KC_SCANCODE;
     607        if (!keystroke.m_data.m_button.m_press && m_lastButton == scanCode)
     608                            fFlags |= KC_LONEKEY;
     609        // PM does: KC_TOGGLE, KC_CTRL, KC_ALT, KC_SHIFT. more?
     610        qmsg.mp1 = MPFROMSH2CH(fFlags, 1, scanCode); /** @todo translate the scan code back to its untranslated form. */
     611
     612        // finaly inject it.
     613        const char *pszError = m_fakeMsg(hab, &qmsg);
     614        if (pszError) {
     615                        LOG((CLOG_ERR " fakeMsg failed to inject msg=%#lx mp1=%#lx mp2=%#lx: %s", qmsg.msg, qmsg.mp1, qmsg.mp2, pszError));
     616        }
     617
     618        // remember the previous key for KC_LONEKEY.
     619        if (keystroke.m_data.m_button.m_press && !keystroke.m_data.m_button.m_repeat)
     620            m_lastButton = scanCode;
    672621                break;
    673622        }
     
    689638                        }
    690639                }
    691 #endif 
     640#endif
    692641                break;
    693642        }
     
    697646CPMKeyState::getActiveModifiersRValue()
    698647{
     648    LOG((CLOG_DEBUG "getActiveModifiersRValue:"));
    699649        if (m_useSavedModifiers) {
    700650                return m_savedModifiers;
    701651        }
    702         else {
    703                 return CKeyState::getActiveModifiersRValue();
    704         }
     652    return CKeyState::getActiveModifiersRValue();
    705653}
    706654
     
    708656CPMKeyState::getKeyID(ULONG virtualKey, KeyButton button)
    709657{
    710         if ((button & 0x100u) != 0) {
    711                 virtualKey += 0x100u;
    712         }
    713         return s_virtualKey[virtualKey];
     658    LOG((CLOG_DEBUG "getKeyID:"));
     659//      if ((button & 0x100u) != 0) {
     660//              virtualKey += 0x100u;
     661//      }
     662//      return s_virtualKey[virtualKey];
     663        return  virtualKey < sizeof(s_virtualKey) / sizeof(s_virtualKey[0])
     664        ?  s_virtualKey[virtualKey]
     665        : kKeyNone;
    714666}
    715667
     
    719671                                PBYTE keyState) const
    720672{
     673    LOG((CLOG_DEBUG "getIDForKey:"));
    721674#if 0
    722675        int n;
     
    750703CPMKeyState::addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item)
    751704{
     705    LOG((CLOG_DEBUG "addKeyEntry:"));
    752706        keyMap.addKeyEntry(item);
    753707        if (item.m_group == 0) {
    754                 m_keyToVKMap[item.m_id] = static_cast<ULONG>(item.m_client);
    755         }
     708                m_keyToVKMap[item.m_id] = item.m_client;
     709    }
    756710}
    757711
  • trunk/synergy/lib/platform/CPMKeyState.h

    r2761 r2765  
    1919#include "CKeyState.h"
    2020#include "CString.h"
     21#include "CPMSynergyHook.h"
    2122#include "stdvector.h"
    2223#define INCL_ERRORS
     
    3435class CPMKeyState : public CKeyState {
    3536public:
    36         CPMKeyState(void* eventTarget);
     37        CPMKeyState(void* eventTarget, FakeMsgFunc fakeMsg);
    3738        virtual ~CPMKeyState();
    3839
     
    153154
    154155private:
    155         typedef std::map<KeyID, ULONG> KeyToVKMap;
    156 
     156        typedef std::map<KeyID, UInt32> KeyToVKMap;
    157157        void*                           m_eventTarget;
    158158        ULONG                           m_buttonToVK[512];
    159         ULONG                           m_buttonToNumpadVK[512];
    160159        KeyButton                       m_virtualKeyToButton[256];
    161160        KeyToVKMap                      m_keyToVKMap;
     161
     162    // function which can inject fake WM_CHAR messages.
     163    FakeMsgFunc                 m_fakeMsg;
     164
     165    // the last button pressed.
     166    KeyButton           m_lastButton;
    162167
    163168        // the timer used to check for fixing key state
  • trunk/synergy/lib/platform/CPMScreen.cpp

    r2764 r2765  
    9696                m_hmodHook = openHookLibrary("synrgyhk");
    9797                m_screensaver = new CPMScreenSaver();
    98                 m_keyState    = new CPMKeyState(getEventTarget());
     98                m_keyState    = new CPMKeyState(getEventTarget(), m_fakeMsg);
    9999                updateScreenShape();
    100100                m_window      = createWindow("Synergy");
  • trunk/synergy/lib/platform/CPMUtil.cpp

    r2761 r2765  
    33 * Copyright (C) 2004 Chris Schoeneman
    44 * Copyright (C) 2006 Knut St. Osmundsen
    5  * 
     5 *
    66 * This package is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU General Public License
    88 * found in the file COPYING that should have accompanied this file.
    9  * 
     9 *
    1010 * This package is distributed in the hope that it will be useful,
    1111 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     
    6767                return result;
    6868        }
    69 #endif 
     69#endif
    7070}
    7171
     
    8383}
    8484
     85
     86/** dynamic resolver */
     87USHORT APIENTRY WinTranslateChar2(USHORT  usCodePage,
     88                                  PUSHORT pusCharInOut,
     89                                  PULONG  pulDeadKeyInfo,
     90                                  WINTCOP enmOperation,
     91                                  PUSHORT pfShiftState)
     92{
     93    static USHORT (* APIENTRY pfnWinTranslateChar2)(USHORT, PUSHORT, PULONG, WINTCOP, PUSHORT) = NULL;
     94    if (!pfnWinTranslateChar2) {
     95        /* resolve it */
     96        HMODULE hmod;
     97        if (    DosLoadModule(NULL, 0, (PCSZ)"PMWIN", &hmod) != NO_ERROR
     98            ||  DosQueryProcAddr(hmod, 1070, NULL, (PPFN)&pfnWinTranslateChar2) != NO_ERROR) {
     99            asm("int3");
     100            *pusCharInOut = 0;
     101            return 0;
     102        }
     103        DosFreeModule(hmod);
     104    }
     105    return pfnWinTranslateChar2(usCodePage, pusCharInOut, pulDeadKeyInfo, enmOperation, pfShiftState);
     106}
     107
  • trunk/synergy/lib/platform/CPMUtil.h

    r2761 r2765  
    33 * Copyright (C) 2004 Chris Schoeneman
    44 * Copyright (C) 2006 Knut St. Osmundsen
    5  * 
     5 *
    66 * This package is free software; you can redistribute it and/or
    77 * modify it under the terms of the GNU General Public License
    88 * found in the file COPYING that should have accompanied this file.
    9  * 
     9 *
    1010 * This package is distributed in the hope that it will be useful,
    1111 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     
    3737        */
    3838        static CString          getErrorString(HMODULE hmod, ULONG error, ULONG id);
    39    
     39
    4040    static HAB          getHAB(void);
    4141    static HMQ          getHMQ(HAB hab = NULLHANDLE);
     
    4343};
    4444
     45
     46/** The WinTranlateChar2 operation. */
     47typedef enum WINTCOP
     48{
     49    TC_CHARTOSCANCODE = 0,
     50    TC_SCANCODETOCHAR,
     51    TC_VIRTUALKEYTOSCANCODE,
     52    TC_SCANCODETOVIRTUALKEY,
     53    TC_SCANTOOEMSCAN,
     54    TC_OEMSCANTOSCAN,
     55    TC_SIZE_HACK = 0x7fff
     56} WINTCOP;
     57
     58/** @name WinTranslateChar2 shift state.
     59 * This state goes with scancode input/output.
     60 * @{ */
     61#define TCF_LSHIFT          0x1
     62#define TCF_RSHIFT          0x2
     63#define TCF_SHIFT           (TCF_LSHIFT | TCF_RSHIFT)
     64#define TCF_LCONTROL        0x4
     65#define TCF_RCONTROL        0x8
     66#define TCF_CONTROL         (TCF_LCONTROL | TCF_RCONTROL)
     67#define TCF_ALT             0x10
     68#define TCF_ALTGR           0x20
     69#define TCF_CAPSLOCK        0x40
     70#define TCF_NUMLOCK         0x80
     71#define TCF_MAX_BITS        8       /**< bits 0-7 are real shift states */
     72#define TCF_OEMSCANCODE     0x100
     73#define TCF_EXTENDEDKEY     0x200
     74/** @} */
     75
     76/**
     77 * Char to/from keyboard code translator.
     78 *
     79 * @returns A combination of some of the KC_* values.
     80 * @param   usCodePage          The code page. Anything goes, apparently ignored.
     81 * @param   pusCharInOut        Where to get the char/code to be translated and to
     82 *                              put the output upon return.
     83 * @param   pulDeadKeyInfo      Previous, dead key.
     84 * @param   enmOperation        The kind of translation.
     85 * @param   pfShiftState        Where to read/store the shift state. Used when
     86 *                              translating from/to scancodes.
     87 * @remark  PMWIN.1070
     88 */
     89extern "C"
     90USHORT APIENTRY WinTranslateChar2(USHORT  usCodePage,
     91                                  PUSHORT pusCharInOut,
     92                                  PULONG  pulDeadKeyInfo,
     93                                  WINTCOP enmOperation,
     94                                  PUSHORT pfShiftState);
     95
    4596#endif
     97
Note: See TracChangeset for help on using the changeset viewer.