Jump to content

Recommended Posts

Posted

I'm trying to write a script that will get the size of a window and set _MouseTrap() to keep the mouse within the window. My code so far is:

#include <Misc.au3>
HotKeySet("{END}", "Quit")
HotKeySet("{PGUP}", "Enable")
HotKeySet("{PGDN}", "Disable")
While 1
WEnd
Func Enable()
    $Pos = WinGetPos("")
    _MouseTrap($Pos[0], $Pos[1], $Pos[2], $Pos[3])
EndFunc
Func Disable()
    _MouseTrap()
EndFunc
Func Quit()
    Exit
EndFunc

The left and top works fine, but the right and bottom are off. I've tried on several windows and still the same result. Any suggestions?

My scripts: Random Painter

Posted (edited)

#include <Misc.au3>
HotKeySet("{END}", "Quit")
HotKeySet("{PGUP}", "Enable")
HotKeySet("{PGDN}", "Disable")
While 1
WEnd
Func Enable()
    $Pos = WinGetPos("")
    _MouseTrap($Pos[0], $Pos[1], $Pos[0]+$Pos[2], $Pos[1]+$Pos[3])
EndFunc
Func Disable()
    _MouseTrap()
EndFunc
Func Quit()
    Exit
EndFunc
Edited by Generator
Posted

Hmmm!!!...???

Works for me!!

#include <Misc.au3>

Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client

Dim $enable

HotKeySet("{END}", "Quit")
HotKeySet("{PGUP}", "Enable")
HotKeySet("{PGDN}", "Disable")

While 1
    Sleep(20)
    If $enable Then
        $Pos = WinGetPos("")
        _MouseTrap($Pos[0], $Pos[1], $Pos[0]+$Pos[2], $Pos[1]+$Pos[3])
    EndIf
WEnd

Func Enable()
    $enable = 1
EndFunc   ;==>Enable

Func Disable()
    $enable = 0
    _MouseTrap()
EndFunc   ;==>Disable

Func Quit()
    Exit
EndFunc   ;==>Quit

8)

NEWHeader1.png

Posted (edited)

And this:

#include <Misc.au3>
HotKeySet("{END}", "Quit")
HotKeySet("{PGUP}", "Enable")
HotKeySet("{PGDN}", "Disable")
While 1
    Sleep(100)
WEnd
Func Enable()
    $Pos = WinGetPos("")
    _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
EndFunc   ;==>Enable
Func Disable()
    _MouseTrap()
EndFunc   ;==>Disable
Func Quit()
    Exit
EndFunc   ;==>Quit

... is working fine for me. :P

EDIT: Posted wrong code.

Edited by CyNDeR

My scripts: Random Painter

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...