Re: new vscode extension allows advanced AHK V1/V2 debugging
Posted: 11 Nov 2020, 08:25
Yes, I think I came across that when researching - I may have to resort to the same method until some other method is found. ¯\_(ツ)_/¯
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=89&t=77464
Yes, I think I came across that when researching - I may have to resort to the same method until some other method is found. ¯\_(ツ)_/¯
This isn't the most elegant solution, but it works. The bottom of the editor window displaying the status bar needs to visible when the window is active (i.e., not hanging off the screen or turned off). It requires the Accessible Viewer Library which can be downloaded here.
Code: Select all
#Include, <Acc>
Caret := VsCodeLineColumn()
Msgbox, % Caret.Ln "," Caret.Col
return
VsCodeLineColumn() {
pCoordMode := A_CoordModeMouse
CoordMode, Mouse, Screen
MouseGetPos, px, py
WinGetPos, x, y, w, h, ahk_exe Code.exe
WinActivate, ahk_exe Code.exe
loop {
MouseMove, x + w - 250 - 30 * A_Index, y + h - 10, 0
oAcc := Acc_ObjectFromPoint(childID)
} until RegExMatch(oAcc.accName(childID), "Ln (\d+), Col (\d+)", m)
MouseMove, px, py, 0
CoordMode, Mouse, % pCoordMode
return {Ln: m1, Col: m2}
}
Hi, is this your extension vscode-autohotkey-plus-plus? I posted a similar question in the repo.zero-plusplus wrote: ↑13 Nov 2020, 02:15I'm currently working on a `vscode-autohotkey` extension to support all AutoHotkey(including H), and I'm thinking of adding this feature to it.
I don't get the script to work on my PC. In fact Acc doesn't read any content from the VS Code window when I try with jeeswg's JEE_AccGetTextAll function. Is there some accessibility setting to enable in VS Code first?boiler wrote: ↑12 Nov 2020, 12:14This isn't the most elegant solution, but it works. The bottom of the editor window displaying the status bar needs to visible when the window is active (i.e., not hanging off the screen or turned off). It requires the Accessible Viewer Library which can be downloaded here.
Sounds useful. I'm also looking for a way to get the VS Code cursor X Y screen position that is faster than using ImageSearch to find the cursor. Consider releasing a separate extension with only that functionality. Because there are already multiple competing AutoHotkey extensions with partly overlapping features and that can be tricky to run at the same time.zero-plusplus wrote: ↑13 Nov 2020, 02:15Using VSCode's API it is probably possible to embed the current state of the VSCode, such as the column number, in to the window title.
The bottom bar of VSCode has column numbers updated in real time, so I'm assuming there is an event to monitor the caret movement.
I don't know. The JEE_AccGetTextAll function and other Acc functions just work for me, and I haven't changed any settings on my system to get them to work.neogna2 wrote: ↑15 Nov 2020, 06:30I don't get the script to work on my PC. In fact Acc doesn't read any content from the VS Code window when I try with jeeswg's JEE_AccGetTextAll function. Is there some accessibility setting to enable in VS Code first?
Code: Select all
#Include, <Acc>
Caret := VsCodeLineColumn()
Msgbox, % Caret.Ln "," Caret.Col
return
VsCodeLineColumn() {
hwnd := WinExist("ahk_exe Code.exe")
oAcc := Acc_Get("Object", "4.1.2.1.1.2.1.1.1.1.2.3.1.8", 0, "ahk_id " hwnd)
RegExMatch(oAcc.accName(0), "Ln (\d+), Col (\d+)", m)
return {Ln: m1, Col: m2}
}
Maybe you haven't installed the library file correctly?
Code: Select all
Caret := VsCodeLineColumn()
WinShow ahk_class Shell_TrayWnd
WinShow Start ahk_class Button
Msgbox, % "Cursor position is at Line: "Caret.Ln " Column: " Caret.Col
ExitApp
ObjectFromPoint(ByRef _idChild_ = "", x = "", y = ""){
Init()
If DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""?0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Init(){
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
VsCodeLineColumn(){
pCoordMode := A_CoordModeMouse
CoordMode, Mouse, Screen
MouseGetPos, px, py
WinGetPos, x, y, w, h, ahk_exe Code.exe
WinActivate, ahk_exe Code.exe
loop {
MouseMove, x + w - 250 - 30 * A_Index, y + h - 11, 0
oAcc := ObjectFromPoint(childID)
} until RegExMatch(oAcc.accName(childID), "Ln (\d+), Col (\d+)", m)
MouseMove, px, py, 0
CoordMode, Mouse, % pCoordMode
return {Ln: m1, Col: m2}
}
Thanks boiler, I shall give that a shot.
Code: Select all
Caret := VsCodeLineColumn()
MsgBox % Caret.Ln "," Caret.Col
return
VsCodeLineColumn()
{
hwnd := WinExist("ahk_exe Code.exe")
oMem := {}, oPos := {}
oMem[1, 1] := Acc_ObjectFromWindow(hwnd, 0x0)
oPos[1] := 1, vLevel := 1
loop
{
if !vLevel
break
if !oMem[vLevel].HasKey(oPos[vLevel])
{
oMem.Delete(vLevel)
oPos.Delete(vLevel)
vLevelLast := vLevel, vLevel -= 1
oPos[vLevel]++
continue
}
oKey := oMem[vLevel, oPos[vLevel]]
vName := "", vValue := ""
if IsObject(oKey)
{
vRoleText := Acc_GetRoleText(oKey.accRole(0))
try vName := oKey.accName(0)
try vValue := oKey.accValue(0)
}
else
{
oParent := oMem[vLevel-1,oPos[vLevel-1]]
vChildId := IsObject(oKey) ? 0 : oPos[vLevel]
vRoleText := Acc_GetRoleText(oParent.accRole(vChildID))
try vName := oParent.accName(vChildID)
try vValue := oParent.accValue(vChildID)
} if (StrLen(vName) > vLimN)
vAccPath := ""
if IsObject(oKey)
{
Loop, % oPos.Length() - 1
vAccPath .= (A_Index=1?"":".") oPos[A_Index+1]
}
else
{
Loop, % oPos.Length() - 2
vAccPath .= (A_Index=1?"":".") oPos[A_Index+1]
vAccPath .= " c" oPos[oPos.Length()]
}
if RegExMatch(vName, "Ln (\d+), Col (\d+)", m)
return {Ln: m1, Col: m2}
oChildren := Acc_Children(oKey)
if !oChildren.Length()
oPos[vLevel]++
else
{
vLevelLast := vLevel, vLevel += 1
oMem[vLevel] := oChildren
oPos[vLevel] := 1
}
}
}
Code: Select all
---------------------------
temp-2020-11-15-15-41-45.ahk
---------------------------
TickCount = 2093
Pos = 4,75
---------------------------
OK
---------------------------
Ok. I've retried with both AutoHotkey 32U and 64U and double checked my Acc.ahk version, but still not working. I can use Acc on other application windows, but on VS Code it doesn't get the contents. Tried the VS Code insiders (beta) version, but same problem there. Since this is a general thing with Acc and VS Code on my PC, not only your script, I'll stop commenting about it here and maybe post in the Ask forum section instead.boiler wrote: ↑15 Nov 2020, 07:18I don't know. The JEE_AccGetTextAll function and other Acc functions just work for me, and I haven't changed any settings on my system to get them to work.neogna2 wrote: ↑15 Nov 2020, 06:30I don't get the script to work on my PC. In fact Acc doesn't read any content from the VS Code window when I try with jeeswg's JEE_AccGetTextAll function.
In some applications where the Acc path changes the variation can be quite small. For example in Firefox some of the elements in the top toolbar can vary but it is only one number in the path that varies between sessions/instances. In such cases it is quicker to loop over possible values for that number and check the path element until the correct path is found, compared to getting the whole Acc object.
It looks like it should be possible since accLocation is one of the methods supported for carets.zero-plusplus wrote: ↑16 Nov 2020, 05:40It's probably not possible to get the screen position. A similar question was found on stackoverflow. Can't I get it in Acc?
That lead me to Acc code by malcev for getting caret position in Chrome. The same approach worked also in VS Code, even on the same PC where the other VS Code Acc script didn't work.boiler wrote: ↑16 Nov 2020, 07:46It looks like it should be possible since accLocation is one of the methods supported for carets.
Reference: https://docs.microsoft.com/en-us/windows/win32/winauto/caret
Code: Select all
#Include <Acc>
;Acc method to capture caret X Y screen position in active window
Acc_Caret := Acc_ObjectFromWindow(WinExist("A"), OBJID_CARET := 0xFFFFFFF8)
Caret_Location := Acc_Location(Acc_Caret)
MsgBox, % Caret_Location.x "`n" Caret_Location.y
return