Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 WunderStrudel   Members   -  Reputation: 156

Like
0Likes
Like

Posted 09 November 2013 - 04:40 PM

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..



Sponsor:

#2 Dave Hunt   Crossbones+   -  Reputation: 3796

Like
2Likes
Like

Posted 09 November 2013 - 09:49 PM

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.



#3 Godmil   Members   -  Reputation: 744

Like
1Likes
Like

Posted 10 November 2013 - 02:09 AM

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, 10 November 2013 - 03:21 AM.


#4 ryt   Members   -  Reputation: 294

Like
1Likes
Like

Posted 10 November 2013 - 06:21 AM

Std library supports string class so I recommend using this instead of arrays.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS