GaryFrost Posted July 29, 2005 Share Posted July 29, 2005 (edited) Requires beta version #include <GuiConstants.au3> Opt("MustDeclareVars",1) Dim $GUI, $coords[4], $msg $GUI = GUICreate("Mouse Trap Example", 392, 323) GUISetState() While 1 $coords = WinGetPos($GUI) _MouseTrap($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3]) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd _MouseTrap() Exit UDF: ;=============================================================================== ; ; Description: _MouseTrap ; Parameter(s): $i_left - Left coord ; $i_top - Top coord ; $i_right - Right coord ; $i_bottom - Bottom coord ; User CallTip: _MouseTrap([$i_left = 0[, $i_top = 0[, $i_right = 0[, $i_bottom = 0]]]]) Confine the Mouse Cursor to specified coords. (required: <Misc.au3>) ; Author(s): Gary Frost (custompcs@charter.net) ; Note(s): Use _MouseTrap() with no params to release the Mouse Cursor ; ;=============================================================================== Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) If @NumParams == 0 Then DllCall("user32.dll", "int", "ClipCursor", "int", 0) Else If @NumParams == 2 And ($i_left > 0 Or $i_top > 0) Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $Rect = "int;int;int;int", $left = 1, $top = 2, $right = 3, $bottom = 4, $r $r = DllStructCreate($Rect) If @error Then Return -1 DllStructSetData($r, $left, $i_left) DllStructSetData($r, $top, $i_top) DllStructSetData($r, $right, $i_right) DllStructSetData($r, $bottom, $i_bottom) DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($r)) DllStructDelete($r) EndIf EndFunc ;==>_MouseTrap Edited August 1, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted July 31, 2005 Author Share Posted July 31, 2005 Looking at possibly adding this into UDFs, if there is enough people interested in this function being added. Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
FuryCell Posted July 31, 2005 Share Posted July 31, 2005 Cool! Just Tried it with params of 0,0,0,0 and It locked the cursor in the corner of the screen. Useful for locking the cursor for security reasons. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 Updated the UDF, using @Numparams, so if you want 0,0,0,0 as the coords only need to call the function with 1 param of 0 Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
LxP Posted August 1, 2005 Share Posted August 1, 2005 How about having the right and bottom fields default to the left and top ones? Then you could call _CursorClip(0, 0) or _CursorClip(200, 200) and 'stick' the cursor to that location. Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 See if that'll work for you. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
LxP Posted August 1, 2005 Share Posted August 1, 2005 (edited) You might want to mention that it's necessary to _CursorClip() before setting a different region.Also, on my system this works better (no movement):If @NumParams = 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIfOn my system _CursorClip(0, 0) hides the cursor. That's a handy feature that should probably be documented! Edited August 1, 2005 by LxP Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 You might want to mention that it's necessary to _CursorClip() before setting a different region.Also, on my system this works better (no movement):If @NumParams = 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 2 EndIfOn my system _CursorClip(0, 0) hides the cursor. That's a handy feature that should probably be documented!<{POST_SNAPBACK}>Ok, changed the if statement added 1 to each only if left or top are not zerono need to call _ClipCursor() before setting diff region at leas not on my system here's an example#include <GuiConstants.au3> HotKeySet("n", "_NewCoords") Opt("MustDeclareVars",1) Dim $GUI, $coords[4], $msg $GUI = GUICreate("Clip Cursor Example", 392, 323) GUISetState() _CursorClip(0,0) While 1 ;~ $coords = WinGetPos($GUI) ;~ _CursorClip($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3]) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd _CursorClip() Exit Func _NewCoords() _CursorClip(50,50, 100, 100) EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
LxP Posted August 1, 2005 Share Posted August 1, 2005 Oops, must have been calling it improperly -- it's working as expected now (still hides the cursor at (0, 0) though).Your UDF's blurb mentions that it needs <Misc.au3> -- why is this? Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 That's where I have it on my system right now, if I get enough ppl interested in it, that's probably where it'll end up. Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
layer Posted August 1, 2005 Share Posted August 1, 2005 (edited) Oops, must have been calling it improperly -- it's working as expected now (still hides the cursor at (0, 0) though).Your UDF's blurb mentions that it needs <Misc.au3> -- why is this?<{POST_SNAPBACK}>For when it gets added to AutoIt as a UDF EDIT: Gafrost beat me to it.. lol Edited August 1, 2005 by layer FootbaG Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 Probably aught to call this function _MouseTrap SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jdickens Posted August 1, 2005 Share Posted August 1, 2005 This is ideal for me. Computer-illiterate staff needs to click OK on an error dialog, but instead they just bury it under some other window. J If I am too verbose, just say so. You don't need to run on and on. Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 great, well renaming the function _MouseTrap, lil more descriptive of what it does, not sure if it's the same thing that Larry's does in the dll, even if it is the all the functions in dll should be able to be done directly thru the beta version now. Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
layer Posted August 1, 2005 Share Posted August 1, 2005 I like _MouseTrap hahah... I think most of Larrys Dll funcs are now native AutoIt commands with Dll*** functions except for _MouseTrap... Sooo, I don't see why this couldn't be added. FootbaG Link to comment Share on other sites More sharing options...
Baku Posted August 1, 2005 Share Posted August 1, 2005 hmm.. Dude, really nice udf. maybe u could also create a function which tells me if someone mouseovers a controll / window? Link to comment Share on other sites More sharing options...
GaryFrost Posted August 1, 2005 Author Share Posted August 1, 2005 Submitted to jpm, we'll see if it makes the cut. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GoronSlayer99 Posted August 2, 2005 Share Posted August 2, 2005 Ok, noob Question: Ok, what button would I press to unlock it? If you dont have that feature I think I could figure out how to add it... with alot of free-time... Also, what's a UDF? Link to comment Share on other sites More sharing options...
GaryFrost Posted August 2, 2005 Author Share Posted August 2, 2005 in the example in the 1st post by hitting the "Esc" key UDF: User Defined Function SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GoronSlayer99 Posted August 2, 2005 Share Posted August 2, 2005 (edited) Oooh, ok, thanks alot, I'm gonna use this so my brother doesn't go looking through everything while I'm away Cheers Edited August 2, 2005 by GoronSlayer99 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now