Code:
class Observer {
public:
virtual ~Observer() {} // virtual destructor
virtual void notify(int key) = 0;
};
class KeyRegistrar {
public:
virtual void addObserver(int key, Observer *x);
virtual void notifyOfKey(int key);
};
I haven't supplied the code for KeyRegistrar, but it basically remembers a list of which observers are interested in which key events. Then when a key event comes in, the observers are notify()'d and can deal with it appropriately. The user of your code can just subclass Observer to deal with keypresses.