Explorer: get name of file under cursor

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 5260
Joined: 19 Dec 2016, 01:58
Location: UK

Explorer: get name of file under cursor

10 Jul 2018, 00:21

- In response to this:
[x64 & x32 fix] DeskIcons - Get/Set Desktop Icon Positions - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 74#p227874

- Here's a way to get the name of the file under the cursor via Acc:

Code: Select all

;[Acc functions] ;Acc library (MSAA) and AccViewer download links - AutoHotkey Community ;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201 ;tested on Windows 7 q:: ;Explorer window/Desktop - get name of file under cursor oAcc := Acc_ObjectFromPoint(vChildID) MouseGetPos,,, hWnd, vCtlClassNN WinGetClass, vWinClass, % "ahk_id " hWnd vText := "" if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass") try vText := oAcc.accValue(vChildID) else if (vWinClass = "Progman") || (vWinClass = "WorkerW") try vText := oAcc.accName(vChildID) MsgBox, % vText oAcc := "" return
- If you experiment with AccViewer, you can get information for, and see the boundaries of, different GUI windows/controls/elements under the cursor.
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

- Also of interest:
.net - c# how to get window explorer Directory path under mouse cursor - Stack Overflow
https://stackoverflow.com/questions/171 ... use-cursor
c# - Get the folder path under cursor? - Stack Overflow
https://stackoverflow.com/questions/786 ... der-cursor
homepage | tutorials
[code boxes are currently not working 100%]
[click the 'Reply with quote' button on a post to see the full indented text]
r2997790
Posts: 24
Joined: 02 Feb 2017, 02:46

Re: Explorer: get name of file under cursor

10 Jul 2018, 23:37

Hi Jesswg,

I was wondering if it was possible to retrieve (in real time) the menu text under a menu?

eg. You press File > Open (and the ACC script would return 'Open' as that is the text under the mouse?

I've had a look at ACC Viewer but it's not possible to have a menu open to interrogate it while using the tool?

Do you think it is possible? Thanks!

Many thanks
R
User avatar
jeeswg
Posts: 5260
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Explorer: get name of file under cursor

10 Jul 2018, 23:48

- Try this to get the text from the GUI element under the cursor.

Code: Select all

;[Acc functions] ;Acc library (MSAA) and AccViewer download links - AutoHotkey Community ;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201 q:: ;get text from GUI element under cursor oAcc := Acc_ObjectFromPoint(vChildID) ;vChildID := 0 ;for a slightly different result uncomment this line vText1 := vText2 := "" try vText1 := oAcc.accName(vChildID) ;get text try vText2 := oAcc.accValue(vChildID) ;get value if !(vText1 = "") Clipboard .= "`r`n" vText1 if !(vText2 = "") && !(vText = vText2) Clipboard .= "`r`n" vText2 oAcc := "" return
- Btw you can use Ctrl+/ to focus a GUI element with AccViewer.
homepage | tutorials
[code boxes are currently not working 100%]
[click the 'Reply with quote' button on a post to see the full indented text]
r2997790
Posts: 24
Joined: 02 Feb 2017, 02:46

Re: Explorer: get name of file under cursor

10 Jul 2018, 23:58

Thank you... it works... wonderful!
r2997790
Posts: 24
Joined: 02 Feb 2017, 02:46

Re: Explorer: get name of file under cursor

11 Jul 2018, 00:59

Jesswg, I've had a play with this and it works pretty well... Thank you.

Is it possible to detect the menu state and only run it to detect menu items when the menu is open?

I also had some trouble getting it to work with Photoshop... seems a bit hit and miss... is there any tips/tricks to get it to be more stable with Adobe? Or perhaps they block/don't expose the menu information? I was working intermittently. Odd.

Thank you for your insights.. super helpful.
User avatar
jeeswg
Posts: 5260
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Explorer: get name of file under cursor

11 Jul 2018, 01:06

- Add these lines at the top between 'q::' and 'oAcc :='.

Code: Select all

DetectHiddenWindows, Off if !WinExist("ahk_class #32768") return
- This will end the subroutine early if no context menu window is detected.
- For Photoshop, which I don't use, I would recommend investigating with AccViewer, try to do the same thing a few times, and look for patterns for when it does/doesn't work.
- Also, try using the ToolTip command to inform you of what's happening, if using the script above.
- No problem, glad they're helpful.

- [EDIT:] Also, check the class of the menu by using MouseGetPos when the cursor is over the menu, the menu may be nonstandard, i.e. not of class #32768.

Code: Select all

MouseGetPos, vCurX, vCurY, hWnd, vCtlClassNN WinGetClass, vWinClass, % "ahk_id " hWnd MsgBox, % vWinClass
- Also, perhaps a menu 'item' is made up of multiple parts (GUI elements), you can check the boundaries with AccViewer.
homepage | tutorials
[code boxes are currently not working 100%]
[click the 'Reply with quote' button on a post to see the full indented text]
r2997790
Posts: 24
Joined: 02 Feb 2017, 02:46

Re: Explorer: get name of file under cursor

11 Jul 2018, 05:21

Thank you very much for this feedback... the use case I'm looking to implement is a 'real-time' text translation of menus.

Unfortunately I often have to us apps which don't have english as the first language (but which I am broadly familiar with) and I want to be able to display a (translated) tooltip of the menu item I am currently on top of.

Your input will help a lot.

Thank you.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: bastage, cocobanana, joefiesta, leosouza85 and 46 guests