Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Lock the mouse


  • Please log in to reply
4 replies to this topic
Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
I saw a shareware program that would do something like this so decided to make something similar in autohotkey.

It will lock the mouse in position unless the correct password is entered.

The mouse will be released with Ctrl-Alt-Delete although I did think about disabling that with something like this-

^!Del::

process, wait, taskmgr.exe, 5
process, close, taskmgr.exe

If another window becomes active the mouse will be released.

Alt-Tab, Win, Alt-F4 and the AppsKey have been disabled.

The script will sleep if the computer is idle for mare than 5 seconds to reduce the CPU load. the CPu is at about 20% when the user is moving the mouse but then goes down to 0% 5 seconds after they stop moving it.

;Requires Windows 2000 / XP and the latest version of Autohotkey (1.0.32+)
;
;This script will lock the mouse and only entering a password will release it
;
;Ctrl-X or Ctrl-Alt-Delete will release the mouse in an emergency

;Set Password here if you don't want to be prompted each time

Password=

Gui, -caption +alwaysontop
Gui, Add, Button, x16 y10 w50 h30 gTrap, Lock
Gui, Add, Button, x76 y10 w50 h30 gFree, Release

Gui, Add, Edit, x18 y65 w110 h20 Password vGuessedPassword, 
Gui, Add, Text, x17 y49 w111 h15, Enter Password below:

Gui, Show, h98 w146, Lock the Mouse

GuiControl, Disable, Release
GuiControl, Disable, Edit1

Return

GuiClose:
ExitApp

Trap:

breakloop=n
incorrectpasswords=0

GuiControl, Disable, Lock
GuiControl, Enable, Release

WinGetPos, X, Y, Width, Height, Lock the Mouse

Y+=%Height%
X-=65

if Password=
InputBox, Password, Set Password, Enter the password that will free the mouse, HIDE, 270, 120, %X%, %Y%

if errorlevel<>0
{
GuiControl, Enable, Lock
GuiControl, Disable, Release
return
}

GuiControl, Enable, Edit1

winactivate,  Lock the Mouse

loop
{

;if greater than 30 seconds idle the sleep to save CPU cycles

if A_TimeIdle > 5000
{
sleep, 500
}

if breakloop=y
break

MouseGetPos, OutputVarX, OutputVarY, Win

if OutputVarX > 145
{
blockinput, on
MouseMove, 145, %OutputVarY%, 0
sleep, 50
blockinput, off
}

if OutputVarX < 0
{
blockinput, on
MouseMove, 0, %OutputVarY%, 0
sleep, 50
blockinput, off
}

if OutputVarY > 96
{
blockinput, on
MouseMove, %OutputVarX%, 96, 0
sleep, 50
blockinput, off
}

if OutputVarY < 0
{
blockinput, on
MouseMove, %OutputVarX%, 0, 0
sleep, 50
blockinput, off
}

WinGetTitle, TitleUnderMouse, A

if TitleUnderMouse <> Lock the Mouse
break

}

return

Free:

blockinput, Mouse

gui, submit, nohide

ControlSetText, Edit1, , Lock the Mouse

if GuessedPassword = %Password%
{
GuiControl, Enable, Lock
GuiControl, Disable, Release
breakloop=y
GuiControl, Disable, Edit1
}
else
{
ControlSetText, Static1, Incorrect Password, Lock the Mouse
sleep, 500
ControlSetText, Static1, Enter Password below, Lock the Mouse

incorrectpasswords+=1
}

return

^x::
Exitapp

!Tab::
!F4::
LWin::
RWin::
Appskey::
return


enrica
  • Members
  • 117 posts
  • Last active: Feb 26 2016 11:15 PM
  • Joined: 21 Mar 2005
Hi, very good!

Can block Winkey and Appkey too?
Thank you!

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Thanks enrica,

I have just changed the script to disable the appskey and windows key.

I've also removed the tooltip. The error message for the incorrect password will now appear on the GUI itself. I found that when the tooltip appeared, it released the mouse temporarily.

fatalanth
  • Members
  • 14 posts
  • Last active: Sep 13 2007 07:32 AM
  • Joined: 30 Aug 2007
can somone modify this to activate after a 2 minute idle and closes the little window when you enter the password and resets the idle timer

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I don't get it... it's easy to move the mouse away from the GUI, and click on another window. As soon as you do, the script stops resetting the mouse position. :? This is much more effective:
BlockInput, MouseMove
The MouseMove parameter was added in v1.0.43.11 (a year after the script was posted.)

Since I'm not sure exactly what the script is supposed to do, I won't tell you how to edit it. To do something after 2 minutes of idle, put this in the auto-execute section:
SetTimer, IdleCheck, 1000
and this elsewhere:
IdleCheck:
    if (A_TimeIdlePhysical > 120000) {  ; idle for 120 seconds (2 minutes)
        if (!IsIdle) {  ; prevent re occurrence while remaining idle
            IsIdle := true
            gosub Idling
        }
    } else
        IsIdle := false
return

Idling:
    ; do stuff here
    SoundPlay, *-1
return