Archived

This topic is now archived and is closed to further replies.

SCRUB

WM_CHAR hack ..need help

Recommended Posts

I am trying to take in text input (event driven style) with WM_CHAR, as this is suppose to take into account your keyboard and its refresh rate etc.. My problem is that _certain_ combinations of keys are bouncing. When I try and use the capital alphabet I get 3 times the characters I want ( AAA BBB etc ). Now either the WM_CHAR messages are slow to get to my WndProc and 3 come at once or the certain keys on the keyboard are bouncing and not waiting for the refresh/update settings (and acting like direct input or something). I made a HACK to get around this but im not happy with this. can someone look at this code and see if they can help my situation.
  
case WM_CHAR:
{
	if (wParam == 16 && (lParam & 0x80000000))	{	shift_pressed = false;	}
	if (wParam == 16 && !(lParam & 0x80000000))	{	shift_pressed = true;	}
			
	if (wParam == 0x7F)	console.AddInput (wParam);	// backspace

	if (wParam == 0x0D)	console.AddInput (wParam);	// return

	if (wParam == 0x20)	console.AddInput (wParam);  // space 


	////////////// HACK FOR BOUNCING  KEYS ///////////

if (shift_pressed && (lParam & 0x80000000))		// if these keys bounce

	{
		if (wParam >= 0x41 && wParam <= 0x5A)		// from A to Z

			console.AddInput (wParam);
	}
	else if (!shift_pressed && (lParam & 0x80000000))	// if these keys bounce

	{
	if (wParam >= 0x30 && wParam <= 0x39)		// from 0 to 9

		console.AddInput (wParam); 
	}
	///////////// END OF HACK ////////////////////////

if (shift_pressed)
	{
		If ( (wParam >= 0x21 && wParam <= 0x2b) ||	// from ! to + 

	      (wParam >= 0x3A && wParam <= 0x40) ||	// from : to @

		      (wParam >= 0x5B && wParam <= 0x60) ||	//  ^ and _

		     (wParam >= 0x7B && wParam <= 0x7E)   )	// from { to ~ 

			 console.AddInput (wParam);  
				
	}
	else if (!shift_pressed)
	{
		if ( (wParam >= 0x2C && wParam <= 0x2F) ||	// from '' to / 

         		      (wParam >= 0x3A && wParam <= 0x40) ||	// ; and = 

		      (wParam >= 0x5B && wParam <= 0x60) ||	// from [ to '' 

		      (wParam >= 0x61 && wParam <= 0x7A)   )	// from a to z 

		      console.AddInput (wParam);  
	}
}
  
there the hack waits for you to lift up the key (no bounce) rather than when I pushed the key down I''d get 3 letters !!!! all help is appreciated ...thanks.

Share this post


Link to post
Share on other sites
I'm not sure why you're recieving multiple characters, but this should work:

        
// Declared at the beginning of your window procedure...

char upper;
int count;

// Inside your message switch...

case WM_CHAR:
upper = (char)LOWORD (CharUpper ((LPTSTR)MAKELONG ((WORD)wParam, 0)));

for (count = 0; count < (int)LOWORD (lParam); count++)
{
if (((upper >= '!') && (upper <= 'Z')) ||
(upper == '^') || (upper == '_') ||
(upper == '\r') || (upper == '\b') || (upper == ' '))
{
console.AddInput (wParam);
}
}

return 0;
// Rest of window procedure...



Edit: mE no spel gud wen tired

Game: The Adventure (tm).
-------------------------


Edited by - RabidOcelot on January 15, 2002 4:37:31 AM

Edited by - RabidOcelot on January 15, 2002 4:40:26 AM

Share this post


Link to post
Share on other sites