Archived

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

Game console input

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

First of all, the console I''m talking about isn''t a DOS window, it''s the command line interface that appears in FPS games when you press ~ I''ve implemented a basic console for my engine, the problem I have right now is how to get input for it, I use DirectInput, which isn''t based on messages like the Win32 API, I check keyboard and mouse input every frame, and respond to it, this works fine with input for moving around in the world, but it doesn''t work at all for the console, because pressing a key would definitely last for more than one frame, repeating the character several times in the console, and I have to check all the keyboard keys every frame. The only way I could come up with is checking all the keys every frame, and storing a cool-down period for each key, which doesn''t sound that efficient to me, any other suggestions?

Share this post


Link to post
Share on other sites
DirectInput was made for game controls, not for text. Although you could use it for regular text, it can be a real pain. Use Win32 messages instead. When someone is typing text, you don''t need to have the ultra fast response that DirectInput gives you. Using Win32 messages is MUCH simpler for this type of thing.

neneboricua

Share this post


Link to post
Share on other sites
I''m not shure if this is posible, I''ve never tryied under windows, but I guess you could write a function like ''scanf'' and obtain your input from the stdin an then you write to the screen yourself.

Share this post


Link to post
Share on other sites
Actually, I have just created a console just like this. What it does, is check to see if the ~ key is pressed (if it is, it switches the console state). Then, if the console is active, it checks to see if the keys A-Z, 0-9, space, backspace, and enter are being pressed. If the console is not active, it goes into normal input checking.

Like this (psuedocode):

if( KEYDOWN( buffer, DIK_GRAVE ) )
switch console state

if( console state = true )
{
if( KEYDOWN( buffer, DIK_A ) )
charToAdd = ''a'';
.
.
.
else if( KEYDOWN( buffer, DIK_ENTER ) )
consoleProcess = true;
}
else
{
// Normal input checking
}


I am having some problems putting padding time between the keystrokes, though.



Circlesoft Velocity Engine

Share this post


Link to post
Share on other sites
In my console I simply used the windows callback procedure to capture the text and it works great! Here is what I mean:

long CALLBACK WndProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
switch( uMessage )
{
case WM_KEYDOWN:
{
unsigned char nVirtKey = (int) wParam;
theConsole.updateConsole(nVirtKey);
return 0;
}
}
}

Repeats are handled according to your windows key repeat settings. I hope this helps you.

[edited by - blind_prophet on November 6, 2003 5:42:44 PM]

Share this post


Link to post
Share on other sites
I was just down your path and I have a possible solution for you, it worked for me, but depending on how you like to implement things, it may not.

I used an object for the console which contained a struct of boolean values for all the keys, 2 for each, (or an array could be used). One for is down, and one for was down. Then when DINPUT detects that a key is down, it checks to see if it was down before, and if it was it flags the next boolean. Then in your code to add the characters into the console, you just check to see if the button was just pressed, if it was then add the character, if it was down before then just bypass it. And have the input checking code just reset the variables whenever it detects that the keys are not down. Yea, it adds quite a few operations, but it works without having to redesign everything to encorporate using windows messages for taking inputs.



I know only that which I know, but I do not know what I know.

Share this post


Link to post
Share on other sites
If you are using DirectInput then handling the windows keyboard messages is your easiest solution since Windows is implied with DirectX. Another way of doing this is to use a struct like

struct key_struct
{
char key;
bool down;
}KEY_STRUCT;

and use a linked list or stack to store say up to 10 or 20 keys to be safe and add/remove keys when they are down/up. Then you only have to cycle through the keys in your list at a fixed interval to see if you want to repeat it or not. I hope that made sense. There is a little more to it than that but it is the basics of what I am using.


Evillive2
E-Mail

Share this post


Link to post
Share on other sites
I did this:

if(KEYDOWN(''A''))
KeyA();

...

void KeyA()
{
static int LastTime;
if(LastTime == 0)
LastTime = GetTickCount();
if(GetTickCount() - LastTime < 100)
return;
LastTime = GetTickCount();
//Rest of KeyA function.

}

Share this post


Link to post
Share on other sites
quote:
Original post by ms291052
I did this:

if(KEYDOWN(''A''))
KeyA();

...

void KeyA()
{
static int LastTime;
if(LastTime == 0)
LastTime = GetTickCount();
if(GetTickCount() - LastTime < 100)
return;
LastTime = GetTickCount();
//Rest of KeyA function.

}




lol... I didn''t even think of that one. Good one though, I''ll have to give that one a try, that might work out a bit better in the long run.




I know only that which I know, but I do not know what I know.

Share this post


Link to post
Share on other sites
quote:
Original post by CyberJay82
You can do buffered input using DirectInput its a little bit more work but it works fine. There is a section on it in the SDK docs for DirectX and DirectInput.


Thanks guys for the help, as the above post suggested, I used DirectInput buffered mode, it works very similarly to Windows messages, so I don''t need to deal with cool-down times or anything, my console works great now

Share this post


Link to post
Share on other sites
quote:
Original post by glUser3f
Bitmap fonts, check out NeHe tutorials:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13


I think the ID3DXFont interface or CD3DFont class (that comes with the SDK framework) is better, since it actually uses 3d and since it's in DirectX, and not OGL.


Circlesoft Velocity Engine


[edited by - circlesoft on November 8, 2003 1:02:08 PM]

Share this post


Link to post
Share on other sites