3 Replies - 7101 Views - Last Post: 11 September 2007 - 03:59 PM Rate Topic: -----

#1 taure  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-September 07

Keyboard handling?

Post icon  Posted 09 September 2007 - 03:15 AM

I'm preparing to make my first game (C/winapi) and I'm wondering how to code the keyboard stuff. I'd like to let two players use keyboard at the same time but it seems to me that WM_KEYDOWN case can't handle multiple key strokes. I tried to use the ASyncKeyState function but the compiler doesn't recognize it (is it C++ only?)

Code... Well, if I have to... :/

That works, but not in a way I'd like to:
case WM_KEYDOWN:
  switch(wParam) {
	case 40:
	  x=x+1;
	  break; 
	case 38:
	  x1=x1+1;
	  break;
  }break;


And this doen't work at all (compiler error "undefined reference to")
case WM_TIMER: {
  if(ASyncKeyState(40)) x=x+1;
  if(ASyncKeyState(38)) x1=x1+1;
  InvalidateRect(hwnd,&rc,1);
}break;


btw I know that this code doen't make any sense, I just want to show the method I used.

Is This A Good Question/Topic? 0
  • +

Replies To: Keyboard handling?

#2 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Keyboard handling?

Posted 09 September 2007 - 05:18 AM

You are not using the right function.
The API Function is GetAsyncKeyState() and not AsyncKeyState()
:)
Was This Post Helpful? 0
  • +
  • -

#3 Apples  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 15-November 06

Re: Keyboard handling?

Posted 11 September 2007 - 03:28 PM

also, i don't think you use brackets for a case in a switch/case.
Was This Post Helpful? 0
  • +
  • -

#4 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Keyboard handling?

Posted 11 September 2007 - 03:59 PM

The WinAPI is a C library.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1