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"
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
|
|
|
//! OS X key state
|
|
|
|
/*!
|
|
|
|
A key state for OS X.
|
|
|
|
*/
|
|
|
|
class COSXKeyState : public CKeyState {
|
|
|
|
public:
|
2004-08-04 22:48:08 +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
|
|
|
COSXKeyState();
|
|
|
|
virtual ~COSXKeyState();
|
|
|
|
|
2004-08-04 22:48:08 +00:00
|
|
|
//! Map physical key id to a KeyButton id
|
|
|
|
/*!
|
|
|
|
Maps an OS X key code to a KeyButton. This simply remaps the ids
|
|
|
|
so we don't use KeyButton 0.
|
|
|
|
*/
|
|
|
|
static KeyButton mapKeyCodeToKeyButton(UInt32 keyCode);
|
|
|
|
|
|
|
|
//! Map KeyButton id to a physical key id
|
|
|
|
/*!
|
|
|
|
Maps a KeyButton to an OS X key code. This is the inverse of
|
|
|
|
mapKeyCodeToKeyButton.
|
|
|
|
*/
|
|
|
|
static UInt32 mapKeyButtonToKeyCode(KeyButton keyButton);
|
|
|
|
|
2004-05-26 19:23:32 +00:00
|
|
|
//! Map key event to a key
|
|
|
|
/*!
|
|
|
|
Converts a key event into a KeyID and the shadow modifier state
|
|
|
|
to a modifier mask.
|
|
|
|
*/
|
|
|
|
KeyID mapKeyFromEvent(EventRef event,
|
|
|
|
KeyModifierMask* maskOut) const;
|
|
|
|
|
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:
|
|
|
|
bool adjustModifiers(Keystrokes& keys,
|
|
|
|
Keystrokes& undo,
|
|
|
|
KeyModifierMask desiredMask) 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
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::map<KeyID, KeyButton> CKeyMap;
|
|
|
|
|
|
|
|
CKeyMap m_keyMap;
|
2004-05-26 19:23:32 +00:00
|
|
|
|
|
|
|
static const KeyID s_virtualKey[];
|
2004-04-11 14:58:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|