grave key and inkey/inchar

Posted By: Germanunkol

grave key and inkey/inchar - 12/16/09 18:29

I can't figure this one out:
The grave key ( ^ ) is used to open up the console in my game. Now if the user starts typing, the first letter is the grave, because when you press grave windows waits until you press another key and then puts down the grave symbol (if it can't make the second letter into an exponent, I believe).
So the first letter in the console input is ALWAYS ^. It's really annoying. I tried truncing it somehow, tried clipping it... doesn't seem to allow that.
Code:
void consoleDeleteGrave(STRING* activeStr)
{
	
	var length = str_len(activeStr);
	while(!inkey_active) wait(1);
	while(inkey_active)
	{
		if(str_len(activeStr) != length)
		{
			errorNum(str_len(activeStr));
			errorNum(length);
			if(str_stri(consoleInputString, "^") == 1) str_clip(consoleInputString, 1);
			
			
			return;
		}
		wait(1);
	}
}



Now I tried inkey. But Inkey is almost worse: When you press the first letter (since it can only read one char) when trying to input a command, it only reads "^" (no second letter) because windows seems to give it the two letters - ^ and the one you've typed - and it only accepts the first one.
Also, I can't get backspace to work correctly with inchar.

Really stupid... if you want to enter a quick command in the heat of battle... none of this is user friendly.

Help?
Posted By: Germanunkol

Re: grave key and inkey/inchar - 12/17/09 19:12

I should shower more. I always think of solutions while in the shower.

Got it to work. First i confused ASCII return value and scan_code return value, but now it works. For anyone who's interested:
Code:
var curScan = 0;
	do{
		//		if(key_any==1 && mouse_left==0 && mouse_right==0 && mouse_middle==0)
		//		{
			curScan = inchar(incharString);
			if(curScan != 8)		 //backspace is not pressed
			{
				if(curScan == 94 && key_lastpressed != 94)
				{
					str_for_key(incharString, key_lastpressed);
				}
				str_cat(consoleInputString,incharString);
			}
			else
			{   //backspace IS pressed
				str_trunc(consoleInputString,1);
			}
		//		}
		wait(1);
	}while(curScan!=27 && curScan != 13);



Thx to anyone who read this...
To give credits where credits are due: EvilSOB's code example in a post here in this forum helped me get started with this...
© 2023 lite-C Forums