Advertisement

WM_KEYDOWN

Started by November 10, 2000 11:17 PM
7 comments, last by Peon 24 years, 2 months ago
I was reading TOTWPG and I came across a cool command: WK_KEYDOWN. I was previosly using WM_CHAR, but in my 2 player pong_clone, it couldn''t take input from both people at the same time. So the book said if I wanted to use the character keys, I had to define them or something. Only thing is, I don''tt know how to do that. Any ideas?
Peon
GetAsyncKeyState is what you want to use
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winui/keybinpt_1x0l.htm
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Use something like this:

    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)//Then, all you have to do is call:if(KEY_DOWN(VK_UP))    //Do something...  


The VK_codes are listed somewhere in the MSDN..

Edited by - Quantum on November 11, 2000 2:11:27 AM
Look at DirectInput. Its easy to set up and use, and faster than windows messaging.
jumble-----------
I considered DirectInput, but I''m not good enough yet, hehe

Just to clarify, I can do the arrow keys and stuff, but when I said character keysI meanthow would I know if someone hit ''a'' or ''b''? Sorry, shoulda been more specific
Peon
You said it yourself... ''a'' or ''b''.
Thats all you need.. although you might want to check if its ''A'' || ''a'' in case they''re holding shift down or caps is on or something like that.
Advertisement
Actually, that''s the problem, maybe I''m just being dense I don''t know how to check for hitting ''a'' or ''b''. If I want to check the up arrow, I do VK_UP and it works. Same with VK_DOWN. But when I do:

  #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)if (KEYDOWN(VK_A))	{                // Test		MessageBox(NULL, "a", "a", MB_OK);	}  


... the compiler says

c:\developer\pong\sourc_code.cpp(197) : error C2065: ''VK_A'' : undeclared identifier

Peon
Aha yeah. What you should do is just

if (KEY_DOWN(''A''))
{
//do stuff
}


You will still want to use WM_KEYDOWN though, because if you are writing a highscores table for instance, or an "Enter Name" screen, you don''t want to do

if (KEY_DOWN(''A''))
next_letter = ''A'';

if (KEY_DOWN(''B''))
next_letter = ''B'';

you want to do something like this:

case WM_KEYDOWN:
next_letter = wParam;

Don''t mean to patronise or anything just sometimes it''s best to use the standard windows messaging
Yeah, wise_Guy said what I meant I should have explained it better.

This topic is closed to new replies.

Advertisement