   Direct Input Scan Codes
  Is there an easier way to convert Direct Input scan codes to ASCII than using a huge switch statement? I ask because I want to take buffered input and use it for a chat box but need to get the input to ASCII characters. Here's what I mean:/**************************************************************************** * * DirectInput keyboard scan codes * ****************************************************************************/#define DIK_ESCAPE0x01#define DIK_10x02#define DIK_20x03#define DIK_30x04#define DIK_40x05#define DIK_50x06#define DIK_60x07#define DIK_70x08#define DIK_80x09#define DIK_90x0A#define DIK_00x0B#define DIK_MINUS 0x0C    /* - on main keyboard */#define DIK_EQUALS0x0D#define DIK_BACK  0x0E    /* backspace */#define DIK_TAB   0x0F#define DIK_Q0x10#define DIK_W0x11#define DIK_E0x12#define DIK_R0x13#define DIK_T0x14#define DIK_Y0x15#define DIK_U0x16#define DIK_I0x17#define DIK_O0x18#define DIK_P0x19#define DIK_LBRACKET   0x1A#define DIK_RBRACKET   0x1B#define DIK_RETURN0x1C    /* Enter on main keyboard */#define DIK_LCONTROL   0x1D#define DIK_A0x1E#define DIK_S0x1F#define DIK_D0x20#define DIK_F0x21#define DIK_G0x22#define DIK_H0x23#define DIK_J0x24#define DIK_K0x25#define DIK_L0x26#define DIK_SEMICOLON  0x27#define DIK_APOSTROPHE 0x28#define DIK_GRAVE 0x29    /* accent grave */#define DIK_LSHIFT0x2A#define DIK_BACKSLASH  0x2B#define DIK_Z0x2C#define DIK_X0x2D#define DIK_C0x2E#define DIK_V0x2F#define DIK_B0x30#define DIK_N0x31#define DIK_M0x32#define DIK_COMMA 0x33#define DIK_PERIOD0x34    /* . on main keyboard */#define DIK_SLASH 0x35    /* / on main keyboard */#define DIK_RSHIFT0x36#define DIK_MULTIPLY   0x37    /* * on numeric keypad */#define DIK_LMENU 0x38    /* left Alt */#define DIK_SPACE 0x39#define DIK_CAPITAL    0x3A#define DIK_F1    0x3B#define DIK_F2    0x3C#define DIK_F3    0x3D#define DIK_F4    0x3E#define DIK_F5    0x3F#define DIK_F6    0x40#define DIK_F7    0x41#define DIK_F8    0x42#define DIK_F9    0x43#define DIK_F10   0x44#define DIK_NUMLOCK    0x45#define DIK_SCROLL0x46    /* Scroll Lock */#define DIK_NUMPAD7    0x47#define DIK_NUMPAD8    0x48#define DIK_NUMPAD9    0x49#define DIK_SUBTRACT   0x4A    /* - on numeric keypad */#define DIK_NUMPAD4    0x4B#define DIK_NUMPAD5    0x4C#define DIK_NUMPAD6    0x4D#define DIK_ADD   0x4E    /* + on numeric keypad */#define DIK_NUMPAD1    0x4F#define DIK_NUMPAD2    0x50#define DIK_NUMPAD3    0x51#define DIK_NUMPAD0    0x52#define DIK_DECIMAL    0x53    /* . on numeric keypad */#define DIK_OEM_102    0x56    /* <> or \| on RT 102-key keyboard (Non-U.S.) */#define DIK_F11   0x57#define DIK_F12   0x58#define DIK_F13   0x64    /* (NEC PC98) */#define DIK_F14   0x65    /* (NEC PC98) */#define DIK_F15   0x66    /* (NEC PC98) */#define DIK_KANA  0x70    /* (Japanese keyboard)  */#define DIK_ABNT_C1    0x73    /* /? on Brazilian keyboard */#define DIK_CONVERT    0x79    /* (Japanese keyboard)  */#define DIK_NOCONVERT  0x7B    /* (Japanese keyboard)  */#define DIK_YEN   0x7D    /* (Japanese keyboard)  */#define DIK_ABNT_C2    0x7E    /* Numpad . on Brazilian keyboard */#define DIK_NUMPADEQUALS    0x8D    /* = on numeric keypad (NEC PC98) */#define DIK_PREVTRACK  0x90    /* Previous Track (DIK_CIRCUMFLEX on Japanese keyboard) */#define DIK_AT    0x91    /* (NEC PC98) */#define DIK_COLON 0x92    /* (NEC PC98) */#define DIK_UNDERLINE  0x93    /* (NEC PC98) */#define DIK_KANJI 0x94    /* (Japanese keyboard)  */#define DIK_STOP  0x95    /* (NEC PC98) */#define DIK_AX    0x96    /* (Japan AX) */#define DIK_UNLABELED  0x97    /*    (J3100) */#define DIK_NEXTTRACK  0x99    /* Next Track */#define DIK_NUMPADENTER0x9C    /* Enter on numeric keypad */#define DIK_RCONTROL   0x9D#define DIK_MUTE  0xA0    /* Mute */#define DIK_CALCULATOR 0xA1    /* Calculator */#define DIK_PLAYPAUSE  0xA2    /* Play / Pause */#define DIK_MEDIASTOP  0xA4    /* Media Stop */#define DIK_VOLUMEDOWN 0xAE    /* Volume - */#define DIK_VOLUMEUP   0xB0    /* Volume + */#define DIK_WEBHOME    0xB2    /* Web home */#define DIK_NUMPADCOMMA0xB3    /* , on numeric keypad (NEC PC98) */#define DIK_DIVIDE0xB5    /* / on numeric keypad */#define DIK_SYSRQ 0xB7#define DIK_RMENU 0xB8    /* right Alt */#define DIK_PAUSE 0xC5    /* Pause */#define DIK_HOME  0xC7    /* Home on arrow keypad */#define DIK_UP    0xC8    /* UpArrow on arrow keypad */#define DIK_PRIOR 0xC9    /* PgUp on arrow keypad */#define DIK_LEFT  0xCB    /* LeftArrow on arrow keypad */#define DIK_RIGHT 0xCD    /* RightArrow on arrow keypad */#define DIK_END   0xCF    /* End on arrow keypad */#define DIK_DOWN  0xD0    /* DownArrow on arrow keypad */#define DIK_NEXT  0xD1    /* PgDn on arrow keypad */#define DIK_INSERT0xD2    /* Insert on arrow keypad */#define DIK_DELETE0xD3    /* Delete on arrow keypad */#define DIK_LWIN  0xDB    /* Left Windows key */#define DIK_RWIN  0xDC    /* Right Windows key */#define DIK_APPS  0xDD    /* AppMenu key */#define DIK_POWER 0xDE    /* System Power */#define DIK_SLEEP 0xDF    /* System Sleep */#define DIK_WAKE  0xE3    /* System Wake */#define DIK_WEBSEARCH  0xE5    /* Web Search */#define DIK_WEBFAVORITES    0xE6    /* Web Favorites */#define DIK_WEBREFRESH 0xE7    /* Web Refresh */#define DIK_WEBSTOP    0xE8    /* Web Stop */#define DIK_WEBFORWARD 0xE9    /* Web Forward */#define DIK_WEBBACK    0xEA    /* Web Back */#define DIK_MYCOMPUTER 0xEB    /* My Computer */#define DIK_MAIL  0xEC    /* Mail */#define DIK_MEDIASELECT0xED    /* Media Select *//* *  Alternate names for keys, to facilitate transition from DOS. */#define DIK_BACKSPACE  DIK_BACK  /* backspace */#define DIK_NUMPADSTAR DIK_MULTIPLY   /* * on numeric keypad */#define DIK_LALT  DIK_LMENU /* left Alt */#define DIK_CAPSLOCK   DIK_CAPITAL    /* CapsLock */#define DIK_NUMPADMINUSDIK_SUBTRACT   /* - on numeric keypad */#define DIK_NUMPADPLUS DIK_ADD   /* + on numeric keypad */#define DIK_NUMPADPERIOD    DIK_DECIMAL    /* . on numeric keypad */#define DIK_NUMPADSLASHDIK_DIVIDE/* / on numeric keypad */#define DIK_RALT  DIK_RMENU /* right Alt */#define DIK_UPARROW    DIK_UP    /* UpArrow on arrow keypad */#define DIK_PGUP  DIK_PRIOR /* PgUp on arrow keypad */#define DIK_LEFTARROW  DIK_LEFT  /* LeftArrow on arrow keypad */#define DIK_RIGHTARROW DIK_RIGHT /* RightArrow on arrow keypad */#define DIK_DOWNARROW  DIK_DOWN  /* DownArrow on arrow keypad */#define DIK_PGDN  DIK_NEXT  /* PgDn on arrow keypad *//* *  Alternate names for keys originally not used on US keyboards. */#define DIK_CIRCUMFLEX DIK_PREVTRACK  /* Japanese keyboard */#endif /* DIJ_RINGZERO */Thats an excerpt from dinput.h. As you can see, the characters a user would type have very different codes from the ones in ASCII, as the scan codes are scan codes which mean they go in order as seen on a keyboard.   
  Fill a lookup table.char Table[] = {0, 27, '1', '2', ... , 'A', 'B', ... , };Now, Table[DIK_ESCAPE] with DIK_ESCAPE = 1 is the ascii code for esc (27), Table[DIK_1] with DIK_1 = 2 is the ascii code for 1 in the above array, and so on. Fill the array in the same order as the scancodes.Cheers.   ; DirectInput: Converting Scan Codes to ASCII;  or, you can capture WM_CHAR messages in your message loop and add them to a string.  a little bonus is that you get key autorepeat.  though you have to parse things like tab, backspace etc.   