Jump to content

Setting Mouse Boundries and Window Borders


Christopher Blue
 Share

Recommended Posts

Ah darn I guess I spoke too soon: the cursor's clipping area keeps getting reset.  I will try to fix that somehow in my program.

In the meantime, how can I use AutoIt to kill a process that doesn't have a window?  (I start my MouseTrap.exe in hidden window mode).

<{POST_SNAPBACK}>

ProcessClose()

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I would sleep only as long as needed to keep the CPU from going haywire.

<{POST_SNAPBACK}>

In other words use a loop to loop through it and sleep at the bottom of the loop about Sleep(10) is what I have always been told.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Here is my finished script and C++ programs:

MouseTrapToggle.au3:

Opt("WinTitleMatchMode", 3)
Opt("MouseCoordMode", 0)

$rest = 2147483647
$hotkey = "{F1}"
$Trapped = 0
$MouseTrapFN = "MouseTrap.exe"
$MouseUnTrapFN = "MouseUnTrap.exe"

HotKeySet($hotkey, "ToggleTrap")

While (1)
    Sleep($rest)
WEnd

Func ToggleTrap()
    If $Trapped Then
        ProcessClose($MouseTrapFN)
        Run($MouseUnTrapFN, "", @SW_HIDE)
    Else
        Run($MouseTrapFN, "", @SW_HIDE )
    EndIf
    $Trapped = NOT $Trapped
EndFunc

MouseTrap.exe:

#include <Windows.h>

int main ()
{
    RECT rcClip;

    rcClip.left = 0;
    rcClip.top = 0;
    rcClip.right = 1024;
    rcClip.bottom = 768;

    ClipCursor(&rcClip); 

    while (1)
    {
        Sleep(5);
        ClipCursor(&rcClip);
    }

    return 0;
}

MouseUnTrap.exe:

#include <Windows.h>

int main ()
{
    RECT rcClip;

    rcClip.left = 0;
    rcClip.top = 0;
    rcClip.right = 2048;
    rcClip.bottom = 768;

    ClipCursor(&rcClip);

    return 0;
}
Edited by Christopher Blue
Link to comment
Share on other sites

Here is the script to remove the borders (really really fucking cool...thanks Larry!). It then resizes the window to fit the desktop and moves it into the upper-left hand corner. It also uses a hotkey to allow quick hiding/unhiding of the window.

Window Movement and Resize.au3:

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 3)

Global $GWL_STYLE = -16
$window_name = "Warcraft III"
$hidden = 0
$hotkey = "^q"
$rest = 2147483647

HotKeySet($hotkey, "ToggleWindowHide")

;Remove the window borders
$hWnd = WinGetHandle($window_name)

$OldStyle = DLLCall( "user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE )
If @error Then Exit
$OldStyle = $OldStyle[0]

$NewStyle = BitAND($OldStyle,BitNOT($WS_DLGFRAME) )
$NewStyle = BitAND($NewStyle,BitNOT($WS_THICKFRAME) )
$NewStyle = BitAND($NewStyle,BitNOT($WS_BORDER) )

DLLCall( "user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", $NewStyle )

; Move the Window into postion and resize it
WinMove($window_name, "", 0, 0, 1024, 768)

; Wait for hotkey input
while (1)
    Sleep ($rest)
WEnd

; Hides/Unhides window
Func ToggleWindowHide()
    If ($hidden) Then
        WinSetState ($window_name, "", @SW_SHOW)
    Else    
        WinSetState ($window_name, "", @SW_HIDE)
    EndIf
    $hidden = NOT $hidden
EndFunc

Between this script and the mouse clipping script, one can enjoy all of the advantages of full-screen mode *and* windowed mode!

Edited by Christopher Blue
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

  • Recently Browsing   0 members

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