Jump to content

A fun little example using MouseTrap


anthonyjr2
 Share

Recommended Posts

Hey everyone,

Since I haven't yet created anything that isn't specific to my job, and haven't ever posted any examples, I figured I would share this little script I made a while ago for fun between projects.

#include <GUIConstants.au3>
#include <Misc.au3>
HotKeySet("{F9}", "Start")
HotKeySet("{ESC}", "Stop")

Func Start()
    Local $hGUI = GUICreate("Transparent GUI", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
    Local $i,$j
    GUISetBkColor(0)
    WinSetTrans($hGUI, "", 50)
    GUISetState(@SW_SHOW, $hGUI)

    For $i=0 To 1040 Step 1
        _Middle($hGUI, "", @DesktopWidth-$i, @DesktopHeight-$i)
        $winCoord = WinGetPos($hGUI)
        _MouseTrap($winCoord[0],$winCoord[1],($winCoord[0] + $winCoord[2])-5,($winCoord[1] + $winCoord[3])-5)
    Next

    For $j=0 to 840 Step 1
        _Middle($hGUI, "", @DesktopWidth-$i-$j, @DesktopHeight-$i)
        $winCoord = WinGetPos($hGUI)
        _MouseTrap($winCoord[0],$winCoord[1],($winCoord[0] + $winCoord[2])-5,($winCoord[1] + $winCoord[3])-5)
    Next

    ToolTip("Your mouse has been trapped!", @DesktopWidth/2-80,@DesktopHeight/2+22)

    While 1
        Sleep(10)
    WEnd

EndFunc   ;==>


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _Middle($win, $txt, $width=-1, $height=-1)
    If $width >= 0 Or $height >= 0 Then
        Local $aWin = WinGetPos($win)
        If $width < 0 Then $width = $aWin[2]
        If $height < 0 Then $height = $aWin[3]
        WinMove($win, $txt, $aWin[0], $aWin[1], $width, $height) ; first winmove
    EndIf
    Local $size = WinGetClientSize($win, $txt)
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
    Return WinMove($win, $txt, $x, $y) ; second winmove
EndFunc   ;==>_Middle

Func Stop()
    _MouseTrap()
    Exit
EndFunc   ;==>Stop

It creates a transparent GUI that slowly shrinks, trapping your mouse inside! I created it after discovering the _MouseTrap() function in the helpfile and the idea floated into my head. It has no real purpose other than entertainment. I figured between all of the serious scripts we use here a little fun is always a nice break :D

F9 to start, ESC to exit at any time.

If this is against the rules feel free to remove it, I didn't see any place this would fall under.

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...