Jump to content
  • Advertisement
Sign in to follow this  
billmason

Async mouse input

This topic is 3788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My game needs to get the position of the mouse to shoot. I am looking for a way that I can get the mouse position async like I do with the keyboard input. Below is the macro that grabs keydown events async:
#define KEYDOWN(vk_code)  ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

In the game run method:
if(KEYDOWN(VK_SPACE)
character.shoot();

I got this from another forum question and it works perfectly. Now I need the same thing with mouse input, right now it is very jerky and lags. For my game it needs to be very smooth. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
I have had problems with message loops when I had a key pressed and mouse moving at the same time. Its kind of a cheap hack, but running the message loop at a certain rate (300hz works for me) processes the messages that are clogged in the queue and makes the input much smoother.

Share this post


Link to post
Share on other sites
Quote:
Original post by billmason
My game needs to get the position of the mouse to shoot. I am looking for a way that I can get the mouse position async like I do with the keyboard input.
Below is the macro that grabs keydown events async:
*** Source Snippet Removed ***
In the game run method:
*** Source Snippet Removed ***
I got this from another forum question and it works perfectly. Now I need the same thing with mouse input, right now it is very jerky and lags. For my game it needs to be very smooth. Any ideas?
GetCursorPos?

Share this post


Link to post
Share on other sites
GetCursorPos is one way of doing it as stated above. (If you need an FPS style mouse control, you can call SetCursorPos after getting your mouse delta from GetCursorPos in order to fix the mouse to a point on screen) Make sure that if you use GetCursorPos, you setup your window such that the client area is the size that you originally defined as your window width and height, otherwise your GetCursorPos coordinates will include the window border.

Refer to: clicky


if(!p_fullscreen){
GetClientRect(*p_window,&client_rect);
MoveWindow(*p_window,
0, //Left edge
0, //Top Edge
window_width+(window_width-client_rect.right), //New Width
window_height+(window_height-client_rect.bottom), //New Height
TRUE);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Leo_E_49
GetCursorPos is one way of doing it as stated above. (If you need an FPS style mouse control, you can call SetCursorPos after getting your mouse delta from GetCursorPos in order to fix the mouse to a point on screen) Make sure that if you use GetCursorPos, you setup your window such that the client area is the size that you originally defined as your window width and height, otherwise your GetCursorPos coordinates will include the window border.

Refer to: clicky


if(!p_fullscreen){
GetClientRect(*p_window,&client_rect);
MoveWindow(*p_window,
0, //Left edge
0, //Top Edge
window_width+(window_width-client_rect.right), //New Width
window_height+(window_height-client_rect.bottom), //New Height
TRUE);
}
That's a terrible way to do it. You should use AdjustWindowRectEx to change the size of the window rect before creating the window.

It's also worth noting that GetCursorPos returns screen coordinates. If you want to convert that to coordinates relative to your window, you should use ScreenToClient.

Share this post


Link to post
Share on other sites
Ah thanks for the correction. First time I've ever seen that function before. Win32 code still gives me a headache these days...

Hey, while we're at it, you know any good books which deal with Win32 API stuff like this? I've been looking for something other than MSDN for this subject for years.

Share this post


Link to post
Share on other sites
Quote:
Original post by Leo_E_49

Hey, while we're at it, you know any good books which deal with Win32 API stuff like this? I've been looking for something other than MSDN for this subject for years.


It's called C# and .Net.

There are things which just can't be fixed, so moving on to better ones is the only solution.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!