Jump to content

Recommended Posts

Posted (edited)

A click on the button has no effect, but if I hit the space bar on it, it works fine. Apart from this 'quirk', everything else in the script works fine. I've set $Button1 as a Global var too, to no avail.. This has got me stumped.. I think some AutoIt god is messing with me because the script is titled 'Mouse Trap'..

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ClipBoard.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)
TraySetIcon("mouse.ico")

Global $coords
Local $GUI, $Label1, $Button1

If _Singleton("Mouse Trap", 1) = 0 Then
    MsgBox(0, "Warning", "Mouse Trap is already running", 3)
    Exit
EndIf

If $CmdLine[0] > 1 And @Compiled Then
    $GUI = GUICreate("Mouse Trap", $CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4])
Else
    $GUI = GUICreate("Mouse Trap", 400, 300)
EndIf

GUISetIcon("mouse.ico")

$Label1 = GUICtrlCreateLabel("ESC - Exit, 2x if Started" & @LF & @LF & _
"F10 - Start" & @LF & @LF & _
"Up, Down, Left, Right - Resize" & @LF & @LF & _
"(Control + Shift) Up, Down, Left, Right - Move", 10, 20, 250, 500)

$Button1 = GUICtrlCreateButton(" Copy Coords ", 10, 125, 85, 30)

GUISetState()

Main()

Func Main()
    HotKeySet("{F10}", "Start")
    HotKeySet("{UP}", "WidthHeight")
    HotKeySet("{DOWN}", "WidthHeight")
    HotKeySet("{LEFT}", "WidthHeight")
    HotKeySet("{RIGHT}", "WidthHeight")
    HotKeySet("^+{UP}", "WidthHeight")
    HotKeySet("^+{DOWN}", "WidthHeight")
    HotKeySet("^+{LEFT}", "WidthHeight")
    HotKeySet("^+{RIGHT}", "WidthHeight")
    WinSetTrans("Mouse Trap", "", 180)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button1
                $coords = WinGetPos($GUI)
                _ClipBoard_SetData ($coords[2] & " " & $coords[3] & " " &  $coords[0] & " " & $coords[1])
        EndSwitch
    Wend
EndFunc

Func WidthHeight()
    $coords = WinGetPos($GUI)
    Switch @HotKeyPressed
        Case "{UP}"
            WinMove("Mouse Trap", "", default, default, default, $coords[3] - 5)
        Case "{DOWN}"
            WinMove("Mouse Trap", "", default, default, default, $coords[3] + 5)
        Case "{RIGHT}"
            WinMove("Mouse Trap", "", default, default, $coords[2] + 5, default)
        Case "{LEFT}"
            WinMove("Mouse Trap", "", default, default, $coords[2] - 5, default)
        Case "^+{UP}"
            WinMove("Mouse Trap", "", default, $coords[1] - 5, default, default)
        Case "^+{DOWN}"
            WinMove("Mouse Trap", "", default, $coords[1] + 5, default, default)
        Case "^+{RIGHT}"
            WinMove("Mouse Trap", "", $coords[0] + 5, default, default, default)
        Case "^+{LEFT}"
            WinMove("Mouse Trap", "", $coords[0] - 5, default, default, default)
    EndSwitch
EndFunc

Func Start()
    HotKeySet("{F10}")
    HotKeySet("{UP}")
    HotKeySet("{DOWN}")
    HotKeySet("{LEFT}")
    HotKeySet("{RIGHT}")
    HotKeySet("^+{UP}")
    HotKeySet("^+{DOWN}")
    HotKeySet("^+{LEFT}")
    HotKeySet("^+{RIGHT}")
    WinSetTrans("Mouse Trap", "", 0)
    $coords = WinGetPos($GUI)
    While 1
        _MouseTrap($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3])
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    _MouseTrap()
    Main()
EndFunc
Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Posted (edited)

Your label is covering up the button.

Set 500 to 105 or less.

Edit: Damn code tags.

Edited by Deltaforce229

[size="1"]Please stop confusing "how to" with "how do"[/size]

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...