source: trunk/synergy/lib/platform/CMSWindowsKeyState.h

Last change on this file was 2765, checked in by bird, 19 years ago

hacking on keyboard stuff.

File size: 6.0 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2003 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef CMSWINDOWSKEYSTATE_H
16#define CMSWINDOWSKEYSTATE_H
17
18#include "CKeyState.h"
19#include "CString.h"
20#include "stdvector.h"
21#define WIN32_LEAN_AND_MEAN
22#include <windows.h>
23
24class CEvent;
25class CEventQueueTimer;
26class CMSWindowsDesks;
27
28//! Microsoft Windows key mapper
29/*!
30This class maps KeyIDs to keystrokes.
31*/
32class CMSWindowsKeyState : public CKeyState {
33public:
34 CMSWindowsKeyState(CMSWindowsDesks* desks, void* eventTarget);
35 virtual ~CMSWindowsKeyState();
36
37 //! @name manipulators
38 //@{
39
40 //! Handle screen disabling
41 /*!
42 Called when screen is disabled. This is needed to deal with platform
43 brokenness.
44 */
45 void disable();
46
47 //! Set the active keyboard layout
48 /*!
49 Uses \p keyLayout when querying the keyboard.
50 */
51 void setKeyLayout(HKL keyLayout);
52
53 //! Test and set autorepeat state
54 /*!
55 Returns true if the given button is autorepeating and updates internal
56 state.
57 */
58 bool testAutoRepeat(bool press, bool isRepeat, KeyButton);
59
60 //! Remember modifier state
61 /*!
62 Records the current non-toggle modifier state.
63 */
64 void saveModifiers();
65
66 //! Set effective modifier state
67 /*!
68 Temporarily sets the non-toggle modifier state to those saved by the
69 last call to \c saveModifiers if \p enable is \c true. Restores the
70 modifier state to the current modifier state if \p enable is \c false.
71 This is for synthesizing keystrokes on the primary screen when the
72 cursor is on a secondary screen. When on a secondary screen we capture
73 all non-toggle modifier state, track the state internally and do not
74 pass it on. So if Alt+F1 synthesizes Alt+X we need to synthesize
75 not just X but also Alt, despite the fact that our internal modifier
76 state indicates Alt is down, because local apps never saw the Alt down
77 event.
78 */
79 void useSavedModifiers(bool enable);
80
81 //@}
82 //! @name accessors
83 //@{
84
85 //! Map a virtual key to a button
86 /*!
87 Returns the button for the \p virtualKey.
88 */
89 KeyButton virtualKeyToButton(UINT virtualKey) const;
90
91 //! Map key event to a key
92 /*!
93 Converts a key event into a KeyID and the shadow modifier state
94 to a modifier mask.
95 */
96 KeyID mapKeyFromEvent(WPARAM charAndVirtKey,
97 LPARAM info, KeyModifierMask* maskOut) const;
98
99 //! Check if keyboard groups have changed
100 /*!
101 Returns true iff the number or order of the keyboard groups have
102 changed since the last call to updateKeys().
103 */
104 bool didGroupsChange() const;
105
106 //! Map key to virtual key
107 /*!
108 Returns the virtual key for key \p key or 0 if there's no such virtual
109 key.
110 */
111 UINT mapKeyToVirtualKey(KeyID key) const;
112
113 //! Map virtual key and button to KeyID
114 /*!
115 Returns the KeyID for virtual key \p virtualKey and button \p button
116 (button should include the extended key bit), or kKeyNone if there is
117 no such key.
118 */
119 static KeyID getKeyID(UINT virtualKey, KeyButton button);
120
121 //@}
122
123 // IKeyState overrides
124 virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
125 KeyButton button);
126 virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
127 SInt32 count, KeyButton button);
128 virtual bool fakeCtrlAltDel();
129 virtual KeyModifierMask
130 pollActiveModifiers() const;
131 virtual SInt32 pollActiveGroup() const;
132 virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
133
134 // CKeyState overrides
135 virtual void onKey(KeyButton button, bool down,
136 KeyModifierMask newState);
137 virtual void sendKeyEvent(void* target,
138 bool press, bool isAutoRepeat,
139 KeyID key, KeyModifierMask mask,
140 SInt32 count, KeyButton button);
141
142protected:
143 // CKeyState overrides
144 virtual void getKeyMap(CKeyMap& keyMap);
145 virtual void fakeKey(const Keystroke& keystroke);
146 virtual KeyModifierMask&
147 getActiveModifiersRValue();
148
149private:
150 typedef std::vector<HKL> GroupList;
151
152 // send ctrl+alt+del hotkey event on NT family
153 static void ctrlAltDelThread(void*);
154
155 bool getGroups(GroupList&) const;
156 void setWindowGroup(SInt32 group);
157
158 void fixKeys();
159 void handleFixKeys(const CEvent&, void*);
160
161 KeyID getIDForKey(CKeyMap::KeyItem& item,
162 KeyButton button, UINT virtualKey,
163 PBYTE keyState, HKL hkl) const;
164
165 void addKeyEntry(CKeyMap& keyMap, CKeyMap::KeyItem& item);
166
167private:
168 // not implemented
169 CMSWindowsKeyState(const CMSWindowsKeyState&);
170 CMSWindowsKeyState& operator=(const CMSWindowsKeyState&);
171
172private:
173 typedef std::map<HKL, SInt32> GroupMap;
174 typedef std::map<KeyID, UINT> KeyToVKMap;
175
176 bool m_is95Family;
177 void* m_eventTarget;
178 CMSWindowsDesks* m_desks;
179 HKL m_keyLayout;
180 UINT m_buttonToVK[512];
181 UINT m_buttonToNumpadVK[512];
182 KeyButton m_virtualKeyToButton[256];
183 KeyToVKMap m_keyToVKMap;
184
185 // the timer used to check for fixing key state
186 CEventQueueTimer* m_fixTimer;
187
188#if 0
189 // the groups (keyboard layouts)
190 GroupList m_groups;
191 GroupMap m_groupMap;
192#endif
193
194 // the last button that we generated a key down event for. this
195 // is zero if the last key event was a key up. we use this to
196 // synthesize key repeats since the low level keyboard hook can't
197 // tell us if an event is a key repeat.
198 KeyButton m_lastDown;
199
200 // modifier tracking
201 bool m_useSavedModifiers;
202 KeyModifierMask m_savedModifiers;
203 KeyModifierMask m_originalSavedModifiers;
204
205 // pointer to ToUnicodeEx. on win95 family this will be NULL.
206 typedef int (WINAPI *ToUnicodeEx_t)(UINT wVirtKey,
207 UINT wScanCode,
208 PBYTE lpKeyState,
209 LPWSTR pwszBuff,
210 int cchBuff,
211 UINT wFlags,
212 HKL dwhkl);
213 ToUnicodeEx_t m_ToUnicodeEx;
214
215 static const KeyID s_virtualKey[];
216};
217
218#endif
Note: See TracBrowser for help on using the repository browser.