Using ClassNN

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
WKen
Posts: 204
Joined: 21 Feb 2023, 00:01

Re: Using ClassNN

Post by WKen » 22 Oct 2023, 06:09

ControlGetClassNN is not available for chromium-based programs. Maybe you need UIA, or determine whether it is an edit control by getting the cursor position:

Code: Select all

    GetCaretPos(&editX, &editY)
    if !editX
        return
	
	GetCaretPos(&x?, &y?) {
    static OBJID_CARET := 0xFFFFFFF8

    AccObject := AccObjectFromWindow(WinExist('A'), OBJID_CARET)
    Pos := AccLocation(AccObject)
    try 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')

    idObject &= 0xFFFFFFFF, AccObject := 0
    DllCall('Ole32\CLSIDFromString', 'Str', idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, 'Ptr', CLSID := Buffer(16))
    if DllCall('Oleacc\AccessibleObjectFromWindow', 'Ptr', hWnd, 'UInt', idObject, 'Ptr', CLSID, 'PtrP', &pAcc := 0) = 0
        AccObject := ComObjFromPtr(pAcc), ComObjFlags(AccObject, F_OWNVALUE, F_OWNVALUE)
    return AccObject
}

AccLocation(Acc, ChildId := 0, &Position := '') {
    static type := (VT_BYREF := 0x4000) | (VT_I4 := 3)
    x := Buffer(4, 0), y := Buffer(4, 0), w := Buffer(4, 0), h := Buffer(4, 0)
    try Acc.accLocation(ComValue(type, x.Ptr), ComValue(type, y.Ptr),
                        ComValue(type, w.Ptr), ComValue(type, h.Ptr), ChildId)
    catch
        return
    return { x: NumGet(x, 'int'), y: NumGet(y, 'int'), w: NumGet(w, 'int'), h: NumGet(h, 'int') }
}
https://www.autohotkey.com/boards/viewtopic.php?p=511470#p511470

Post Reply

Return to “Ask for Help (v2)”