Changeset 2761 for trunk/synergy/lib/platform/CPMKeyState.cpp
- Timestamp:
- Aug 13, 2006, 1:41:05 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/synergy/lib/platform/CPMKeyState.cpp
r2755 r2761 181 181 // extract character, virtual key, and if we didn't use AltGr 182 182 char c = (char)((charAndVirtKey & 0xff00u) >> 8); 183 U INT vkCode= (charAndVirtKey & 0xffu);183 ULONG vkCode = (charAndVirtKey & 0xffu); 184 184 bool noAltGr = ((charAndVirtKey & 0xff0000u) != 0); 185 185 … … 240 240 241 241 void 242 CPMKeyState::onKey(KeyButton button, bool down, KeyModifierMask newState)243 {244 // handle win32 brokenness and forward to superclass245 fixKeys();246 CKeyState::onKey(button, down, newState);247 fixKeys();248 }249 250 void251 242 CPMKeyState::sendKeyEvent(void* target, 252 243 bool press, bool isAutoRepeat, … … 316 307 CPMKeyState::pollActiveGroup() const 317 308 { 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 323 310 HKL hkl = GetKeyboardLayout(targetThread); 324 311 … … 331 318 332 319 return i->second; 320 #else 321 return 0; 322 #endif 333 323 } 334 324 … … 337 327 { 338 328 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 } 345 336 } 346 337 … … 348 339 CPMKeyState::getKeyMap(CKeyMap& keyMap) 349 340 { 341 #if 0 350 342 // update keyboard groups 351 343 if (getGroups(m_groups)) { … … 374 366 // map buttons (scancodes) to virtual keys 375 367 for (KeyButton i = 1; i < 256; ++i) { 376 U INTvk = MapVirtualKey(i, 1);368 ULONG vk = MapVirtualKey(i, 1); 377 369 if (vk == 0) { 378 370 // unmapped … … 453 445 // either a numpad key and we use the button as is or it's an 454 446 // extended button. 455 for (U INTi = 1; i < 255; ++i) {447 for (ULONG i = 1; i < 255; ++i) { 456 448 // skip virtual keys we don't want 457 449 switch (i) { … … 551 543 // shift, caps lock, and AltGr. 552 544 struct Modifier { 553 U INTm_vk1;554 U INTm_vk2;545 ULONG m_vk1; 546 ULONG m_vk2; 555 547 BYTE m_state; 556 548 KeyModifierMask m_mask; … … 650 642 // restore keyboard layout 651 643 ActivateKeyboardLayout(activeLayout, 0); 644 #endif 652 645 } 653 646 … … 668 661 669 662 // 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! 685 667 m_desks->fakeKeyEvent(button, vk, 686 668 keystroke.m_data.m_button.m_press, 687 669 keystroke.m_data.m_button.m_repeat); 670 #endif 688 671 break; 689 672 } 690 673 691 674 case Keystroke::kGroup: 675 #if 0 692 676 // we don't restore the group. we'd like to but we can't be 693 677 // sure the restoring group change will be processed after the … … 704 688 } 705 689 } 690 #endif 706 691 break; 707 692 } … … 719 704 } 720 705 721 void722 CPMKeyState::fixKeys()723 {724 // fake key releases for the windows keys if we think they're725 // down but they're really up. we have to do this because if the726 // user presses and releases a windows key without pressing any727 // other key while it's down then the system will eat the key728 // release. if we don't detect that and synthesize the release729 // then the client won't take the usual windows key release action730 // (which on windows is to show the start menu).731 //732 // only check on the windows 95 family since the NT family reports733 // 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 down745 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 modifier752 state &= ~KeyModifierSuper;753 }754 755 // report up events756 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 check771 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 check778 EVENTQUEUE->removeHandler(CEvent::kTimer, m_fixTimer);779 EVENTQUEUE->deleteTimer(m_fixTimer);780 m_fixTimer = NULL;781 }782 }783 784 void785 CPMKeyState::handleFixKeys(const CEvent&, void*)786 {787 fixKeys();788 }789 790 706 KeyID 791 CPMKeyState::getKeyID(U INTvirtualKey, KeyButton button)707 CPMKeyState::getKeyID(ULONG virtualKey, KeyButton button) 792 708 { 793 709 if ((button & 0x100u) != 0) { … … 799 715 KeyID 800 716 CPMKeyState::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 804 721 int n; 805 722 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); 819 726 switch (n) { 820 727 case -1: … … 833 740 return getIDForKey(item, button, virtualKey, keyState, hkl); 834 741 } 742 #else 743 //fixme! 744 return 0; 745 #endif 835 746 } 836 747 … … 840 751 keyMap.addKeyEntry(item); 841 752 if (item.m_group == 0) { 842 m_keyToVKMap[item.m_id] = static_cast<U INT>(item.m_client);753 m_keyToVKMap[item.m_id] = static_cast<ULONG>(item.m_client); 843 754 } 844 755 }
Note:
See TracChangeset
for help on using the changeset viewer.