Multi-Monitor Cursor Trap Fix

Other talk that doesn't fit elsewhere.
This is for General Discussion, not General chat.
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Multi-Monitor Cursor Trap Fix

Post by milo christiansen »

Just in case no one noticed trapping the cursor on the primary monitor of a multi-monitor computer is broken in the latest masters. This really does a number on edge scrolling so I decided to share a AutoIt script I made a long time ago to solve similar problems in other games.

WARNING PERSONAL USE CODE AHEAD

Personal use code is code written for the personal use of the coder, therefore it may be buggy, lack comments, or be written in a lazy manner.

Code: Select all

#Region-Splash-And-Icon---------------------------------------------------------
#AutoIt3Wrapper_Res_LegalCopyright=Copyright 2010-2011 by Milo Christiansen
#AutoIt3Wrapper_Res_Description=
#AutoIt3Wrapper_Res_Comment=
#AutoIt3Wrapper_Res_Fileversion=2.0
#AutoIt3Wrapper_Res_Field=Company|Double Click Technologies
#EndRegion-Splash-And-Icon------------------------------------------------------
;Header-Start-------------------------------------------------------------------
;
; AutoIt Version: 3.3.0.0
; Author:         Milo Christiansen
;
; Script Function:
;		
;
;Header-End---------------------------------------------------------------------

;Includes-Start-----------------------------------------------------------------

#Include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

;Includes-End-------------------------------------------------------------------

;Options-Start------------------------------------------------------------------

Opt("MustDeclareVars", 1)
Opt("TrayAutoPause",0)

;Options-End--------------------------------------------------------------------

;General-Declerations-Start-----------------------------------------------------

Dim $hDisplay

Dim $Count

; These coords define the area to trap the cursor in
; You will probably have to change these to fit your computer
Dim $ULX = 0
Dim $ULY = 0
Dim $BRX = 1280
Dim $BRY = 1024

;General-Declerations-End-------------------------------------------------------

;Input-Start--------------------------------------------------------------------

;Input-End----------------------------------------------------------------------

;Main-Script-Start--------------------------------------------------------------

_MouseTrap($ULX, $ULY, $BRX, $BRY)

;GUI
GUICreate("Mouse Restrictor v2", 234, 22, 0, 0, -1, $WS_EX_TOOLWINDOW)

$hDisplay = GUICtrlCreateLabel(" Mouse Confined to Primary Monitor", 1, 1, 232, 20, $SS_SUNKEN)
GUICtrlSetFont($hDisplay, 11, 400, 0, "Arial")

GUISetState()

_MouseTrap($ULX, $ULY, $BRX, $BRY)

;main loop
While 1
	Local $MSG = GUIGetMsg()
	Select
		Case $MSG = $GUI_EVENT_CLOSE
			; MouseTrap with no args untraps cursor
			_MouseTrap()
			Exit
		Case Else
			; This is called every few ms because any click ouside of a 
			; window owned be the calling aplication untraps the mouse.
			; if call frequently this is not apperent to the user
			If $Count > 20 Then $Count = 1 And _MouseTrap($ULX, $ULY, $BRX, $BRY)
			$Count += 1
	EndSelect
WEnd

;Main-Script-End----------------------------------------------------------------

;Function-Decleration-Start-----------------------------------------------------

;Function-Decleration-End-------------------------------------------------------
This script will likely need to be modified to work on your system. I added a few comments indicating the interesting spots.
consider this CC0
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
effigy
Regular
Regular
Posts: 1217
Joined: 22 Jan 2010, 03:21

Re: Multi-Monitor Cursor Trap Fix

Post by effigy »

Does AuotIt need to be installed to use this script? or does it just need to be saved as a certain file type?

Did you add a keystroke to end the script? I can't tell from the code above :(
This is why some features aren't implemented: http://forums.wz2100.net/viewtopic.php?f=30&t=7490&view=unread#p87241
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Multi-Monitor Cursor Trap Fix

Post by milo christiansen »

Yes and no

Yes, AutoIt needs to be installed, or you need a copy of autoit.exe at least. If you have Autoit installed then make sure the file is saved as a ".au3" file.

No, I did not add a hot-key and I don't plan to. If you want a hot-key look up... hotkeyset I think... in the AutoIt docs. Its a simple mod that would require minimal knowledge of AutoIt to add.
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
effigy
Regular
Regular
Posts: 1217
Joined: 22 Jan 2010, 03:21

Re: Multi-Monitor Cursor Trap Fix

Post by effigy »

groovy, thanks :D
This is why some features aren't implemented: http://forums.wz2100.net/viewtopic.php?f=30&t=7490&view=unread#p87241