• Main Page
  • Classes
  • Files
  • File List

CKeyState.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2004 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef CKEYSTATE_H
00020 #define CKEYSTATE_H
00021 
00022 #include "IKeyState.h"
00023 #include "CKeyMap.h"
00024 
00026 
00030 class CKeyState : public IKeyState {
00031 public:
00032     CKeyState();
00033     CKeyState(IEventQueue& eventQueue, CKeyMap& keyMap);
00034     virtual ~CKeyState();
00035 
00037 
00038 
00040 
00046     virtual void        onKey(KeyButton button, bool down,
00047                             KeyModifierMask newState);
00048 
00050 
00055     virtual void        sendKeyEvent(void* target,
00056                             bool press, bool isAutoRepeat,
00057                             KeyID key, KeyModifierMask mask,
00058                             SInt32 count, KeyButton button);
00059 
00061 
00062 
00063 
00065 
00066     // IKeyState overrides
00067     virtual void        updateKeyMap();
00068     virtual void        updateKeyState();
00069     virtual void        setHalfDuplexMask(KeyModifierMask);
00070     virtual void        fakeKeyDown(KeyID id, KeyModifierMask mask,
00071                             KeyButton button);
00072     virtual bool        fakeKeyRepeat(KeyID id, KeyModifierMask mask,
00073                             SInt32 count, KeyButton button);
00074     virtual bool        fakeKeyUp(KeyButton button);
00075     virtual void        fakeAllKeysUp();
00076     virtual bool        fakeCtrlAltDel() = 0;
00077     virtual bool        isKeyDown(KeyButton) const;
00078     virtual KeyModifierMask
00079                         getActiveModifiers() const;
00080     virtual KeyModifierMask
00081                         pollActiveModifiers() const = 0;
00082     virtual SInt32      pollActiveGroup() const = 0;
00083     virtual void        pollPressedKeys(KeyButtonSet& pressedKeys) const = 0;
00084 
00085     SInt32 getKeyState(KeyButton keyButton) { return m_keys[keyButton]; }
00086 
00087 protected:
00088     typedef CKeyMap::Keystroke Keystroke;
00089 
00091 
00092 
00094 
00097     virtual void        getKeyMap(CKeyMap& keyMap) = 0;
00098 
00100 
00103     virtual void        fakeKey(const Keystroke& keystroke) = 0;
00104 
00106 
00110     virtual KeyModifierMask&
00111                         getActiveModifiersRValue();
00112 
00114 
00115 
00116 
00118 
00121     SInt32              getEffectiveGroup(SInt32 group, SInt32 offset) const;
00122 
00124 
00128     virtual bool        isIgnoredKey(KeyID key, KeyModifierMask mask) const;
00129 
00131 
00135     KeyButton           getButton(KeyID id, SInt32 group) const;
00136 
00138 
00139 private:
00140     typedef CKeyMap::Keystrokes Keystrokes;
00141     typedef CKeyMap::ModifierToKeys ModifierToKeys;
00142 public:
00143     struct CAddActiveModifierContext {
00144     public:
00145         CAddActiveModifierContext(SInt32 group, KeyModifierMask mask,
00146                             ModifierToKeys& activeModifiers);
00147 
00148     public:
00149         SInt32          m_activeGroup;
00150         KeyModifierMask m_mask;
00151         ModifierToKeys& m_activeModifiers;
00152 
00153     private:
00154         // not implemented
00155         CAddActiveModifierContext(const CAddActiveModifierContext&);
00156         CAddActiveModifierContext& operator=(const CAddActiveModifierContext&);
00157     };
00158 private:
00159     
00160     class ButtonToKeyLess {
00161     public:
00162         bool operator()(const CKeyMap::ButtonToKeyMap::value_type& a,
00163                         const CKeyMap::ButtonToKeyMap::value_type b) const
00164         {
00165             return (a.first < b.first);
00166         }
00167     };
00168 
00169     // not implemented
00170     CKeyState(const CKeyState&);
00171     CKeyState& operator=(const CKeyState&);
00172 
00173     // called by all ctors.
00174     void                init();
00175 
00176     // adds alias key sequences.  these are sequences that are equivalent
00177     // to other sequences.
00178     void                addAliasEntries();
00179 
00180     // adds non-keypad key sequences for keypad KeyIDs
00181     void                addKeypadEntries();
00182 
00183     // adds key sequences for combination KeyIDs (those built using
00184     // dead keys)
00185     void                addCombinationEntries();
00186 
00187     // synthesize key events.  synthesize auto-repeat events count times.
00188     void                fakeKeys(const Keystrokes&, UInt32 count);
00189 
00190     // update key state to match changes to modifiers
00191     void                updateModifierKeyState(KeyButton button,
00192                             const ModifierToKeys& oldModifiers,
00193                             const ModifierToKeys& newModifiers);
00194 
00195     // active modifiers collection callback
00196     static void         addActiveModifierCB(KeyID id, SInt32 group,
00197                             CKeyMap::KeyItem& keyItem, void* vcontext);
00198 
00199 private:
00200     // must be declared before m_keyMap. used when this class owns the key map.
00201     CKeyMap*            m_keyMapPtr;
00202 
00203     // the keyboard map
00204     CKeyMap&            m_keyMap;
00205 
00206     // current modifier state
00207     KeyModifierMask     m_mask;
00208 
00209     // the active modifiers and the buttons activating them
00210     ModifierToKeys      m_activeModifiers;
00211 
00212     // current keyboard state (> 0 if pressed, 0 otherwise).  this is
00213     // initialized to the keyboard state according to the system then
00214     // it tracks synthesized events.
00215     SInt32              m_keys[kNumButtons];
00216 
00217     // synthetic keyboard state (> 0 if pressed, 0 otherwise).  this
00218     // tracks the synthesized keyboard state.  if m_keys[n] > 0 but
00219     // m_syntheticKeys[n] == 0 then the key was pressed locally and
00220     // not synthesized yet.
00221     SInt32              m_syntheticKeys[kNumButtons];
00222 
00223     // client data for each pressed key
00224     UInt32              m_keyClientData[kNumButtons];
00225 
00226     // server keyboard state.  an entry is 0 if not the key isn't pressed
00227     // otherwise it's the local KeyButton synthesized for the server key.
00228     KeyButton           m_serverKeys[kNumButtons];
00229 };
00230 
00231 #endif

Generated on Wed May 22 2013 00:00:05 for Synergy by  doxygen 1.7.1