2003-09-02 22:05:47 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2003 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 IKEYSTATE_H
|
|
|
|
#define IKEYSTATE_H
|
|
|
|
|
|
|
|
#include "IInterface.h"
|
|
|
|
#include "KeyTypes.h"
|
2004-03-21 20:01:41 +00:00
|
|
|
#include "CEvent.h"
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Key state interface
|
|
|
|
/*!
|
|
|
|
This interface provides access to set and query the keyboard state and
|
|
|
|
to synthesize key events.
|
|
|
|
*/
|
2003-09-02 22:05:47 +00:00
|
|
|
class IKeyState : public IInterface {
|
|
|
|
public:
|
2004-03-21 20:01:41 +00:00
|
|
|
enum {
|
|
|
|
kNumButtons = 0x200
|
2003-09-02 22:05:47 +00:00
|
|
|
};
|
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Key event data
|
|
|
|
class CKeyInfo {
|
|
|
|
public:
|
|
|
|
static CKeyInfo* alloc(KeyID, KeyModifierMask, KeyButton, SInt32 count);
|
|
|
|
|
|
|
|
public:
|
|
|
|
KeyID m_key;
|
|
|
|
KeyModifierMask m_mask;
|
|
|
|
KeyButton m_button;
|
|
|
|
SInt32 m_count;
|
|
|
|
};
|
2003-09-02 22:05:47 +00:00
|
|
|
|
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
|
|
|
|
|
|
|
//! Update the key state
|
|
|
|
/*!
|
|
|
|
Causes the key state to get updated to reflect the physical keyboard
|
|
|
|
state and current keyboard mapping.
|
|
|
|
*/
|
|
|
|
virtual void updateKeys() = 0;
|
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Set half-duplex mask
|
2003-09-02 22:05:47 +00:00
|
|
|
/*!
|
2004-03-21 20:01:41 +00:00
|
|
|
Sets which modifier toggle keys are half-duplex. A half-duplex
|
|
|
|
toggle key doesn't report a key release when toggled on and
|
|
|
|
doesn't report a key press when toggled off.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
2004-03-21 20:01:41 +00:00
|
|
|
virtual void setHalfDuplexMask(KeyModifierMask) = 0;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Fake a key press
|
2003-09-02 22:05:47 +00:00
|
|
|
/*!
|
2004-03-21 20:01:41 +00:00
|
|
|
Synthesizes a key press event and updates the key state.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
2004-03-21 20:01:41 +00:00
|
|
|
virtual void fakeKeyDown(KeyID id, KeyModifierMask mask,
|
|
|
|
KeyButton button) = 0;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Fake a key repeat
|
2003-09-02 22:05:47 +00:00
|
|
|
/*!
|
2004-03-21 20:01:41 +00:00
|
|
|
Synthesizes a key repeat event and updates the key state.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
2004-03-21 20:01:41 +00:00
|
|
|
virtual void fakeKeyRepeat(KeyID id, KeyModifierMask mask,
|
|
|
|
SInt32 count, KeyButton button) = 0;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Fake a key release
|
2003-09-02 22:05:47 +00:00
|
|
|
/*!
|
2004-03-21 20:01:41 +00:00
|
|
|
Synthesizes a key release event and updates the key state.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
2004-03-21 20:01:41 +00:00
|
|
|
virtual void fakeKeyUp(KeyButton button) = 0;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Fake a modifier toggle
|
2003-09-02 22:05:47 +00:00
|
|
|
/*!
|
2004-03-21 20:01:41 +00:00
|
|
|
Synthesizes key press/release events to toggle the given \p modifier
|
|
|
|
and updates the key state.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
2004-03-21 20:01:41 +00:00
|
|
|
virtual void fakeToggle(KeyModifierMask modifier) = 0;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-26 20:59:26 +00:00
|
|
|
//! Fake ctrl+alt+del
|
|
|
|
/*!
|
|
|
|
Synthesize a press of ctrl+alt+del. Return true if processing is
|
|
|
|
complete and false if normal key processing should continue.
|
|
|
|
*/
|
|
|
|
virtual bool fakeCtrlAltDel() = 0;
|
|
|
|
|
2003-09-02 22:05:47 +00:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
|
|
|
|
|
|
|
//! Test if key is pressed
|
|
|
|
/*!
|
|
|
|
Returns true iff the given key is down. Half-duplex toggles
|
2004-03-21 20:01:41 +00:00
|
|
|
always return false.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
|
|
|
virtual bool isKeyDown(KeyButton) const = 0;
|
|
|
|
|
|
|
|
//! Get the active modifiers
|
|
|
|
/*!
|
|
|
|
Returns the modifiers that are currently active.
|
|
|
|
*/
|
|
|
|
virtual KeyModifierMask
|
|
|
|
getActiveModifiers() const = 0;
|
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Get name of key
|
2003-09-02 22:05:47 +00:00
|
|
|
/*!
|
2004-03-21 20:01:41 +00:00
|
|
|
Return a string describing the given key.
|
2003-09-02 22:05:47 +00:00
|
|
|
*/
|
2004-03-21 20:01:41 +00:00
|
|
|
virtual const char* getKeyName(KeyButton) const = 0;
|
2003-09-02 22:05:47 +00:00
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
//! Get key down event type. Event data is CKeyInfo*, count == 1.
|
|
|
|
static CEvent::Type getKeyDownEvent();
|
|
|
|
//! Get key up event type. Event data is CKeyInfo*, count == 1.
|
|
|
|
static CEvent::Type getKeyUpEvent();
|
|
|
|
//! Get key repeat event type. Event data is CKeyInfo*.
|
|
|
|
static CEvent::Type getKeyRepeatEvent();
|
2003-09-02 22:05:47 +00:00
|
|
|
|
|
|
|
//@}
|
|
|
|
|
2004-03-21 20:01:41 +00:00
|
|
|
private:
|
|
|
|
static CEvent::Type s_keyDownEvent;
|
|
|
|
static CEvent::Type s_keyUpEvent;
|
|
|
|
static CEvent::Type s_keyRepeatEvent;
|
2003-09-02 22:05:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|