Jazz Posted January 12, 2017 Share Posted January 12, 2017 Is there a command to lock the cursor to the monitor the game is on? When you accidentally click on another screen it minimizes the game. Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
Ma-Shell Posted January 13, 2017 Share Posted January 13, 2017 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); 2 Quote Link to comment Share on other sites More sharing options...
Jazz Posted January 13, 2017 Author Share Posted January 13, 2017 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. Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
Rick Posted January 13, 2017 Share Posted January 13, 2017 I do. There are some annoyances using LE with it but I just deal with I guess. Quote Link to comment Share on other sites More sharing options...
Jazz Posted January 13, 2017 Author Share Posted January 13, 2017 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. Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 13, 2017 Share Posted January 13, 2017 You could check the mouse position boundries and place it back on the edge of the screen. Quote Link to comment Share on other sites More sharing options...
Jazz Posted January 13, 2017 Author Share Posted January 13, 2017 I already do that but the mouse still jumps off screen and back. Quote --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
Ma-Shell Posted January 13, 2017 Share Posted January 13, 2017 (edited) 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...? 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 January 13, 2017 by Ma-Shell 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted January 14, 2017 Share Posted January 14, 2017 I am getting a 4K monitor soon, so that might be a good time to test this out. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Einlander Posted January 14, 2017 Share Posted January 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.