Page 1 of 1
Blockinput, mousemove fix or alternative
Posted: 12 Aug 2022, 00:02
by hemsith14_
Hey
How do I get the following function to also block the x axis in addition to y (both of them)?
I know about blockinputs, but still.
Thanks!
Code: Select all
ClipCursor(x := "", y := "", w := "", h := "") {
if p := x != "" {
VarSetCapacity(RECT, 16, 0), p := &RECT
for k, v in [x, y, x + w, y + h]
NumPut(v, p + 4*(k - 1), "Int")
}
DllCall("ClipCursor", "Ptr", p)
}
Re: Clip cursor quesiton
Posted: 12 Aug 2022, 01:49
by Rohwedder
Hallo,
try:
Code: Select all
q:: ;On/Off
CoordMode, Mouse, Screen
MouseGetPos, x, y
(Clip:=!Clip)?ClipCursor(x,y,0,0):ClipCursor()
Return
ClipCursor(x := "", y := "", w := "", h := "") {
if p := x != "" {
VarSetCapacity(RECT, 16, 0), p := &RECT
for k, v in [x, y, x + w, y + h]
NumPut(v, p + 4*(k - 1), "Int")
}
DllCall("ClipCursor", "Ptr", p)
}
Re: Clip cursor quesiton
Posted: 12 Aug 2022, 09:47
by hemsith14_
Thank you!
It works almost perfectly, but it still possible to move the mouse a tiny amount to each side. Is there a way to prevent that?
Re: Clip cursor quesiton
Posted: 12 Aug 2022, 11:06
by Rohwedder
Then perhaps?:
Code: Select all
q:: (BlockInputMouse := !BlockInputMouse)
?hHookMouse := SetWindowsHookEx(WH_MOUSE_LL := 14
, RegisterCallback("True")):UnhookWindowsHookEx(hHookMouse)
True() {
Return, True
}SetWindowsHookEx(idHook, pfn) {
Return DllCall("SetWindowsHookEx", "int", idHook, "Uint"
, pfn, "Uint", DllCall("GetModuleHandle", "Str"), "Uint", 0)
}UnhookWindowsHookEx(hHook) {
Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}
Ingredients extracted from:
teadrinker
viewtopic.php?p=271462#p271462
Re: Clip cursor quesiton
Posted: 12 Aug 2022, 11:53
by wetware05
Rohwedder, very effective, too...!!! how do you unlock it from your last script?
(Warning: putting in a way to exit, for example ^F3:: ExitApp, has taken me a long time to remove the execution of the script from memory.)
Reissued:
Ah, already, I had not understood the concept, activate and deactivate it in the same keyboard shortcut. But what if you don't want to use it within a script, and not because it has to be activated/deactivated by a keyboard shortcut?
Re: Clip cursor quesiton
Posted: 12 Aug 2022, 14:11
by hemsith14_
Rohwedder wrote: ↑12 Aug 2022, 11:06
Then perhaps?:
Code: Select all
q:: (BlockInputMouse := !BlockInputMouse)
?hHookMouse := SetWindowsHookEx(WH_MOUSE_LL := 14
, RegisterCallback("True")):UnhookWindowsHookEx(hHookMouse)
True() {
Return, True
}SetWindowsHookEx(idHook, pfn) {
Return DllCall("SetWindowsHookEx", "int", idHook, "Uint"
, pfn, "Uint", DllCall("GetModuleHandle", "Str"), "Uint", 0)
}UnhookWindowsHookEx(hHook) {
Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}
Ingredients extracted from:
teadrinker
viewtopic.php?p=271462#p271462
Thank you so much!
How can I use it as function like?
Code: Select all
1::
BlockInputMouse := True
KeyWait, 1
BlockInputMouse := False
Return
Also, how can it be used in conjunction with mousemove so it will basically act like blockinput?
Re: Clip cursor quesiton
Posted: 13 Aug 2022, 02:07
by Rohwedder
Then:
Code: Select all
1::
BlockInputMouse(True)
KeyWait, 1
BlockInputMouse(False)
Return
BlockInputMouse(Block)
{ Static hHookMouse
IF Block And !hHookMouse
hHookMouse := SetWindowsHookEx(WH_MOUSE_LL := 14, RegisterCallback("True"))
Else IF !Block And hHookMouse
UnhookWindowsHookEx(hHookMouse), hHookMouse := False
}True() {
Return, True
}SetWindowsHookEx(idHook, pfn) {
Return DllCall("SetWindowsHookEx", "int", idHook, "Uint"
, pfn, "Uint", DllCall("GetModuleHandle", "Str"), "Uint", 0)
}UnhookWindowsHookEx(hHook) {
Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}
However, MouseMoves are also blocked!
I don't drink enough tea to understand what exactly is happening.
Re: Clip cursor quesiton
Posted: 13 Aug 2022, 12:14
by hemsith14_
It's working great but the whole point of this is to block user input during the mouse movements so I need to have it working somehow
Re: Clip cursor quesiton
Posted: 13 Aug 2022, 13:47
by Rohwedder
Then perhaps:
Code: Select all
OnExit("UnClip_ExitApp")
Radius := 300, X0 := 500, Y0 := 500
Alpha := 0, 2PI := 8*Atan(1)
SetTimer, Circle, 10
Esc::ExitApp
Circle:
Alpha := Mod(Alpha + .2, 2PI)
MouseMove_Clip(X0+Radius*Cos(Alpha), Y0+Radius*Sin(Alpha))
Return
MouseMove_Clip(X:=0, Y:=0)
{
VarSetCapacity(I, 16, 0)
For k, v in [X, Y, X, Y]
NumPut(v, &I + 4*(k - 1), "Int")
DllCall("ClipCursor") ;UnClip
DllCall("ClipCursor", "UInt", &I) ;MouseMove + Clip
}
UnClip_ExitApp()
{
DllCall("ClipCursor")
ExitApp
}
End the circling with the Escape key.
Re: Clip cursor quesiton
Posted: 13 Aug 2022, 16:16
by hemsith14_
Rohwedder wrote: ↑13 Aug 2022, 13:47
Then perhaps:
Code: Select all
OnExit("UnClip_ExitApp")
Radius := 300, X0 := 500, Y0 := 500
Alpha := 0, 2PI := 8*Atan(1)
SetTimer, Circle, 10
Esc::ExitApp
Circle:
Alpha := Mod(Alpha + .2, 2PI)
MouseMove_Clip(X0+Radius*Cos(Alpha), Y0+Radius*Sin(Alpha))
Return
MouseMove_Clip(X:=0, Y:=0)
{
VarSetCapacity(I, 16, 0)
For k, v in [X, Y, X, Y]
NumPut(v, &I + 4*(k - 1), "Int")
DllCall("ClipCursor") ;UnClip
DllCall("ClipCursor", "UInt", &I) ;MouseMove + Clip
}
UnClip_ExitApp()
{
DllCall("ClipCursor")
ExitApp
}
End the circling with the Escape key.
And this as a temporary hotkey like the one with keywait?
Basically, I'm just looking for a blockinput mousemove alternative that will not cause the mouse to move while a mouse movement is in progress. Something like
- Block mouse here
- hotkey here that includes mouse move
- Unblock
P.S I'm using a relative mosuemove
Basically a hotkey like:
Code: Select all
^0::
;Block mouse
Loop 100
MouseMove, 1, 0,, R
;Unblock mouse
Return
Re: Clip cursor quesiton
Posted: 14 Aug 2022, 02:48
by Rohwedder
Debugged and three examples added:
Code: Select all
OnExit("ExitApp")
Esc::ExitApp
^0::
MouseMoveBlock(,, 1) ;Block mouse
ToolTip, mouse blocked
Sleep, 2000
ToolTip, blocked mouse moves
Loop 200
{
MouseMoveBlock(1, 0, 1) ;Relative MoveBlock X=1,Y=0
Sleep, 10
}
ToolTip, blocked mouse stops
Sleep, 2000
MouseMoveBlock(,, -1) ;Unblock mouse
ToolTip, mouse unblocked
Sleep, 1000
ToolTip
Return
^1::MouseMoveBlock(500, 500) ;Absolute MoveBlock X=500,Y=500
^2::MouseMoveBlock(,, -1) ;Unblock mouse
MouseMoveBlock(X:=0, Y:=0, Mode:=0)
{ ;Mode: 0,1,-1 : Absolute+Block, Relative+Block, Unblock
Static X0, Y0, OldMode := 0
IF (Mode = 1)
{
IF (OldMode <> 1)
{
CoordMode, Mouse, Screen
MouseGetPos, X0, Y0
OldMode := 1
}
X0 := X += X0, Y0 := Y += Y0
}
Else If (0 > OldMode:=Mode)
{
DllCall("ClipCursor", "Ptr", 0)
Return
}
VarSetCapacity(I, 16, 0)
For k, v in [X, Y, X, Y]
NumPut(v, &I + 4*(k - 1), "Int")
DllCall("ClipCursor", "Ptr", 0)
DllCall("ClipCursor", "UInt", &I)
}
ExitApp()
{
MouseMoveBlock(,, -1) ;Unblock mouse
ExitApp
}
Re: Clip cursor quesiton
Posted: 14 Aug 2022, 16:00
by hemsith14_
Thanks so much!!!
Re: Clip cursor quesiton
Posted: 14 Aug 2022, 16:32
by hemsith14_
For some reason the following is too fast in order to stop the loop in time, while with the normal blockinput it worked fine. Any idea on how to fix this?
Using sleep, even if it's just sleep 1, makes it too slow..
Code: Select all
!RButton::
MouseMoveBlock(,, 1) ;Block mouse
Sleep 1
While (A_Cursor = "SizeNS")
MouseMoveBlock(1, 0, 1)
Click, Down
MouseMoveBlock(,, -1) ;Unblock mouse
KeyWait, RButton
Click, Up
Return
Re: Clip cursor quesiton
Posted: 15 Aug 2022, 00:26
by Rohwedder
Then use Moves smaller than 1 e.g. .2
Code: Select all
While (A_Cursor = "SizeNS")
MouseMoveBlock(.2, 0, 1)
or Sleep and greater Moves:
Code: Select all
While (A_Cursor = "SizeNS")
{
MouseMoveBlock(20, 0, 1)
Sleep, 1
}
This many DllCalls in MouseMoveBlock() are not elegant. If somehow possible one should better use BlockInput.
Re: Clip cursor quesiton
Posted: 15 Aug 2022, 00:43
by BoBo
@teadrinker
Re: Clip cursor quesiton
Posted: 15 Aug 2022, 00:47
by hemsith14_
It's still not "catching" the cursor changes like the normal mousemove tend to do. Could you test it and see if you can get the same result as I?
Even better, is there a way to fix the blockinput mousemove? perhaps by starting the script differently or something?
Re: Clip cursor quesiton
Posted: 15 Aug 2022, 01:13
by Rohwedder
See
https://www.autohotkey.com/docs/FAQ.htm#uac
UAC may also prevent SendPlay and BlockInput from working.
Re: Clip cursor quesiton
Posted: 15 Aug 2022, 12:56
by teadrinker
@BoBo
@Rohwedder
Guys, you don't have to limit yourself to tea!
Re: Clip cursor quesiton
Posted: 15 Aug 2022, 16:06
by hemsith14_
Just tried the normal blockinput mousemove with the UAC setting, but it didn't fix it, I'm starting to lose hope regarding this. Why is it happening? Why can blockinput mousemove can just block the mouse move regardless of anything that happens?