Turn off ClipCursor ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
liner
Posts: 5
Joined: 23 Oct 2018, 06:59

Turn off ClipCursor ?

23 Oct 2018, 07:17

Hello :D

So i'm new to AutoHotkey, and i mainly use it for Maya (3d software)

I created a script to search for a slider i use (this one -> https://puu.sh/BPDqq/0a828ad5f1.png)
The script searches the logo with the TW at the center and sends the cursor on it, then clicks and hold, until i release the f key, then it sends the cursor back to its original position.

It's this one

Code: Select all

f:: 
CoordMode, Mouse, Screen
IfWinActive, ahk_exe maya.exe
	{
	MouseGetPos x, y
	CoordMode Pixel
	ImageSearch, FoundX, FoundY, 2, 840, 844, 1079, *50 D:\tw.jpg
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Image could not be found on the screen
else
		BlockInput, MouseMove
	CoordMode, Mouse, Screen
	MouseMove, %FoundX%, %FoundY%, 0
	MouseMove, 15, 15, 0, R
	Click, down
		BlockInput, MouseMoveOff	
	KeyWait, f
	Click, up
	MouseMove %x%, %y%, 0
	return
	}
else
	SendInput {Blind}{Text}f
The thing is,
I wanted to try to keep my cursor between the boundaries of the cursor while i'm pressing the F key.
So i searched and found the ClipCursor function, which seems to work, but i don't know how to to turn it off except by pressing Alt+Tab or a Windows Key.

And all the scripts i found that use ClipCursor suggest to stop it by pressing another key or press the same key again to toggle it
It's not practical at all, because the whole purpose of the first script was to have only to press F, slide, and then release it to get my cursor back to its original position.

So basically i'm looking to get this script inside my first one

Code: Select all

Confine := !Confine
	MouseGetPos, GetX, GetY
			VarX1 := GetX - 90
			VarX2 := GetX + 90
			VarY1 := GetY - 0
			VarY2 := GetY + 0
	ClipCursor( 1, VarX1, VarY2, VarX2, VarY2)
return
	


ClipCursor( Confine := 1, x1=0 , y1=0, x2=1, y2=1 ) {
 VarSetCapacity(R,16,0),  NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}
And turn off the ClipCursor function when i release F

I tried to look on the forum but found nothing, i may have not searched for the right terms or something like that.

I'd be glad if you'd have a solution !

Cheers ;)
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Turn off ClipCursor ?

23 Oct 2018, 07:22

try ClipCursor(0)
liner
Posts: 5
Joined: 23 Oct 2018, 06:59

Re: Turn off ClipCursor ?

23 Oct 2018, 07:27

It didn't work, i tried it with a GetKeyState type of code and with a simple Keywait
but none of them worked :/
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Turn off ClipCursor ?

23 Oct 2018, 07:45

maybe "a GetKeyState type of code and a simple Keywait" is buggy.
ClipCursor(0) is the correct command to switch off cursor clipping, no Alt+Tab or a Windows Key.
liner
Posts: 5
Joined: 23 Oct 2018, 06:59

Re: Turn off ClipCursor ?

23 Oct 2018, 07:49

Ok, i tried it like this to test it out

Code: Select all

CoordMode, Mouse, Screen  

B::

	Confine := !Confine
	MouseGetPos, GetX, GetY
			VarX1 := GetX - 90
			VarX2 := GetX + 90
			VarY1 := GetY - 0
			VarY2 := GetY + 0
	ClipCursor( 1, VarX1, VarY2, VarX2, VarY2)
return

^N::
	ClipCursor(0)
return


ClipCursor( Confine := 1, x1=0 , y1=0, x2=1, y2=1 ) {
 VarSetCapacity(R,16,0),  NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}

And it didn't work :(
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Turn off ClipCursor ?

23 Oct 2018, 08:30

There is something beyond my knowledge. I have a demo script where it is used successfully. (MasterFocus did a proportional resize demo).
The best I can do for now is the entirely unacceptable work-round with a msgbox, sorry.
ClipCursor(0) is the correct command and syntax, but there is some interference going on.
I hope somebody else can enlighten the two of us.


Code: Select all

B::
    MouseGetPos, GetX, GetY
    VarX1 := GetX - 90
    VarX2 := GetX + 90
    VarY1 := GetY - 0
    VarY2 := GetY + 0
    ClipCursor( 1, VarX1, VarY2, VarX2, VarY2)
return

B Up::
    MsgBox,,,,1
    ClipCursor(0)
return
You could even leave the CllipCursor(0) out altogether now. I left it anyway.
liner
Posts: 5
Joined: 23 Oct 2018, 06:59

Re: Turn off ClipCursor ?

23 Oct 2018, 09:32

Okok, thanks !

I tried to move the msgbox away and send an enter key instantly after it's created, but i can't send away the msgbox

Though no big deal because it's only on the screen for a few frames ;)

Here's how it turns out https://puu.sh/BPGdh/59b721b2ff.gif

And the script i Got looks like this :

Code: Select all

f:: 
CoordMode, Mouse, Screen
IfWinActive, ahk_exe maya.exe
	{
	MouseGetPos x, y
	CoordMode Pixel
	ImageSearch, FoundX, FoundY, 2, 840, 844, 1079, *50 D:\tw.jpg
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Image could not be found on the screen
else
		BlockInput, MouseMove
	CoordMode, Mouse, Screen
	MouseMove, %FoundX%, %FoundY%, 0
	MouseMove, 15, 15, 0, R
	MouseGetPos, GetX, GetY
    VarX1 := GetX - 95
    VarX2 := GetX + 95
    VarY1 := GetY - 0
    VarY2 := GetY + 0
    ClipCursor( 1, VarX1, VarY2, VarX2, VarY2)
	Click, down
		BlockInput, MouseMoveOff	
	KeyWait, f
	SetTimer, MoveMsgBox, -50
MsgBox,,,,1
MoveMsgBox:
WinGetActiveTitle, Title
SendInput {Enter}
	Click, up
	MouseMove %x%, %y%, 0
	return
	}
else
	SendInput {Blind}{Text}f

ClipCursor( Confine := 1, x1=0 , y1=0, x2=1, y2=1 ) {
 VarSetCapacity(R,16,0),  NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}
I can't remove the MoveMsgBox function neither the settimer, because otherwise, the msgbox stays on the screen for too long :/

But it works quite well so thanks a lot !

I'm quite curious about why the ClipCursor(0) doesn't work as well
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Turn off ClipCursor ?

24 Oct 2018, 14:33

No message box needed.
I still have no idea why ClipCursor(0) does not work, but using the DllCall directly works.

Code: Select all

CoordMode, Mouse, Screen
B::
    MouseGetPos, GetX, GetY
    ClipCursor(1, GetX - 90, GetY, GetX + 90, GetY)
    KeyWait, B
    DllCall("ClipCursor")
return
liner
Posts: 5
Joined: 23 Oct 2018, 06:59

Re: Turn off ClipCursor ?

25 Oct 2018, 02:43

Thanks a lot ! works perfectly :)
User avatar
SteveMylo
Posts: 233
Joined: 22 Jun 2021, 00:50
Location: Australia
Contact:

Re: Turn off ClipCursor ?

13 Feb 2022, 21:24

This helped me just turning off the clipcursor() function.

Code: Select all

b::
Gui, show
Gui, hide
Return
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Turn off ClipCursor ?

14 Feb 2022, 10:20

Or clicking on title bars or on task bar or flashing a tooltip. But I think the best ways are just to call DllCall("ClipCursor") directly or to use this variation of ClipCursor(false):

Code: Select all

ClipCursor(confine := true, x1 := 0, y1 := 0, x2 := 1, y2 := 1) {
	if !confine 
		return DllCall("ClipCursor")
	VarSetCapacity(R, 16, 0)
	NumPut(x1, &R+0), NumPut(y1, &R+4)
	NumPut(x2, &R+8), NumPut(y2, &R+12)
	return DllCall("ClipCursor", UInt, &R)
}
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: -Elaphe-, downstairs, Frogrammer and 278 guests