Jump to content

Mouse barrier script help.


Recommended Posts

I've been trying to get this script working which was written for me by somebody who i can no longer contact.

There are two issues i would like to change.

The first one i assume is easy, i want a hotkey to turn it on and off on the fly without closing the process.

And the second one is a bug where if you move your mouse along the X axis and run into the wall, the mouse will teleport to the opposite side. Which is causing me some problems.

$enabled = True

$cx = 1920/2;
$cy = 1080/2;

$r = 150;
$pi = 3.14159265358979

While True
   if $enabled Then
      $pos = MouseGetPos();
      $dist = Sqrt(($pos[0]-$cx)^2 + ($pos[1]-$cy)^2);
      if $dist > $r Then
         $angle = atan(($cx-$pos[0]) / ($cy-$pos[1]));
         
         $x = $r*Sin($angle);
         $y = $r*Cos($angle);
         
         if $pos[1] >= $cy Then
            $x = $cx + $x; 
            $y = $cy + $y;
         Else
            $x = $cx - $x; 
            $y = $cy - $y;
         EndIf
         
         MouseMove ( $x, $y, 0 );
         ToolTip($x&","&$y,900,5);
      EndIf
   Else
      Sleep(1000)
   EndIf
WEnd

If anybody could give me a hand that would be fantastic.

Link to comment
Share on other sites

This code is modified example code of both the HotKeySet and _MouseTrap functions. It has a 'pause' ability, and 'mouse barrier' 50 pixels from the 4 edges of the screen. Refer to the help file for details about either of the functions used here.

 

Welcome to the Forum! :graduated:

#include <GUIConstantsEx.au3>
#include <Misc.au3>

Global $Paused

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

_Main()

Func TogglePause()
    _MouseTrap()
    $Paused = Not $Paused
    While $Paused
     Sleep(100)
     ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
    _Main()
EndFunc   ;==>TogglePause

Func Terminate()
    _MouseTrap()
    Exit 0
EndFunc   ;==>Terminate

Func _Main()
    Local $coords[4]

    While 1
    $coords = WinGetPos("Program Manager")
        _MouseTrap($coords[0] + 50, $coords[1] + 50, $coords[0] + $coords[2] - 50, $coords[1] + $coords[3] - 50)
    Sleep(10)
    WEnd
EndFunc   ;==>_Main
Edited by somdcomputerguy

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

Link to comment
Share on other sites

Probably not, that other code confuses me. Most of my projects have simply been modified snips from the help file examples. I'm sure that someone else may be able to offer more assistance. Make sure you read this before you post anymore though.. http://www.autoitscript.com/forum/index.php?app=forums&module=extras&section=boardrules

Good luck!

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

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...