|
-
October 3rd, 2007, 09:30 PM
#1
Getting things to move around
I have to do a game for my class and we are required to take input from the keyboard in order to move things around. Mainly we will be using the arrow keys to shift an object to the left, right, and down.
Does anyone a function that will do this?
I was researching and came across GetAsyncKeyState, would this be a plausible choice and how can I implement it in code?
-
October 3rd, 2007, 10:38 PM
#2
Re: Getting things to move around
I assume you're working in Windows, since GetAsyncKeyState is a windows function (this is key to establishing context for an answer).
Typically, though, the method used is to respond to WM_KEYDOWN, WM_KEYUP or related (WM_SYSKEYxx) messages.
The GetAyncKeyState is, well, asynchronous. It has to be 'polled' - that is, repeated at timed intervals in order to catch transitions in the state of a key.
The message paradigm is better in that you receive a message for each of the key operations (one message for each key press or release).
There is no 'function' to perform here. This is more of a question of design or architecture. The answer requires even more context from you, because the means are different if you're using MFC or writing WinAPI code (or something else).
If you research key message processing within the context of your framework or API, you'll end up discovering the related code design and possibly the sample code that gives an otherwise completed example.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
-
October 4th, 2007, 12:13 AM
#3
Re: Getting things to move around
Hello,
A similar problem where images are moves using mouse is dealt in the FAQ How do I drag an image?. Moving things using keyboard is much simpler, where one has to handle WM_KEYUP / WM_KWYDOWN messages.
Regards,
Pravin.
-
October 4th, 2007, 12:25 AM
#4
Re: Getting things to move around
Just to add another possible solution to this, if you have the time and interest, I would suggest taking a look at DirectInput. It is pretty straightforward and easy to use, and even in tools or utilities made in MFC I often use it instead of windows messages for user input.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|