改了改代码,更简洁有效了,这下几乎完全不闪了
#Persistent
#SingleInstance Force
SetWinDelay, -1
CoordMode, Caret , Screen
SetTimer, movesogou, 1
return
movesogou:
if !GetCaretPos(x, y)
;MsgBox, 无法识别光标位置
1=1
else {
CoordMode, Mouse
XX:=x-30
YY:=y
WinMove, ahk_class SoPY_Cand, , XX, YY
return
}
return
;=============库代码,勿改动===============
GetCaretPos(ByRef x, ByRef y) {
static OBJID_CARET := 0xFFFFFFF8
CoordMode, Caret
if (A_CaretX != "" && A_CaretY != "")
x := A_CaretX, y := A_CaretY
else {
AccObject := AccObjectFromWindow(WinExist("A"), OBJID_CARET)
Pos := AccLocation(AccObject)
x := Pos.x, y := Pos.y
}
Return x && y
}
AccObjectFromWindow(hWnd, idObject = 0) {
static IID_IDispatch := "{00020400-0000-0000-C000-000000000046}"
, IID_IAccessible := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
, OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1
, h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF, AccObject := 0
DllCall("ole32\CLSIDFromString", "Str", idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, "Ptr", &IID)
if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject, "Ptr", &IID, "PtrP", pAcc) = 0
AccObject := ComObject(VT_DISPATCH, pAcc, F_OWNVALUE)
Return AccObject
}
AccLocation(Acc, ChildId := 0, ByRef Position := "") {
static type := (VT_BYREF := 0x4000) | (VT_I4 := 3)
try Acc.accLocation( ComObject(type, &x := 0), ComObject(type, &y := 0)
, ComObject(type, &w := 0), ComObject(type, &h := 0), ChildId )
catch
Return
_x := NumGet(x, "int"), _y := NumGet(y, "int"), _w = NumGet(w, "int"), _h := NumGet(h, "int")
Position := "x" . _x . " y" . _y . " w" . _w . " h" . _h
Return {x: _x, y: _y, w: _w, h: _h}
}