Author Topic: Lock cursor to game window (WORKING SOLUTION)  (Read 14173 times)

Offline DesiQ

  • Newbie Mark II
  • *
  • Posts: 24
Lock cursor to game window (WORKING SOLUTION)
« on: April 26, 2012, 07:47:06 am »
AVWW is unable to lock the cursor to its own screen during full-screen play, which means that people with multi-monitor displays can minimise the game by accidentally clicking outside the game window during heated battles.

I've made a script using Autohotkey that locks the cursor inside the game window, and makes the system ignore any clicks placed outside it. Just download it and run the .exe appropriate to your in-game resolution in the background while you play the game.

Right now the pacakge comes with executables supporting screen widths of 1920 and 1024. Just post here if you need a different width and I'll upload it. You can also edit the included source (AVWW Mousekeeper.ahk) yourself if you'd like, but you'll need to install Autohotkey separately if you want to run a raw .ahk file. The script now runs for all resolutions, even if AVWW isn't running at your desktop's resolution. If you change AVWW's resolution while the script is running, just hit Delete to recapture the cursor.

Download AVWW MouseKeeper v2
Remember to read the readme!
« Last Edit: April 27, 2012, 06:00:26 am by DesiQ »

Offline Mánagarmr

  • Core Member Mark V
  • *****
  • Posts: 4,272
  • if (isInRange(target)) { kill(target); }
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #1 on: April 26, 2012, 08:58:02 am »
Nice! Yeah, that Unity limitation is rather frustrating.
Click here to get started with Mantis for Suggestions and Bug Reports.

Thank you for contributing to making the game better!

Offline mrhanman

  • Hero Member Mark II
  • *****
  • Posts: 764
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #2 on: April 26, 2012, 03:04:53 pm »
Sweet! I've lost more than one character to this issue.

Offline DesiQ

  • Newbie Mark II
  • *
  • Posts: 24
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #3 on: April 26, 2012, 08:57:53 pm »
I've made a quick fix to the script that stops it from autofiring left-click, which was an unintended side effect and very bad in the game's menus. Just redownload.

Offline Quaix

  • Jr. Member Mark II
  • **
  • Posts: 75
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #4 on: April 27, 2012, 03:57:14 am »
I couldn't figure out why Desi used a timer so I made my own version.
Took me a while to get it to work to my satisfaction, so I thought I'd share it.
How it's different from Desi's is that it doesn't try to lock the mouse to the game screen, but any clicks outside the game are sent into the game (only time it moves the mouse). Works for both left and right mouse buttons. No configuration needed.
Should work for other games too, if you change the #IfWinActive part.

Here's the readme:

Prevents clicks in AVWW outside the screen in multi monitor setups
Designed to work with the game running on your primary monitor and in full screen mode
Windows Key + Backspace to terminate script or right click on the icon in system tray and click 'Exit'
Script executes only when AVWW is running and active
You can place the script in your windows startup folder and have it running 24/7 without it affecting your computer performance in any way
No configuration necessary

Download AVVV MouseLock here.

Offline DesiQ

  • Newbie Mark II
  • *
  • Posts: 24
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #5 on: April 27, 2012, 04:50:54 am »
Hey, another AHKer! Your script works very well. :D

My script is actually a tailored version of a more general script for capturing and limiting cursor traverse (unsurprisingly called MouseKeeper). MouseKeeper's primary goal was to simulate a hard boundary on the edge of the screen, which is accomplished by constantly checking where the cursor is and moving back if it strays, hence the fast-iterating timer.

This is a very useful thing to have in games that aren't AVWW. A very broad example would be any game that has a top-down camera angle, since moving the mouse towards the edges of the screen in these games often pans the camera; if the game doesn't capture the cursor, then it means that you won't be able to pan the camera in the direction of your secondary/tertiary monitor. Forcing the cursor to sit on the edge of the screen instead of allowing it to wander off makes this game feature work again.

P.S. Thanks for reminding me about A_ScreenWidth.
« Last Edit: April 27, 2012, 05:15:19 am by DesiQ »

Offline Quaix

  • Jr. Member Mark II
  • **
  • Posts: 75
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #6 on: April 27, 2012, 05:28:09 am »
Ah, I've ran into games like that and didn't think of using AHK to fix it. AVWW seems to be a special case where the 'hard boundary' isn't needed.

By the way, I thought your site looked familiar. I've been to it before when trying to google for a minecraft remap mod. Unfortunately it wasn't a problem I could fix with AHK -- one of the modifier keys was hardcoded.

Offline DesiQ

  • Newbie Mark II
  • *
  • Posts: 24
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #7 on: April 27, 2012, 06:05:46 am »
What modifier for Minecraft?

I did things a bit differently to your script. Your script assumes that people are running AVWW at the same res as their desktop, which may not be true. I used WinGetPos to get the window's width instead, sticking it into a label to run automatically once, and on demand afterwards.

Code: [Select]
GetWinSize:
WinGetPos,,, raw_width
screen_width := raw_width-5
return

#IfWinActive, AValleyWithoutWind
{

*LButton::
if screen_width_found = 0
{
Gosub GetWinSize
screen_width_found = 1
}
blahblah
return

Delete::GoSub GetWinSize
}

Offline Quaix

  • Jr. Member Mark II
  • **
  • Posts: 75
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #8 on: April 27, 2012, 06:58:19 am »
Quote
What modifier for Minecraft?

You know, it's been a while that I don't remember exactly which keys were bothering me. I recall remapping them with AHK, which remapped them in chat as well, so every time I typed something I had to use another keybind to pause my script. It worked, but I wanted a better solution. The modmacros mod for minecraft did exactly what I wanted.

Quote
Your script assumes that people are running AVWW at the same res as their desktop, which may not be true.

I just tried it, and A_ScreenWidth and A_ScreenHeight have the correct dimensions when the game is running in full screen, even if it's different than the desktop resolution.  Are you trying to lock the mouse to the game when it's in windowed mode as well? 

Offline DesiQ

  • Newbie Mark II
  • *
  • Posts: 24
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #9 on: April 27, 2012, 05:32:55 pm »
Oh maybe it's because I'm running CoordMode relative to the screen and not relative to the active window. That was necessary for me since if it was relative to windows, then basic MouseKeeper would trigger in folder windows, browser windows etc.

Offline Penumbra

  • Sr. Member Mark III
  • ****
  • Posts: 464
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #10 on: May 02, 2012, 10:12:53 am »
Can we move this to the "Mods" section?

Offline bvchaosinc

  • Newbie Mark III
  • *
  • Posts: 47
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #11 on: May 02, 2012, 10:19:41 am »
I don't want to crap on user contributions, but there's an app for this.

http://www.snakebytestudios.com/projects/apps/cursor-lock/

Offline tigersfan

  • Arcen Games Contractor
  • Arcen Staff
  • Master Member Mark II
  • *****
  • Posts: 1,599
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #12 on: May 02, 2012, 07:07:18 pm »
Just thought I'd let you guys know that this will hopefully not be needed for ver. 1.008! :)

Offline DesiQ

  • Newbie Mark II
  • *
  • Posts: 24
Re: Lock cursor to game window (WORKING SOLUTION)
« Reply #13 on: May 03, 2012, 04:21:18 pm »
I don't want to crap on user contributions, but there's an app for this.

http://www.snakebytestudios.com/projects/apps/cursor-lock/
Oh fancy! That works a lot better than AHK's ghetto way of capturing the mouse.

Just thought I'd let you guys know that this will hopefully not be needed for ver. 1.008! :)
And this is good news too. :3