00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
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
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
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
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
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
00186 CEventQueueTimer* m_fixTimer;
00187
00188
00189 GroupList m_groups;
00190 GroupMap m_groupMap;
00191
00192
00193
00194
00195
00196 KeyButton m_lastDown;
00197
00198
00199 bool m_useSavedModifiers;
00200 KeyModifierMask m_savedModifiers;
00201 KeyModifierMask m_originalSavedModifiers;
00202
00203
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