Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

CMSWindowsKeyState.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2003 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef CMSWINDOWSKEYSTATE_H
00016 #define CMSWINDOWSKEYSTATE_H
00017 
00018 #include "CKeyState.h"
00019 #include "CString.h"
00020 #include "stdvector.h"
00021 #define WIN32_LEAN_AND_MEAN
00022 #include <windows.h>
00023 
00024 class CEvent;
00025 class CEventQueueTimer;
00026 class CMSWindowsDesks;
00027 
00029 
00032 class CMSWindowsKeyState : public CKeyState {
00033 public:
00034     CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget);
00035     virtual ~CMSWindowsKeyState();
00036 
00038 
00039 
00041 
00045     void                disable();
00046 
00048 
00051     void                setKeyLayout(HKL keyLayout);
00052 
00054 
00058     bool                testAutoRepeat(bool press, bool isRepeat, KeyButton);
00059 
00061 
00064     void                saveModifiers();
00065 
00067 
00079     void                useSavedModifiers(bool enable);
00080 
00082 
00083 
00084 
00086 
00089     KeyButton           virtualKeyToButton(UINT virtualKey) const;
00090 
00092 
00096     KeyID               mapKeyFromEvent(WPARAM charAndVirtKey,
00097                             LPARAM info, KeyModifierMask* maskOut) const;
00098 
00100 
00104     bool                didGroupsChange() const;
00105 
00107 
00111     UINT                mapKeyToVirtualKey(KeyID key) const;
00112 
00114 
00119     static KeyID        getKeyID(UINT virtualKey, KeyButton button);
00120 
00122 
00123     // IKeyState overrides
00124     virtual void        fakeKeyDown(KeyID id, KeyModifierMask mask,
00125                             KeyButton button);
00126     virtual void        fakeKeyRepeat(KeyID id, KeyModifierMask mask,
00127                             SInt32 count, KeyButton button);
00128     virtual bool        fakeCtrlAltDel();
00129     virtual KeyModifierMask
00130                         pollActiveModifiers() const;
00131     virtual SInt32      pollActiveGroup() const;
00132     virtual void        pollPressedKeys(KeyButtonSet& pressedKeys) const;
00133 
00134     // CKeyState overrides
00135     virtual void        onKey(KeyButton button, bool down,
00136                             KeyModifierMask newState);
00137     virtual void        sendKeyEvent(void* target,
00138                             bool press, bool isAutoRepeat,
00139                             KeyID key, KeyModifierMask mask,
00140                             SInt32 count, KeyButton button);
00141 
00142 protected:
00143     // CKeyState overrides
00144     virtual void        getKeyMap(CKeyMap& keyMap);
00145     virtual void        fakeKey(const Keystroke& keystroke);
00146     virtual KeyModifierMask&
00147                         getActiveModifiersRValue();
00148 
00149 private:
00150     typedef std::vector<HKL> GroupList;
00151 
00152     // send ctrl+alt+del hotkey event on NT family
00153     static void         ctrlAltDelThread(void*);
00154 
00155     bool                getGroups(GroupList&) const;
00156     void                setWindowGroup(SInt32 group);
00157 
00158     void                fixKeys();
00159     void                handleFixKeys(const CEvent&, void*);
00160 
00161     KeyID               getIDForKey(CKeyMap::KeyItem& item,
00162                             KeyButton button, UINT virtualKey,
00163                             PBYTE keyState, HKL hkl) const;
00164 
00165     void                addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item);
00166 
00167 private:
00168     // not implemented
00169     CMSWindowsKeyState(const CMSWindowsKeyState&);
00170     CMSWindowsKeyState& operator=(const CMSWindowsKeyState&);
00171 
00172 private:
00173     typedef std::map<HKL, SInt32> GroupMap;
00174     typedef std::map<KeyID, UINT> KeyToVKMap;
00175 
00176     bool                m_is95Family;
00177     void*               m_eventTarget;
00178     CMSWindowsDesks*    m_desks;
00179     HKL                 m_keyLayout;
00180     UINT                m_buttonToVK[512];
00181     UINT                m_buttonToNumpadVK[512];
00182     KeyButton           m_virtualKeyToButton[256];
00183     KeyToVKMap          m_keyToVKMap;
00184 
00185     // the timer used to check for fixing key state
00186     CEventQueueTimer*   m_fixTimer;
00187 
00188     // the groups (keyboard layouts)
00189     GroupList           m_groups;
00190     GroupMap            m_groupMap;
00191 
00192     // the last button that we generated a key down event for.  this
00193     // is zero if the last key event was a key up.  we use this to
00194     // synthesize key repeats since the low level keyboard hook can't
00195     // tell us if an event is a key repeat.
00196     KeyButton           m_lastDown;
00197 
00198     // modifier tracking
00199     bool                m_useSavedModifiers;
00200     KeyModifierMask     m_savedModifiers;
00201     KeyModifierMask     m_originalSavedModifiers;
00202 
00203     // pointer to ToUnicodeEx.  on win95 family this will be NULL.
00204     typedef int (WINAPI *ToUnicodeEx_t)(UINT wVirtKey,
00205                                         UINT wScanCode,
00206                                         PBYTE lpKeyState,
00207                                         LPWSTR pwszBuff,
00208                                         int cchBuff,
00209                                         UINT wFlags,
00210                                         HKL dwhkl);
00211     ToUnicodeEx_t       m_ToUnicodeEx;
00212 
00213     static const KeyID  s_virtualKey[];
00214 };
00215 
00216 #endif

Generated on Fri Nov 6 00:21:14 2009 for synergy-plus by  doxygen 1.3.9.1