HandleKeys( ) Function not working...

Started by
5 comments, last by AAAP 18 years, 4 months ago
When I try to make a program with the HandleKeys() function it says it is undeclared... what I would like to know is what library are the functions for user input in? ie HandleKeys(), WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc.
Advertisement
ah, I believe those would be the windows API mouse buttons, but i don't really know. lemme just check real quick here..

I was right. Okay, heres what it is. If you wanna do keyboard handling, what you're looking for is

WM_KEYDOWN( key )

and WM_KEYUP( key )

where KEYDOWN is what should happen if key is down, and KEYUP is what should happen if key is up.

typically, what you should do, is have an array of keys like bool keys[256]

and do WM_KEYDOWN( key )
{
keys[key] = true;
}
WM_KEYDOWN( key )
{
keys[key] = false;
}

then, have another function which handles what to do when a certain key is true, that you run every frame.

if you want, i can post some code that works really well for handling keyboard input. mouse input works similarly.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
I have the code already for the handling of keystrokes, and it looks alot like what you said. Unfortunately it all starts at HandleKeys(), so all I need is the library that supports this function.

[Edited by - KingSatchmo on November 27, 2005 12:40:05 AM]
Also I made a mistake in saying what it was saying was undeclared... it wasn't WM_LBUTTONDOWN and WM_RBUTTONDOWN that it said was undeclared, it was MouseButtonDown(), etc. Here is my code in the game engine:
(HandleEvent Switch-case)
Quote:
case WM_LBUTTONDOWN:
// Handle left mouse button press
MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;

case WM_LBUTTONUP:
// Handle left mouse button release
MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;

case WM_RBUTTONDOWN:
// Handle right mouse button press
MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
return 0;

case WM_RBUTTONUP:
// Handle right mouse button release
MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
return 0;

case WM_MOUSEMOVE:
// Handle mouse movement
MouseMove(LOWORD(lParam), HIWORD(lParam));
return 0;

And also:
(in WinMain)
Quote:
iTickCount = GetTickCount();
if (iTickCount > iTickTrigger)
{
iTickTrigger = iTickCount +
GameEngine::GetEngine()->GetFrameDelay();
HandleKeys();
GameCycle();
}


And here are the bugs it comes up with:
Quote:
C:\Dev-Cpp\Practice\New Folder\GameEngine.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
54 C:\Dev-Cpp\Practice\New Folder\GameEngine.cpp `Handlekeys' undeclared (first use this function)
C:\Dev-Cpp\Practice\New Folder\GameEngine.cpp In member function `LRESULT GameEngine::HandleEvent(HWND__*, UINT, WPARAM, LPARAM)':
189 C:\Dev-Cpp\Practice\New Folder\GameEngine.cpp `MouseButtonDown' undeclared (first use this function)
194 C:\Dev-Cpp\Practice\New Folder\GameEngine.cpp `MouseButtonUp' undeclared (first use this function)
209 C:\Dev-Cpp\Practice\New Folder\GameEngine.cpp `MouseMove' undeclared (first use this function)
C:\Dev-Cpp\Practice\Makefile.win [Build Error] ["New Folder/GameEngine.o"] Error 1



Please help! All I need is a library!
did you get that from an example on a web page or something?

it certainly isn't SDL, i havn't looked at allegro, doesnt look like direct X, my guess is the author just implemented functions with those names?

LOWORD(lParam) and HIWORD(lParam) for example, are probably mouse coordinates stored in byte form with like the X in the low bits and Y in the high bits, im just guessing cuz i dont know windows that good, but it seems likely, and false / true SEEMS to signify if its left or right thats being clicked.

that said, the function implemented at MouseButtonDown etc is probably like figure out the coordinates based on loword and hiword of lParam, and which button were talking about.

in short, they probably aren't from any library, the author just made them himself.

(but this is all based on the assumption that you got the code from an example site)

[Edited by - AAAP on November 27, 2005 8:31:07 PM]
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)
Yes I did get it from a book's example CD... I copy and pasted it into my "Practice" file that I use to stick stuff into to experiment with. When I try to run his program in its entirety (spelling?) it is chock full of bugs... I guess I need to find a new way to "handle" key presses and mouse presses...
tommorow when I'm back from school, I'll look that mouse stuff up on MSDN, i'm pretty sure I know how you can implement that, and it will probably be a lot faster than GLUT's mouse stuff -_-.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)

This topic is closed to new replies.

Advertisement