Skip to main content
GameDev.net gamedev.net
🔒 Locked

Universal KeyCode?

Started by Sevans Jul 12, 2007 at 2:39 PM 0 replies 1.9k views
Original Post
Sevans
Sevans
I am currently building a wrapper for DirectInput. I would like to use my own keycodes instead of the DirectInput keycodes. I am having trouble thinking up a good way to convert the DirectInput keycodes into my keycodes. Is there any universal keycode to correspond to keys? I know I could convert to ascii but sometimes information can be lost, and I would also need a function to convert from Ascii to DirectInput codes (this would be most helpful right now). Here is roughly how I want it to work.

// input wrapper interface
class IInputDriver {
   enum MyKeyCodeType {
      KEY_RIGHT
      //...
   };

   virtual bool isKeyDown( MyKeyCodeType key )=0;
};

// directinput wrapper implementation
class InputDriverDX9 : public IInputDriver {
   // this class has all of the logic to
   // deal with direct input

   bool isKeyDown( MyKeyCodeType key ){
      // at this point I have an array of bytes.
      // bit 0x80 is set iff the key was down at last device poll
      // the array is indexed by DirectInput Key Codes.
      // so I need to convert my MyKeyCodeType key passed in
      // to a DirectInput key code.
      // so I wonder, what would be the best value for my key codes
      //  and how would i convert them?
   };
};

// how to use the input driver
int main(){
   // this will be done by a factory in real implementation
   IInputDriver *driver = new InputDriverDX9();
}


Anyone got any ideas? Thanks -Sevans
-Sevans
Sevans
Sevans
Well I am going to start implementing a translation table, between the DI codes and my codes, boo hoo. ^.^d

BUT if anyone knows of a better way to do this by simply making a few fancy schmancy method calls please let me know.
-Sevans

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.