Jump to content
  • Advertisement
Sign in to follow this  
wforl

OpenGL User text input

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

How would i go about creating text input by the user? such that they pressed a text mode key such as 'T', which then they can enter script commands, which then will be activated by pressing enter. Kind of like this in console mode game::frameUpdate(float time) { if(keyPress == "t"){ cin << scriptJob << endl; } if (scriptJob == "godMode"){ life = 100; damageStrength = 0; } } i have had no real win32 experience other than creating the window for directx/openGL, so dont know where to look really. thanks

Share this post


Link to post
Share on other sites
Advertisement
First, stay away from DirectInput. It's completely unsiotable for keyboard or mouse input.

I'd just handle WM_CHAR messages and display the characters as they're entered using whatever method you like to render text.

Share this post


Link to post
Share on other sites
hmm, so when t is pressed, detect keys, and output each key as it is pressed?

hmm, but after t is pressed and i use a switch statement to go through, looking for what the first key pressed was, and append it to a string, there going to have to pressed t again, to enter the wm_char: again.

could you possibly show me an example of the win32 code?

i gather it would be a while loop until enter is pressed, but when in in wm_char:, im only going to have that one key? (t), how would i get the next entered key.

I know how to render the string to text.

Share this post


Link to post
Share on other sites
Quote:
Original post by wforl
hmm, so when t is pressed, detect keys, and output each key as it is pressed?

hmm, but after t is pressed and i use a switch statement to go through, looking for what the first key pressed was, and append it to a string, there going to have to pressed t again, to enter the wm_char: again.

could you possibly show me an example of the win32 code?
It entirely depends on how the rest of your code is written. Usually you'd have a "game" state, which you're in normally. When t is pressed, you'd change state to "inputting text", and then stay in that state till enter was pressed, when you'd handle the whole string and then go back to the "game" state.

Quote:
Original post by wforl
i gather it would be a while loop until enter is pressed, but when in in wm_char:, im only going to have that one key? (t), how would i get the next entered key.
It'd be something like (psuedo-code, and quite ugly):

void onKeypress(char ch)
{
if(state == STATE_InGame)
{
if(ch == 't')
{
state = STATE_InputtingText;
strBuffer = "";
}
}
else
{
if(ch == '\n')
{
processCommand(strBuffer);
state = STATE_InGame;
}
else
strBuffer += ch;
}
}

Share this post


Link to post
Share on other sites
How would i go about creating text input by the user? such that they pressed a text mode key such as 'T', which then they can enter script commands, which then will be activated by pressing enter.

in the WndProc function you want ,

CASE WM_CHAR:
switch(wParam)
{
case 'T': DoSomething(); break;
}

Share this post


Link to post
Share on other sites
i have that, but im wondering how i get further text though?


CASE WM_CHAR:
switch(wParam)
{
case 'T': getTextInput(); break;
}


how would getTextInput work?, i know how to do this in console but not in win32, where i would use, cin, or getch() etc

Share this post


Link to post
Share on other sites
how would getTextInput work?, i know how to do this in console but not in win32, where i would use, cin, or getch() etc

so your working to get text from the console window?
why dont you create a console with AllocConsole and use ReadConsole to recieve the input text , not sure if you can use a standard console with a directx window , i think the cin is only used when you have int main and not WinMain

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!