Sign in to follow this  
Followers 0
XTensionX

trap cursor

12 posts in this topic

#1 ·  Posted (edited)

hi, im trying to make the cursor trapped inside my input box, but i dont know why it doesn't work

here is my code

#include <Misc.au3>
    
$input = InputBox ("Example", "please type your text here","","",150,80)
$Pos = WinGetPos($input)
_MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])

can anyone tell me what i did wrong?

thanks

Edit: Damn wrong section sry :S

Edited by XTensionX

Share this post


Link to post
Share on other sites



I've seen on the forums similar situations and the explination given was something along the lines of:

When the code hits the input box line, it pauses until the input box is complete, then moves on.

I can't remember the solution, but some searching should help you out.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

I've seen on the forums similar situations and the explination given was something along the lines of:

When the code hits the input box line, it pauses until the input box is complete, then moves on.

I can't remember the solution, but some searching should help you out.

i've been looking around for a while myself aswell.. but i cant seem to find a working answer to this problem ;)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The problem is that InputBox stops the script and is waiting for an input - no other functions e.g. AdlibRegister() will not be performed!

There is an example in the help file:

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

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
 Local $GUI, $coords[4]

 $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])
 Switch GUIGetMsg()
 Case $GUI_EVENT_CLOSE
 ExitLoop
 Case Else
 ;;;
 EndSwitch
 WEnd
 _MouseTrap()
 Exit
EndFunc ;==>_Main

You have to create a GUI!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

The problem is that InputBox stops the script and is waiting for an input - no other functions e.g. AdlibRegister() will not be performed!

There is an example in the help file:

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

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
 Local $GUI, $coords[4]

 $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])
 Switch GUIGetMsg()
 Case $GUI_EVENT_CLOSE
 ExitLoop
 Case Else
 ;;;
 EndSwitch
 WEnd
 _MouseTrap()
 Exit
EndFunc ;==>_Main

You have to create a GUI!

Br,

UEZ

i looked into this example aswell.. and i can get the mousetrap working on GUI, but i need it to work on a input box, so theres no way the _mousetrap would work on a input box? :/

Share this post


Link to post
Share on other sites

In otherwords, you have to create a gui that looks and acts just like an inputbox.

oh i see gna have to remake my script a little then

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

No need to do much at all, certainly no need to make your own gui. I think the code below does what you want .

#include <Misc.au3>
#include <timers.au3>

 $t1 = _Timer_SetTimer(0,50,"Trap")
$input = InputBox ("Example 001", "please type your text here","","",150,80)

func Trap($a,$b,$c,$d)
    Local $margin = 6;might be better to keep cursor within client area
    $pos=wingetpos("Example 001")
    _MouseTrap($Pos[0]+$margin, $Pos[1]+$margin, $Pos[0] + $Pos[2]-$margin, $Pos[1] + $Pos[3]-$margin)
    _Timer_KillAllTimers(0)
EndFunc

The margin is needed to prevent sizing arrows appearing.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Nice to know that _Timer_SetTimer() is skipping this limit! But after resizing the window "trapping" is not working anymore ;)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

No need to do much at all, certainly no need to make your own gui. I think the code below does what you want .

#include <Misc.au3>
#include <timers.au3>

 $t1 = _Timer_SetTimer(0,50,"Trap")
$input = InputBox ("Example 001", "please type your text here","","",150,80)

func Trap($a,$b,$c,$d)
    Local $margin = 6;might be better to keep cursor within client area
    $pos=wingetpos("Example 001")
    _MouseTrap($Pos[0]+$margin, $Pos[1]+$margin, $Pos[0] + $Pos[2]-$margin, $Pos[1] + $Pos[3]-$margin)
    _Timer_KillAllTimers(0)
EndFunc

The margin is needed to prevent sizing arrows appearing.

thanks it works ;)

but sizing arrow still apears, and after after i resize it/move the input box, the mousetrap doesnt work no more :/

Share this post


Link to post
Share on other sites

thanks it works ;)

but sizing arrow still apears, and after after i resize it/move the input box, the mousetrap doesnt work no more :/

I tried this on XP and the margin of 6 keeps the cursor away from the edges so I cannot resize. Maybe you and Uez are using W7. In that case maybe in W7 you need to increase the margin, and maybe have a different margin at the top as my comment in the function. Or if you are resizing using Alt SPACE then choosing sizing, move the killAlltimers line like this

#include <Misc.au3>
#include <timers.au3>

 $t1 = _Timer_SetTimer(0,50,"Trap")
$input = InputBox ("Example 001", "please type your text here","","",150,80)
_Timer_KillAllTimers(0)

func Trap($a,$b,$c,$d)
    Local $margin = 6;might be better to keep cursor within client area
    $pos=wingetpos("Example 001")
    _MouseTrap($Pos[0]+$margin, $Pos[1]+$margin, $Pos[0] + $Pos[2]-$margin, $Pos[1] + $Pos[3]-$margin)
    ;_Timer_KillAllTimers(0)
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I tried this on XP and the margin of 6 keeps the cursor away from the edges so I cannot resize. Maybe you and Uez are using W7. In that case maybe in W7 you need to increase the margin, and maybe have a different margin at the top as my comment in the function. Or if you are resizing using Alt SPACE then choosing sizing, move the killAlltimers line like this

#include <Misc.au3>
#include <timers.au3>

 $t1 = _Timer_SetTimer(0,50,"Trap")
$input = InputBox ("Example 001", "please type your text here","","",150,80)
_Timer_KillAllTimers(0)

func Trap($a,$b,$c,$d)
    Local $margin = 6;might be better to keep cursor within client area
    $pos=wingetpos("Example 001")
    _MouseTrap($Pos[0]+$margin, $Pos[1]+$margin, $Pos[0] + $Pos[2]-$margin, $Pos[1] + $Pos[3]-$margin)
    ;_Timer_KillAllTimers(0)
EndFunc

it works ^^

thanks, and yes im using W7 =]

Share this post


Link to post
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
Sign in to follow this  
Followers 0