• Advertisement

Archived

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

scanf command

This topic is 5711 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

Could someone post some code they used to make their own "scanf" command using directinput? this proves to be very hard.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You could just collect the inputted characters into a buffer and use sscanf

Share this post


Link to post
Share on other sites
Well, is there a way to change the DIK_WHATEVER into ascii? I would very much hate doing if(keydown(DIK_A)) etc..

Share this post


Link to post
Share on other sites
Well, what do I use for the scancode argument? I''m using a UCHAR array to store the characters..

Share this post


Link to post
Share on other sites
well, if I''m going to do it that way, its useless. because I would have to do one call for each letter... and I could do the same thing by writing my own code to handle each letter. Isn''t there something I could pass the character array to and it would search through it and see which ones are pressed and at it to a character array? thats all I really need..

Share this post


Link to post
Share on other sites
I don''t see what the problem is, every time a key is pressed, just call the scan2asc function that IndirectX provided, and append it to the string...


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
but I don''t know what DIK_WHATEVER is. I want to be able to do it without having to write a big switch command.

Share this post


Link to post
Share on other sites
OK, so I assume since you don''t understand this that you''re using IDirectInputDevice8::GetDeviceStateKeyboard or IDirectInputDevice8::GetDeviceState. That''s the wrong function to be using, you should use IDirectInputDevice8::GetDeviceData. Here''s a quick sample:


  
DIDEVICEOBJECTDATA keyState[64];
unsigned long numKeys = 64;

m_Keyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), keyState, &numKeys, 0 );

for( int i = 0; i < (signed)numKeys; i++ )
{
if( keyState[i].dwData != 0 ) // key was pressed

{
char ascii = scan2asc( keyState[i].dwOfs );
// now append ascii to your string...

}
}



codeka.com - Just click it.

Share this post


Link to post
Share on other sites

  • Advertisement