Jump to content

Mouse and multiple monitors


Jazz
 Share

Recommended Posts

If you have the C++-version, you can use the windows-ClipCursor-function for this:

I recommend using the following in your App::Loop-function:

if(window->Active())
   ClipCursor(&window->rect);

 

Using the window->Active-condition will ensure that you only do this, if your window is actually focused (so when you alt-tab, your cursor won't be locked). Also note, that upon moving the window or switching to a different window, the locking will be void, which is why you should put this in the App::Loop instead of at the start of the game (it would be even better to register a callback for focusing and putting it there but I don't think, that will gain you that much performance to actually be worth the troubles).

I also noticed that window->rect is a bit off for me (strangely even the GetWindowRect-function returns this "false" rectangle). Also this includes the title-bar and the border. If you only want the area without the border (the so-called client-area), you can use the following chunk of code:

 

RECT r;
GetClientRect(window->hwnd, &r);
MapWindowPoints(window->hwnd, HWND_DESKTOP, (LPPOINT)&r, sizeof(RECT)/sizeof(POINT));
if(window->Active())
   ClipCursor(&r);

  • Upvote 2
Link to comment
Share on other sites

I'm using LUA. I should have stated that. Maybe something like this could be added to the engine.

Curious how many LW users have a multi-monitor setup.

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

use Window::Center flag when create window for ur application. this makes the app borderless nd stop minimizing ur game.

 

I need the mouse to stay on the game screen.

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

The main problem is that between frames, if you move the mouse fast enough, you might click somewhere out of the window. The only possible solution for this is to tell the operating system to do so, using the windows-API as I showed in the above code-snippet. So the only way to do so without C++-version is, if Josh adds a wrapper for my 2nd snippet above to the Leadwerks-library, and exposes it to LUA.

So Josh, please...? smile.png

 

Edit:

As a side-note: This does not only concern multi-monitor environments. If you have a non-fullscreen-window, this can happen to you on a single-monitor, as well, so I think many people might profit from a simple "trapMouseInContext"-function that does exactly what I've demonstrated.

Edited by Ma-Shell
  • Upvote 1
Link to comment
Share on other sites

I've had this issue too. With 3 monitors twitch based gaming can become a pain. This code forcibly puts the mouse back in the windows active area. http://www.leadwerks.com/werkspace/topic/10211-trapping-the-mouse-to-the-current-window/

The only issue is, as already mentioned in this thread, that if you move the mouse fast enough you can click outside the window. Leadwerks will as usual keep polling for input.

 

The code is from when Leadwerks use to have an app.lua instead of main.lua.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...