Skip to main content
GameDev.net gamedev.net
🔒 Locked

win32 input handling

Started by Golf Mar 17, 2011 at 8:49 PM 4 replies 2.4k views
Original Post
Golf
Golf
I know that you use the Window Procedure to handle input but how can you do anything useful without needing global variables? If someone clicks the mouse then I can find out exactly where they clicked but the function that handles game information will need to not only have the position of the mouse click but also will at least need a pointer to a struct containing information about the game state. Is there any way of handling input without having to use a global variable?
wicked357
wicked357
You can use GetAsyncKeyState(key code) for input, I found it useful in creating my own input module. Here is the link to it at MSDN.
Golf
Golf

You can use GetAsyncKeyState(key code) for input, I found it useful in creating my own input module. Here is the link to it at MSDN.

That's all very well for keyboard input but there doesn't seem any way of changing the game state when a menu item is selected or the mouse is clicked. It will also make saving the game state very difficult as when someone clicks save on the menu there's no way to access the game state unless there is global variable.
Buckeye
Buckeye
how can you do anything useful without needing global variables?[/quote]
I often use a class that handles the window procedure and passes information as needed to other objects.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
wicked357
wicked357
It actual does handle mouse clicks in fact all 5 of my mouse buttons and you can use GetCursorPos(..) for mouse coordinates.
freeworld
freeworld
I use callbacks for my input. I have a separate window class that allows storing callback functors that are triggered by a specific windows message. ie my mouse class registers functions for the messages key up and key down, it then adjusts it's state based on what has happened. I like this method because I never have to update the input on my own. I can further register functors with the input class... such as UI responding when a mouse button has been pressed. rather than constantly checking every frame if the button has been pressed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.