Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

EGD Eric

Using DirectInput to get a player's name

This topic is 5242 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If you wanted to get a player to type in his/her name using the keyboard, would you use DirectInput or the Window''s message procedure? If you would use DirectInput, how would you get the characters?

Share this post

Link to post
Share on other sites
I'm really not sure how to convert from DirectInput type
characters to ascii values. Even if you do, you have to
handle the caps / shift keys yourself.

Here's a brute force lookup table to convert from DIK_*
to ascii. Index 0 is normal, 1 is with Shift Keys, 2 is with
Caps lock. It's rather large.

CHAR VKeys[3][256]

VKeys[0][DIK_1] ='1'; VKeys[1][DIK_1] ='!'; VKeys[2][DIK_1] ='1';
VKeys[0][DIK_2] ='2'; VKeys[1][DIK_2] ='@'; VKeys[2][DIK_2] ='2';
VKeys[0][DIK_3] ='3'; VKeys[1][DIK_3] ='#'; VKeys[2][DIK_3] ='3';
VKeys[0][DIK_4] ='4'; VKeys[1][DIK_4] ='$'; VKeys[2][DIK_4] ='4';
VKeys[0][DIK_5] ='5'; VKeys[1][DIK_5] ='%'; VKeys[2][DIK_5] ='5';
VKeys[0][DIK_6] ='6'; VKeys[1][DIK_6] ='^'; VKeys[2][DIK_6] ='6';
VKeys[0][DIK_7] ='7'; VKeys[1][DIK_7] ='&'; VKeys[2][DIK_7] ='7';
VKeys[0][DIK_8] ='8'; VKeys[1][DIK_8] ='*'; VKeys[2][DIK_8] ='8';
VKeys[0][DIK_9] ='9'; VKeys[1][DIK_9] ='('; VKeys[2][DIK_9] ='9';
VKeys[0][DIK_0] ='0'; VKeys[1][DIK_0] =')'; VKeys[2][DIK_0] ='0';
VKeys[0][DIK_MINUS] ='-'; VKeys[1][DIK_MINUS] ='_'; VKeys[2][DIK_MINUS] ='-';
VKeys[0][DIK_EQUALS] ='='; VKeys[1][DIK_EQUALS] ='+'; VKeys[2][DIK_EQUALS] ='=';
VKeys[0][DIK_TAB] ='\t'; VKeys[1][DIK_TAB] ='\t'; VKeys[2][DIK_TAB] ='\t';
VKeys[0][DIK_Q] ='q'; VKeys[1][DIK_Q] ='Q'; VKeys[2][DIK_Q] ='Q';
VKeys[0][DIK_W] ='w'; VKeys[1][DIK_W] ='W'; VKeys[2][DIK_W] ='W';
VKeys[0][DIK_E] ='e'; VKeys[1][DIK_E] ='E'; VKeys[2][DIK_E] ='E';
VKeys[0][DIK_R] ='r'; VKeys[1][DIK_R] ='R'; VKeys[2][DIK_R] ='R';
VKeys[0][DIK_T] ='t'; VKeys[1][DIK_T] ='T'; VKeys[2][DIK_T] ='T';
VKeys[0][DIK_Y] ='y'; VKeys[1][DIK_Y] ='Y'; VKeys[2][DIK_Y] ='Y';
VKeys[0][DIK_U] ='u'; VKeys[1][DIK_U] ='U'; VKeys[2][DIK_U] ='U';
VKeys[0][DIK_I] ='i'; VKeys[1][DIK_I] ='I'; VKeys[2][DIK_I] ='I';
VKeys[0][DIK_O] ='o'; VKeys[1][DIK_O] ='O'; VKeys[2][DIK_O] ='O';
VKeys[0][DIK_P] ='p'; VKeys[1][DIK_P] ='P'; VKeys[2][DIK_P] ='P';
VKeys[0][DIK_LBRACKET] ='['; VKeys[1][DIK_LBRACKET] ='{'; VKeys[2][DIK_LBRACKET] ='[';
][DIK_RBRACKET] =']'; VKeys[1][DIK_RBRACKET] ='}'; VKeys[2][DIK_RBRACKET] =']';
VKeys[0][DIK_A] ='a'; VKeys[1][DIK_A] ='A'; VKeys[2][DIK_A] ='A';
VKeys[0][DIK_S] ='s'; VKeys[1][DIK_S] ='S'; VKeys[2][DIK_S] ='S';
VKeys[0][DIK_D] ='d'; VKeys[1][DIK_D] ='D'; VKeys[2][DIK_D] ='D';
VKeys[0][DIK_F] ='f'; VKeys[1][DIK_F] ='F'; VKeys[2][DIK_F] ='F';
VKeys[0][DIK_G] ='g'; VKeys[1][DIK_G] ='G'; VKeys[2][DIK_G] ='G';
VKeys[0][DIK_H] ='h'; VKeys[1][DIK_H] ='H'; VKeys[2][DIK_H] ='H';
VKeys[0][DIK_J] ='j'; VKeys[1][DIK_J] ='J'; VKeys[2][DIK_J] ='J';
VKeys[0][DIK_K] ='k'; VKeys[1][DIK_K] ='K'; VKeys[2][DIK_K] ='K';
VKeys[0][DIK_L] ='l'; VKeys[1][DIK_L] ='L'; VKeys[2][DIK_L] ='L';
VKeys[0][DIK_SEMICOLON] =';'; VKeys[1][DIK_SEMICOLON] =':'; VKeys[2][DIK_SEMICOLON] =';';
VKeys[0][DIK_APOSTROPHE]='\''; VKeys[1][DIK_APOSTROPHE]='\"'; VKeys[2][DIK_APOSTROPHE]='\'';
VKeys[0][DIK_GRAVE] ='`'; VKeys[1][DIK_GRAVE] ='~'; VKeys[2][DIK_GRAVE] ='`';
VKeys[0][DIK_BACKSLASH] ='\\'; VKeys[1][DIK_BACKSLASH] ='|'; VKeys[2][DIK_BACKSLASH] ='\\';
VKeys[0][DIK_Z] ='z'; VKeys[1][DIK_Z] ='Z'; VKeys[2][DIK_Z] ='Z';
VKeys[0][DIK_X] ='x'; VKeys[1][DIK_X] ='X'; VKeys[2][DIK_X] ='X';
VKeys[0][DIK_C] ='c'; VKeys[1][DIK_C] ='C'; VKeys[2][DIK_C] ='C';
VKeys[0][DIK_V] ='v'; VKeys[1][DIK_V] ='V'; VKeys[2][DIK_V] ='V';
VKeys[0][DIK_B] ='b'; VKeys[1][DIK_B] ='B'; VKeys[2][DIK_B] ='B';
VKeys[0][DIK_N] ='n'; VKeys[1][DIK_N] ='N'; VKeys[2][DIK_N] ='N';
VKeys[0][DIK_M] ='m'; VKeys[1][DIK_M] ='M'; VKeys[2][DIK_M] ='M';
VKeys[0][DIK_COMMA] =','; VKeys[1][DIK_COMMA] ='<'; VKeys[2][DIK_COMMA] =',';
VKeys[0][DIK_PERIOD] ='.'; VKeys[1][DIK_PERIOD] ='>'; VKeys[2][DIK_PERIOD] ='.';
VKeys[0][DIK_SLASH] ='/'; VKeys[1][DIK_SLASH] ='?'; VKeys[2][DIK_SLASH] ='/';
VKeys[0][DIK_SPACE] =' '; VKeys[1][DIK_SPACE] =' '; VKeys[2][DIK_SPACE] =' ';

[edited by - Jiia on May 20, 2004 3:08:42 PM]

Share this post

Link to post
Share on other sites
I have found that the hardest part with typing with DirectInput is the timing part of it. For example, if you make the buffer time too short, when the user presses the ''a'' key, they''re going to get multiple a''s when they want only one. On the other hand, if you make the buffer time too long, the user has to wait intentionally to make their keystrokes. Either way, it''s a very cumbersome system.

However, there is a solution to this. Look into using Buffered Input, instead of Immediate Input. Buffered Input only records when a key is pressed or released - not how long it''s held down, so you can use it effectivly for typing.

Dustin Franklin
Mircrosoft DirectX MVP

Share this post

Link to post
Share on other sites
Use buffered input as suggested above, and see here:

[edited by - AndyTX on May 20, 2004 4:40:37 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!