R
Rubén Campos
I want to write a class to manage keyboard SHIFT, ALT and CTRL modifier keys
in an event management system, distinguishing between left and right keys of
each one. This seems trivial, but I've found a design problem (from a formal
perspective) I dealed with before, in other contexts, and for which I can't
find an optimum solution. Specifically, I don't know which is the optimum
way to provide access to each modifier key state.
My first alternative is to include explicit access methods for each modifier
key:
enum TKeyState { KEY_STATE_RELEASED, KEY_STATE_PUSHED };
class CKeyboardModifierKeys
{
// ...
TKeyState GetLeftSHIFTState () const;
TKeyState GetRightSHIFTState () const;
TKeyState GetSHIFTState () const;
TKeyState GetLeftALTState () const;
TKeyState GetRightALTState () const;
TKeyState GetALTState () const;
TKeyState GetLeftCTRLState () const;
TKeyState GetRightCTRLState () const;
TKeyState GetCTRLState () const;
void SetLeftSHIFTState (const TKeyState value);
void SetRightSHIFTState (const TKeyState value);
void SetLeftALTState (const TKeyState value);
void SetRightALTState (const TKeyState value);
void SetLeftCTRLState (const TKeyState value);
void SetRightCTRLState (const TKeyState value);
// ...
};
My second alternative is to refer the different keys through members of an
enumeration:
class CKeyboardModifierKeys
{
// ...
enum TModifierKey { SHIFT, ALT, CTRL };
enum TWhichKey { LEFT, RIGHT, ANY };
TKeyState GetKeyState (const TModifierKey key, const TWhichKey which)
const;
void GetKeyState (const TModifierKey key, const TWhichKey which, const
TKeyState value);
// ...
};
I don't know additional ways, but I'm sure that other alternatives can be
considered. Can someone give me advice? Thank yo in advance
in an event management system, distinguishing between left and right keys of
each one. This seems trivial, but I've found a design problem (from a formal
perspective) I dealed with before, in other contexts, and for which I can't
find an optimum solution. Specifically, I don't know which is the optimum
way to provide access to each modifier key state.
My first alternative is to include explicit access methods for each modifier
key:
enum TKeyState { KEY_STATE_RELEASED, KEY_STATE_PUSHED };
class CKeyboardModifierKeys
{
// ...
TKeyState GetLeftSHIFTState () const;
TKeyState GetRightSHIFTState () const;
TKeyState GetSHIFTState () const;
TKeyState GetLeftALTState () const;
TKeyState GetRightALTState () const;
TKeyState GetALTState () const;
TKeyState GetLeftCTRLState () const;
TKeyState GetRightCTRLState () const;
TKeyState GetCTRLState () const;
void SetLeftSHIFTState (const TKeyState value);
void SetRightSHIFTState (const TKeyState value);
void SetLeftALTState (const TKeyState value);
void SetRightALTState (const TKeyState value);
void SetLeftCTRLState (const TKeyState value);
void SetRightCTRLState (const TKeyState value);
// ...
};
My second alternative is to refer the different keys through members of an
enumeration:
class CKeyboardModifierKeys
{
// ...
enum TModifierKey { SHIFT, ALT, CTRL };
enum TWhichKey { LEFT, RIGHT, ANY };
TKeyState GetKeyState (const TModifierKey key, const TWhichKey which)
const;
void GetKeyState (const TModifierKey key, const TWhichKey which, const
TKeyState value);
// ...
};
I don't know additional ways, but I'm sure that other alternatives can be
considered. Can someone give me advice? Thank yo in advance