Ignore:
Timestamp:
Aug 13, 2006, 1:41:05 AM (19 years ago)
Author:
bird
Message:

Hacking and debugging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/lib/platform/CPMKeyState.cpp

    r2755 r2761  
    181181        // extract character, virtual key, and if we didn't use AltGr
    182182        char c       = (char)((charAndVirtKey & 0xff00u) >> 8);
    183         UINT vkCode = (charAndVirtKey & 0xffu);
     183        ULONG vkCode = (charAndVirtKey & 0xffu);
    184184        bool noAltGr = ((charAndVirtKey & 0xff0000u) != 0);
    185185
     
    240240
    241241void
    242 CPMKeyState::onKey(KeyButton button, bool down, KeyModifierMask newState)
    243 {
    244         // handle win32 brokenness and forward to superclass
    245         fixKeys();
    246         CKeyState::onKey(button, down, newState);
    247         fixKeys();
    248 }
    249 
    250 void
    251242CPMKeyState::sendKeyEvent(void* target,
    252243                                                        bool press, bool isAutoRepeat,
     
    316307CPMKeyState::pollActiveGroup() const
    317308{
    318         // determine the thread that'll receive this event
    319         HWND  targetWindow = GetForegroundWindow();
    320         ULONG targetThread = GetWindowThreadProcessId(targetWindow, NULL);
    321 
    322         // get keyboard layout for the thread
     309#if 0
    323310        HKL hkl            = GetKeyboardLayout(targetThread);
    324311
     
    331318
    332319        return i->second;
     320#else
     321    return 0;
     322#endif
    333323}
    334324
     
    337327{
    338328        BYTE keyState[256];
    339         GetKeyboardState(keyState);
    340         for (KeyButton i = 1; i < 256; ++i) {
    341                 if ((keyState[i] & 0x80) != 0) {
    342                         pressedKeys.insert(i);
    343                 }
    344         }
     329    if (WinSetKeyboardStateTable(HWND_DESKTOP, keyState, FALSE)) {
     330        for (KeyButton i = 1; i < 256; ++i) {
     331                if ((keyState[i] & 0x80) != 0) {
     332                        pressedKeys.insert(i);
     333                }
     334        }
     335    }
    345336}
    346337
     
    348339CPMKeyState::getKeyMap(CKeyMap& keyMap)
    349340{
     341#if 0
    350342        // update keyboard groups
    351343        if (getGroups(m_groups)) {
     
    374366                // map buttons (scancodes) to virtual keys
    375367                for (KeyButton i = 1; i < 256; ++i) {
    376                         UINT vk = MapVirtualKey(i, 1);
     368                        ULONG vk = MapVirtualKey(i, 1);
    377369                        if (vk == 0) {
    378370                                // unmapped
     
    453445                // either a numpad key and we use the button as is or it's an
    454446                // extended button.
    455                 for (UINT i = 1; i < 255; ++i) {
     447                for (ULONG i = 1; i < 255; ++i) {
    456448                        // skip virtual keys we don't want
    457449                        switch (i) {
     
    551543                                        // shift, caps lock, and AltGr.
    552544                                        struct Modifier {
    553                                                 UINT                    m_vk1;
    554                                                 UINT                    m_vk2;
     545                                                ULONG                   m_vk1;
     546                                                ULONG                   m_vk2;
    555547                                                BYTE                    m_state;
    556548                                                KeyModifierMask m_mask;
     
    650642        // restore keyboard layout
    651643        ActivateKeyboardLayout(activeLayout, 0);
     644#endif
    652645}
    653646
     
    668661
    669662                // get the virtual key for the button
    670                 UINT vk = keystroke.m_data.m_button.m_client;
    671 
    672                 // special handling of VK_SNAPSHOT
    673                 if (vk == VK_SNAPSHOT) {
    674                         if ((getActiveModifiers() & KeyModifierAlt) != 0) {
    675                                 // snapshot active window
    676                                 button = 1;
    677                         }
    678                         else {
    679                                 // snapshot full screen
    680                                 button = 0;
    681                         }
    682                 }
    683 
    684                 // synthesize event
     663                ULONG vk = keystroke.m_data.m_button.m_client;
     664
     665        // synthesize event
     666#if 0///fixme!
    685667                m_desks->fakeKeyEvent(button, vk,
    686668                                                                keystroke.m_data.m_button.m_press,
    687669                                                                keystroke.m_data.m_button.m_repeat);
     670#endif
    688671                break;
    689672        }
    690673
    691674        case Keystroke::kGroup:
     675#if 0
    692676                // we don't restore the group.  we'd like to but we can't be
    693677                // sure the restoring group change will be processed after the
     
    704688                        }
    705689                }
     690#endif
    706691                break;
    707692        }
     
    719704}
    720705
    721 void
    722 CPMKeyState::fixKeys()
    723 {
    724         // fake key releases for the windows keys if we think they're
    725         // down but they're really up.  we have to do this because if the
    726         // user presses and releases a windows key without pressing any
    727         // other key while it's down then the system will eat the key
    728         // release.  if we don't detect that and synthesize the release
    729         // then the client won't take the usual windows key release action
    730         // (which on windows is to show the start menu).
    731         //
    732         // only check on the windows 95 family since the NT family reports
    733         // the key releases as usual.
    734         if (!m_is95Family) {
    735                 return;
    736         }
    737 
    738         KeyButton leftButton  = virtualKeyToButton(VK_LWIN);
    739         KeyButton rightButton = virtualKeyToButton(VK_RWIN);
    740         bool leftDown         = isKeyDown(leftButton);
    741         bool rightDown        = isKeyDown(rightButton);
    742         bool fix              = (leftDown || rightDown);
    743         if (fix) {
    744                 // check if either button is not really down
    745                 bool leftAsyncDown  = ((GetAsyncKeyState(VK_LWIN) & 0x8000) != 0);
    746                 bool rightAsyncDown = ((GetAsyncKeyState(VK_RWIN) & 0x8000) != 0);
    747 
    748                 if (leftAsyncDown != leftDown || rightAsyncDown != rightDown) {
    749                         KeyModifierMask state = getActiveModifiers();
    750                         if (!leftAsyncDown && !rightAsyncDown) {
    751                                 // no win keys are down so remove super modifier
    752                                 state &= ~KeyModifierSuper;
    753                         }
    754 
    755                         // report up events
    756                         if (leftDown  && !leftAsyncDown) {
    757                                 LOG((CLOG_DEBUG1 "event: fake key release left windows key (0x%03x)", leftButton));
    758                                 CKeyState::onKey(leftButton, false, state);
    759                                 CKeyState::sendKeyEvent(m_eventTarget, false, false, kKeySuper_L, state, 1, leftButton);
    760                         }
    761                         if (rightDown && !rightAsyncDown) {
    762                                 LOG((CLOG_DEBUG1 "event: fake key release right windows key (0x%03x)", rightButton));
    763                                 CKeyState::onKey(rightButton, false, state);
    764                                 CKeyState::sendKeyEvent(m_eventTarget, false, false, kKeySuper_R, state, 1, rightButton);
    765                         }
    766                 }
    767         }
    768 
    769         if (fix && m_fixTimer == NULL) {
    770                 // schedule check
    771                 m_fixTimer = EVENTQUEUE->newTimer(0.1, NULL);
    772                 EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
    773                                                         new TMethodEventJob<CPMKeyState>(
    774                                                                 this, &CPMKeyState::handleFixKeys));
    775         }
    776         else if (!fix && m_fixTimer != NULL) {
    777                 // remove scheduled check
    778                 EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);
    779                 EVENTQUEUE->deleteTimer(m_fixTimer);
    780                 m_fixTimer = NULL;
    781         }
    782 }
    783 
    784 void
    785 CPMKeyState::handleFixKeys(const CEvent&, void*)
    786 {
    787         fixKeys();
    788 }
    789 
    790706KeyID
    791 CPMKeyState::getKeyID(UINT virtualKey, KeyButton button)
     707CPMKeyState::getKeyID(ULONG virtualKey, KeyButton button)
    792708{
    793709        if ((button & 0x100u) != 0) {
     
    799715KeyID
    800716CPMKeyState::getIDForKey(CKeyMap::KeyItem& item,
    801                                 KeyButton button, UINT virtualKey,
    802                                 PBYTE keyState, HKL hkl) const
    803 {
     717                                KeyButton button, ULONG virtualKey,
     718                                PBYTE keyState) const
     719{
     720#if 0
    804721        int n;
    805722        KeyID id;
    806         if (m_is95Family) {
    807                 // XXX -- how do we get characters not in Latin-1?
    808                 WORD ascii;
    809                 n  = ToAsciiEx(virtualKey, button, keyState, &ascii, 0, hkl);
    810                 id = static_cast<KeyID>(ascii & 0xffu);
    811         }
    812         else {
    813                 WCHAR unicode[2];
    814                 n  = m_ToUnicodeEx(virtualKey, button, keyState,
    815                                                                 unicode, sizeof(unicode) / sizeof(unicode[0]),
    816                                                                 0, hkl);
    817                 id = static_cast<KeyID>(unicode[0]);
    818         }
     723    WORD ascii;
     724    n  = ToAsciiEx(virtualKey, button, keyState, &ascii, 0, hkl);
     725    id = static_cast<KeyID>(ascii & 0xffu);
    819726        switch (n) {
    820727        case -1:
     
    833740                return getIDForKey(item, button, virtualKey, keyState, hkl);
    834741        }
     742#else
     743    //fixme!
     744    return 0;
     745#endif
    835746}
    836747
     
    840751        keyMap.addKeyEntry(item);
    841752        if (item.m_group == 0) {
    842                 m_keyToVKMap[item.m_id] = static_cast<UINT>(item.m_client);
     753                m_keyToVKMap[item.m_id] = static_cast<ULONG>(item.m_client);
    843754        }
    844755}
Note: See TracChangeset for help on using the changeset viewer.