我使用的代码在激活时将光标限制在水平方向,但是我遇到了以下问题:在脚本上进行切换时,光标会从其原始位置向下移动保持在相同的高度。
我正在使用的代码是这样的:
!s:: ; Hotkey will toggle status
Confine := !Confine
MouseGetPos ,, SetY
Confine ? ClipCursor( 0 , SetY , A_ScreenWidth , SetY+1 ) : DllCall( "ClipCursor" )
Return
ClipCursor( 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 DllCall( "ClipCursor" , UInt , &R )
}
我需要光标不要跳转。该行为如何解决?
这个问题与我之前发布的另一个问题有关:
答案 0 :(得分:0)
坐标SetY必须相对于桌面(整个屏幕)。
!s:: ; Hotkey will toggle status
Confine := !Confine
CoordMode, Mouse, Screen ; If this command is not used the coordinates are relative to the active window.
MouseGetPos ,, SetY
If (Confine)
ClipCursor( Confine, 0, SetY, A_ScreenWidth+1, SetY+1 )
else
DllCall( "ClipCursor" )
Return
ClipCursor( Confine=True, 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 DllCall( "ClipCursor" , UInt , &R )
}