Yes, I think I came across that when researching - I may have to resort to the same method until some other method is found. ¯\_(ツ)_/¯
new vscode extension allows advanced AHK V1/V2 debugging
Re: new vscode extension allows advanced AHK V1/V2 debugging
Re: new vscode extension allows advanced AHK V1/V2 debugging
I posed the question on Stack Overflow but it hasn't garnered much interest.
Essentially, I'm trying to determine what the start position is is for a selected block of text, preferably using windows cmd/PowerShell and used in a script variable.
Essentially, I'm trying to determine what the start position is is for a selected block of text, preferably using windows cmd/PowerShell and used in a script variable.
Re: new vscode extension allows advanced AHK V1/V2 debugging
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}
}
It should be possible to accomplish via reading process memory that would be faster and invisible. I might try getting that to work.
-
- Posts: 26
- Joined: 23 May 2020, 08:01
- Contact:
Re: new vscode extension allows advanced AHK V1/V2 debugging
I use machine translation.
My idea for solving that is to embed information like column numbers and so on in the VSCode window title. If it is a window title you can read it with AutoHotkey.
Using 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'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 plan to release a preview version of this extension as early as this month, or by the end of this year at the latest.
My idea for solving that is to embed information like column numbers and so on in the VSCode window title. If it is a window title you can read it with AutoHotkey.
Using 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'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 plan to release a preview version of this extension as early as this month, or by the end of this year at the latest.
Re: new vscode extension allows advanced AHK V1/V2 debugging
Excellent, this solution does work for me - just needed to make a couple of adjustments.
- I prefer to have my taskbar hidden with the editor open fullscreen. The initial MouseMove y coord, in the Loop{}Until routine, causes the taskbar to be revealed, obscuring the browser status bar, resulting in the mouse to getting trapped in the bottom left corner of the screen. This was resolved by reducing the y coord by an extra pixel to -11.
- I sometimes launch scripts from the taskbar, so of course, the editor's status bar gets hidden when open fullscreen. Got around that by wrapping the function call with Lexikos' code snippet that hides/unhides the taskbar.
Re: new vscode extension allows advanced AHK V1/V2 debugging
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.
-
- Posts: 26
- Joined: 23 May 2020, 08:01
- Contact:
Re: new vscode extension allows advanced AHK V1/V2 debugging
The `vscode-autohotkey` repository is not yet public.
It will be published on the following accounts.
https://github.com/zero-plusplus
It will be published on the following accounts.
https://github.com/zero-plusplus
Re: new vscode extension allows advanced AHK V1/V2 debugging
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.
Re: new vscode extension allows advanced AHK V1/V2 debugging
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?
@fade2gray (@zero-plusplus may also be interested) - Having learned more about Acc, I now have an much better function for getting the VS Code caret's line and column position. It works instantly and invisibly (without activating the window or moving the mouse).
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}
}
Re: new vscode extension allows advanced AHK V1/V2 debugging
Maybe you haven't installed the library file correctly?
This includes the function taken from the library file.
EDIT: Had to update the code to include another libry function call that I missed.
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}
}
Last edited by fade2gray on 15 Nov 2020, 08:49, edited 1 time in total.
Re: new vscode extension allows advanced AHK V1/V2 debugging
Thanks boiler, I shall give that a shot.
EDIT: Nope, doesn't work for me - is it possibly dependent on screen size/resolution?
Re: new vscode extension allows advanced AHK V1/V2 debugging
It shouldn't have to do with size or resolution, but it may have to do with whatever else happens to be displayed in your VSCode client because it will affect the object structure. Try this version, which is based on jeeswg's JEE_AccGetTextAll(). It's a bit slower because it navigates the entire Acc object structure until it finds the element that contains the Ln/Col info.
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
}
}
}
Re: new vscode extension allows advanced AHK V1/V2 debugging
Wow, I see what you mean
Code: Select all
---------------------------
temp-2020-11-15-15-41-45.ahk
---------------------------
TickCount = 2093
Pos = 4,75
---------------------------
OK
---------------------------
Re: new vscode extension allows advanced AHK V1/V2 debugging
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.
Here's what the AccViewer shows when I drag the crosshair onto the VS Code window https://imgur.com/a/wXWWHjE
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.
-
- Posts: 26
- Joined: 23 May 2020, 08:01
- Contact:
Re: new vscode extension allows advanced AHK V1/V2 debugging
@boiler
I'm interested in it too. I recently learned about Acc but gave up on it because it doesn't work with v2. Caret position is important when automating, so I'd like to port it to v2 if I have the time.
@neogna2
I'll publish it as a separate extension. It will be named `vscode-customize-title`.
I' ll release it in December or in January next year, though it will be delayed because of the priority of `vscode-autohotkey` development.
I'll report here as soon as it's done.
It's probably not possible to get the screen position. A similar question was found on stackoverflow. Can't I get it in Acc?
https://stackoverflow.com/questions/59283972/would-it-be-theoretically-possible-to-get-x-y-screen-coordinates-of-caret-in-vs
I'm interested in it too. I recently learned about Acc but gave up on it because it doesn't work with v2. Caret position is important when automating, so I'd like to port it to v2 if I have the time.
@neogna2
I'll publish it as a separate extension. It will be named `vscode-customize-title`.
I' ll release it in December or in January next year, though it will be delayed because of the priority of `vscode-autohotkey` development.
I'll report here as soon as it's done.
It's probably not possible to get the screen position. A similar question was found on stackoverflow. Can't I get it in Acc?
https://stackoverflow.com/questions/59283972/would-it-be-theoretically-possible-to-get-x-y-screen-coordinates-of-caret-in-vs
Last edited by zero-plusplus on 17 Nov 2020, 23:03, edited 1 time in total.
Re: new vscode extension allows advanced AHK V1/V2 debugging
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?
Reference: https://docs.microsoft.com/en-us/windows/win32/winauto/caret
Re: new vscode extension allows advanced AHK V1/V2 debugging
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
-
- Posts: 26
- Joined: 23 May 2020, 08:01
- Contact:
Re: new vscode extension allows advanced AHK V1/V2 debugging
It's great to be able to get the screen position of the caret! I learned something good.
I tried to create a `vscode-customize-title`, but unfortunately it's not useful.
It works fine, but I've encountered another problem: needs to change the `window.title` in settings.json to change the title.
This means that if you move the caret 1000 times, it will cause 1000 writes to be made to settings.json.
There is no problem in terms of speed, so if you don't care about the storage load, you can use it without any problem. But it's best not to do it.
An alternative is to set up a server and communicate with AutoHotkey. This will allow you to get the caret location without any problems.
However, it is too difficult to write the communication process in AutoHotkey, so would have to create a library, but then it is faster to use Acc from the start.
postscript:
I noticed that the window title can be changed using AutoHotkey. This solves the above problem.
I tried to create a `vscode-customize-title`, but unfortunately it's not useful.
It works fine, but I've encountered another problem: needs to change the `window.title` in settings.json to change the title.
This means that if you move the caret 1000 times, it will cause 1000 writes to be made to settings.json.
There is no problem in terms of speed, so if you don't care about the storage load, you can use it without any problem. But it's best not to do it.
An alternative is to set up a server and communicate with AutoHotkey. This will allow you to get the caret location without any problems.
However, it is too difficult to write the communication process in AutoHotkey, so would have to create a library, but then it is faster to use Acc from the start.
postscript:
I noticed that the window title can be changed using AutoHotkey. This solves the above problem.
-
- Posts: 26
- Joined: 23 May 2020, 08:01
- Contact:
Re: new vscode extension allows advanced AHK V1/V2 debugging
Thank you for your patience.
The planned extension has been merged into another extension.
Since the URL does not display correctly, please search for "zero-plusplus.vscode-operate-from-autohotkey" in the VSCode Marketplace.
This extension is for executing commands that do not have a shortcut key set. It also includes commands to get some context information (such as caret position).
See the README for details.
The planned extension has been merged into another extension.
Since the URL does not display correctly, please search for "zero-plusplus.vscode-operate-from-autohotkey" in the VSCode Marketplace.
This extension is for executing commands that do not have a shortcut key set. It also includes commands to get some context information (such as caret position).
See the README for details.
Return to “Visual Studio Code”
Who is online
Users browsing this forum: No registered users and 8 guests