Jump to content
  • Advertisement
Sign in to follow this  
WunderStrudel

C / C++ --> Need help with some text input.

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

Hii guys (: 
I've been programming in c/c++ for about 6 - 8 month now, mostly game stuff, which might be why i'm asking this newbie question ^^ 
I got tired of playing around with SDL and Opengl efter a while, and i thought to myself "What do you want to achive with programming?", and i guess my answer was "it all" biggrin.png 
But right now i'm making my own little kinda cmd chat, right now just for localhost. 

My problem is getting the keystrokes converted to strings/words, so that it does not just buffer a single letter at the time, but submit the whole word or sesntence. i just deleted my whole project and started from scratch so this is all my code so far; 

#include <iostream>
#include <windows.h>
#include <Winuser.h>
#include <time.h>
using namespace std;

int main()
{

	TCHAR pcName [250];
	TCHAR userName [250];
	DWORD pcSize = 20;
	DWORD userSize = 20;
	SYSTEMTIME st;
	GetLocalTime(&st);

	if(!GetComputerName(pcName,&pcSize))
	{
		cout << "Size: " << pcSize << "\tError Code: " << GetLastError() << std::endl;
	}
	if(!GetUserName(userName,&userSize))
	{
		cout << "Size: " << userSize << "\tError Code: " << GetLastError() << std::endl;
	}



	cout << "(";
	cout << st.wDay;
	cout << "/";
	cout << st.wMonth;
	cout << "/";
	cout << st.wYear;
	cout << " - ";
	cout << st.wHour;
	if((int)st.wMinute < 10)
	{
		cout << ":0";
	} else
		cout << ":";
	
	cout << st.wMinute;
	cout << ":";
	cout << st.wSecond;
	cout << ")";
	cout << " -> ";
	cout << pcName;
	cout << " -> ";
	cout << userName << endl;





	system ("PAUSE");
	return 0;
}

And in the other runs/tests i'v been using GetAsyncKeyState() to detect the keystrokes. Anybody have any lessons to teach me? biggrin.png 
Thanks a lot on advantage. Sincerly Wunder..

Share this post


Link to post
Share on other sites
Advertisement

Based on that little bit of code, I'd recommend this article.

 

In the future, when asking questions it's best to post what you've tried rather than everything but the part you're having a problem with. Asking for help with input and then posting code that has no attempt at input in it isn't the best approach.

Share this post


Link to post
Share on other sites

If you're using c++ it's probable best not to be using character arrays. I tend to read lines into a stringstream, then spit them out into strings or numbers as needed.

Edited by Godmil

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!