User text input
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
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.
I'd just handle WM_CHAR messages and display the characters as they're entered using whatever method you like to render text.
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.
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.
Quote:Original post by wforlIt 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.
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?
Quote:Original post by wforlIt'd be something like (psuedo-code, and quite ugly):
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.
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; }}
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;
}
in the WndProc function you want ,
CASE WM_CHAR:
switch(wParam)
{
case 'T': DoSomething(); break;
}
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement