2004-04-11 14:58:08 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2004 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COSXKEYSTATE_H
|
|
|
|
#define COSXKEYSTATE_H
|
|
|
|
|
|
|
|
#include "CKeyState.h"
|
|
|
|
#include "stdmap.h"
|
2004-11-12 15:50:04 +00:00
|
|
|
#include "stdset.h"
|
2004-10-24 18:15:33 +00:00
|
|
|
#include "stdvector.h"
|
2004-04-11 14:58:08 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
|
|
|
//! OS X key state
|
|
|
|
/*!
|
|
|
|
A key state for OS X.
|
|
|
|
*/
|
|
|
|
class COSXKeyState : public CKeyState {
|
|
|
|
public:
|
2004-10-24 18:15:33 +00:00
|
|
|
typedef std::vector<KeyID> CKeyIDs;
|
2004-08-04 22:48:08 +00:00
|
|
|
|
2004-04-11 14:58:08 +00:00
|
|
|
COSXKeyState();
|
|
|
|
virtual ~COSXKeyState();
|
|
|
|
|
2004-10-24 18:15:33 +00:00
|
|
|
//! Map key event to keys
|
2004-08-04 22:48:08 +00:00
|
|
|
/*!
|
2004-10-24 18:15:33 +00:00
|
|
|
Converts a key event into a sequence of KeyIDs and the shadow modifier
|
|
|
|
state to a modifier mask. The KeyIDs list, in order, the characters
|
|
|
|
generated by the key press/release. It returns the id of the button
|
|
|
|
that was pressed or released, or 0 if the button doesn't map to a known
|
|
|
|
KeyID.
|
2004-08-04 22:48:08 +00:00
|
|
|
*/
|
2004-10-24 18:15:33 +00:00
|
|
|
KeyButton mapKeyFromEvent(CKeyIDs& ids,
|
|
|
|
KeyModifierMask* maskOut, EventRef event) const;
|
2004-05-26 19:23:32 +00:00
|
|
|
|
2004-07-29 22:11:27 +00:00
|
|
|
//! Handle modifier key change
|
|
|
|
/*!
|
|
|
|
Determines which modifier keys have changed and updates the modifier
|
|
|
|
state and sends key events as appropriate.
|
|
|
|
*/
|
|
|
|
void handleModifierKeys(void* target,
|
|
|
|
KeyModifierMask oldMask, KeyModifierMask newMask);
|
|
|
|
|
2004-04-11 14:58:08 +00:00
|
|
|
// IKeyState overrides
|
2004-07-29 22:11:27 +00:00
|
|
|
virtual void setHalfDuplexMask(KeyModifierMask);
|
2004-04-11 14:58:08 +00:00
|
|
|
virtual bool fakeCtrlAltDel();
|
|
|
|
virtual const char* getKeyName(KeyButton) const;
|
2004-05-26 19:23:32 +00:00
|
|
|
virtual void sendKeyEvent(void* target,
|
|
|
|
bool press, bool isAutoRepeat,
|
|
|
|
KeyID key, KeyModifierMask mask,
|
|
|
|
SInt32 count, KeyButton button);
|
2004-07-29 22:11:27 +00:00
|
|
|
|
2004-04-11 14:58:08 +00:00
|
|
|
protected:
|
|
|
|
// IKeyState overrides
|
|
|
|
virtual void doUpdateKeys();
|
|
|
|
virtual void doFakeKeyEvent(KeyButton button,
|
|
|
|
bool press, bool isAutoRepeat);
|
|
|
|
virtual KeyButton mapKey(Keystrokes& keys, KeyID id,
|
|
|
|
KeyModifierMask desiredMask,
|
|
|
|
bool isAutoRepeat) const;
|
|
|
|
|
|
|
|
private:
|
2004-11-09 20:05:33 +00:00
|
|
|
struct CKeyEventInfo {
|
|
|
|
public:
|
|
|
|
KeyButton m_button;
|
|
|
|
KeyModifierMask m_requiredMask;
|
|
|
|
KeyModifierMask m_requiredState;
|
|
|
|
};
|
|
|
|
typedef std::vector<CKeyEventInfo> CKeySequence;
|
2004-10-24 18:15:33 +00:00
|
|
|
typedef std::map<KeyID, CKeySequence> CKeyIDMap;
|
|
|
|
typedef std::map<UInt32, KeyID> CVirtualKeyMap;
|
2004-11-12 15:50:04 +00:00
|
|
|
typedef std::set<KeyID> CKeySet;
|
2004-10-24 18:15:33 +00:00
|
|
|
|
|
|
|
KeyButton addKeystrokes(Keystrokes& keys,
|
|
|
|
KeyButton keyButton,
|
|
|
|
KeyModifierMask desiredMask,
|
|
|
|
KeyModifierMask requiredMask,
|
|
|
|
bool isAutoRepeat) const;
|
2004-04-11 14:58:08 +00:00
|
|
|
bool adjustModifiers(Keystrokes& keys,
|
|
|
|
Keystrokes& undo,
|
2004-10-24 18:15:33 +00:00
|
|
|
KeyModifierMask desiredMask,
|
|
|
|
KeyModifierMask requiredMask) const;
|
2004-07-29 22:11:27 +00:00
|
|
|
void addKeyButton(KeyButtons& keys, KeyID id) const;
|
|
|
|
void handleModifierKey(void* target, KeyID id, bool down);
|
2004-04-11 14:58:08 +00:00
|
|
|
|
2004-10-24 18:15:33 +00:00
|
|
|
// Check if the keyboard layout has changed and call doUpdateKeys
|
|
|
|
// if so.
|
|
|
|
void checkKeyboardLayout();
|
|
|
|
|
|
|
|
// Switch to a new keyboard layout.
|
|
|
|
void setKeyboardLayout(SInt16 keyboardLayoutID);
|
|
|
|
|
|
|
|
// Insert KeyID to key sequences for non-printing characters, like
|
|
|
|
// delete, home, up arrow, etc. and the virtual key to KeyID mapping.
|
|
|
|
void fillSpecialKeys(CKeyIDMap& keyMap,
|
|
|
|
CVirtualKeyMap& virtualKeyMap) const;
|
|
|
|
|
|
|
|
// Convert the KCHR resource to a KeyID to key sequence map. the
|
|
|
|
// map maps each KeyID to the sequence of keys (with modifiers)
|
|
|
|
// that would have to be synthesized to generate the KeyID character.
|
|
|
|
// Returns false iff no KCHR resource was found.
|
2004-11-12 15:50:04 +00:00
|
|
|
bool fillKCHRKeysMap(CKeyIDMap& keyMap,
|
|
|
|
CKeySet& capsLockSet) const;
|
2004-10-24 18:15:33 +00:00
|
|
|
|
|
|
|
// Convert the uchr resource to a KeyID to key sequence map. the
|
|
|
|
// map maps each KeyID to the sequence of keys (with modifiers)
|
|
|
|
// that would have to be synthesized to generate the KeyID character.
|
|
|
|
// Returns false iff no uchr resource was found.
|
2004-11-12 15:50:04 +00:00
|
|
|
bool filluchrKeysMap(CKeyIDMap& keyMap,
|
|
|
|
CKeySet& capsLockSet) const;
|
2004-10-24 18:15:33 +00:00
|
|
|
|
|
|
|
// Maps an OS X virtual key id to a KeyButton. This simply remaps
|
|
|
|
// the ids so we don't use KeyButton 0.
|
|
|
|
static KeyButton mapVirtualKeyToKeyButton(UInt32 keyCode);
|
|
|
|
|
|
|
|
// Maps a KeyButton to an OS X key code. This is the inverse of
|
|
|
|
// mapVirtualKeyToKeyButton.
|
|
|
|
static UInt32 mapKeyButtonToVirtualKey(KeyButton keyButton);
|
|
|
|
|
|
|
|
// Convert a character in the current script to the equivalent KeyID.
|
|
|
|
static KeyID charToKeyID(UInt8);
|
|
|
|
|
|
|
|
// Convert a unicode character to the equivalent KeyID.
|
|
|
|
static KeyID unicharToKeyID(UniChar);
|
|
|
|
|
|
|
|
// Choose the modifier mask with the fewest modifiers for character
|
|
|
|
// mapping table i.
|
|
|
|
static KeyModifierMask
|
|
|
|
maskForTable(UInt8 i, UInt8* tableSelectors);
|
|
|
|
|
2004-04-11 14:58:08 +00:00
|
|
|
private:
|
2004-10-24 18:15:33 +00:00
|
|
|
// OS X uses a physical key if 0 for the 'A' key. synergy reserves
|
|
|
|
// KeyButton 0 so we offset all OS X physical key ids by this much
|
|
|
|
// when used as a KeyButton and by minus this much to map a KeyButton
|
|
|
|
// to a physical button.
|
|
|
|
enum {
|
|
|
|
KeyButtonOffset = 1
|
|
|
|
};
|
2004-04-11 14:58:08 +00:00
|
|
|
|
2004-10-24 18:15:33 +00:00
|
|
|
// KCHR resource header
|
|
|
|
struct CKCHRResource {
|
|
|
|
public:
|
|
|
|
SInt16 m_version;
|
|
|
|
UInt8 m_tableSelectionIndex[256];
|
|
|
|
SInt16 m_numTables;
|
|
|
|
UInt8 m_characterTables[1][128];
|
|
|
|
};
|
2004-05-26 19:23:32 +00:00
|
|
|
|
2004-10-24 18:15:33 +00:00
|
|
|
SInt16 m_keyboardLayoutID;
|
|
|
|
mutable UInt32 m_deadKeyState;
|
|
|
|
Handle m_KCHRHandle;
|
|
|
|
Handle m_uchrHandle;
|
|
|
|
CKCHRResource* m_KCHRResource;
|
|
|
|
UCKeyboardLayout* m_uchrResource;
|
|
|
|
CKeyIDMap m_keyMap;
|
|
|
|
CVirtualKeyMap m_virtualKeyMap;
|
2004-11-12 15:50:04 +00:00
|
|
|
CKeySet m_capsLockSet;
|
2004-04-11 14:58:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|