controlsend problems (Help!)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

controlsend problems (Help!)

06 May 2019, 11:56

ok im having this problem!!!

Code: Select all

n=TheFileinThisFolder.jpg
explorer is open to the indicated files folder...
winspy reports the following:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
screenshots
ahk_class CabinetWClass

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 799, 279 (less often used)
In Active Window: 2001, -243

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<

Color: 0x000000 (Blue=00 Green=00 Red=00)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: -1202 top: 522 width: 638 height: 478

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<
(1): 1,087 items (Disk free space: 56.7 GB)
(2): 544 MB
(3): Computer

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
Address: C:\Games\utilities\Steam\userdata\39045926\760\remote\383120\screenshots
screenshots
Namespace Tree Control
Tree View
ShellView

>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<
Shell Preview Extension Host
Namespace Tree Control

>>>>( TitleMatchMode=slow Visible Text )<<<<
1,087 items (Disk free space: 56.7 GB)

>>>>( TitleMatchMode=slow Hidden Text )<<<<
i have tried ALL of these while the explorer window is active.....

Code: Select all

Run, explorer /select`,""C:\this folder\with\files\screenshots"",,,ProgID

ControlSend,ahk_class CabinetWClass,%n%,screenshots,,
ControlSend,ahk_class CabinetWClass,%n%
ControlSend,screenshots,%n%,ahk_class CabinetWClass
ControlSend,screenshots,%n%
ControlSend,,%n%,screenshots
controlsend, ahk_class CabinetWClass,%n%
ControlSend,,%n%, ahk_class CabinetWClass
ControlSend,ProgID,%n%, ahk_class CabinetWClass
ControlSend,ProgID,%n%
ControlSend,,%n%,ProgID
ControlSend,,%n%,ClassNN ProgID
ControlSend,ClassNN ProgID,%n%
ControlSend,,%n%, ahk_pid ProgID
ControlSend,ahk_pid ProgID,%n%
ControlSend,ahk_pid ProgID,%n%, ahk_class CabinetWClass
ControlSend,%ProgID%,%n%, ahk_class CabinetWClass
ControlSend,%ProgID%,%n%
ControlSend,,%n%,%ProgID%
ControlSend,,%n%,ClassNN %ProgID%
ControlSend,ClassNN %ProgID%,%n%
ControlSend,,%n%, ahk_pid %ProgID%
ControlSend,ahk_pid %ProgID%,%n%
ControlSend,ahk_pid %ProgID%,%n%, ahk_class CabinetWClass
ControlSend,ahk_pid %ProgID%,%n%,ahk_pid %ProgID%
ControlSend,screenshots,%n%
ControlSend,ahk_class CabinetWClass,%n%
ControlSend,%n%,screenshots
ControlSend,%n%,ahk_class CabinetWClass,%n%

NOTHING here is working inside explorer to highlight the file listed in %n%
i HATE control-send so much! it never works and is always a WALL whenever i program! its extremely anti intuitive!
It makes me want to throw bricks!! :headwall:

im just trying to get controlsend to do the job that send %n% already does while the explorer window is active! so WTH!


all of that work above cant accomplish what:

Code: Select all

send %n%
can do!!

Mod edit: Even when you're frustrated, try to behave.
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

06 May 2019, 22:53

So the list of attempts has gotten bigger...

here is more proof that controlSend does not work with win7-ult-x64 Explorer.exe

Code: Select all

n=TheFileinThisFolder.jpg
Run, explorer /select`,""C:\this folder\with\files\screenshots"",,,ProgID

controlSend, SysListView321,%n%
controlSend, screenshots,%n%,SysListView321
controlSend, screenshots,%n%,ToolbarWindow322
controlSend, screenshots,%n%
controlSend, ahk_class WorkerW,%n%,SysListView321
controlSend, ahk_class WorkerW,%n%,ToolbarWindow322
controlSend, ahk_class WorkerW,%n%
controlSend, ahk_id %ProgID%,%n%,SysListView321
controlSend, ahk_id %ProgID%,%n%,ToolbarWindow322
controlSend, ahk_id %ProgID%,%n%
controlSend,ToolbarWindow322,%n%
controlSend,,%n%,ToolbarWindow322
controlSend,screenshots,%n%,ToolbarWindow322
ControlSend,ahk_class CabinetWClass,%n%,screenshots,,
ControlSend,ahk_class CabinetWClass,%n%
ControlSend,screenshots,%n%,ahk_class CabinetWClass
ControlSend,screenshots,%n%
ControlSend,,%n%,screenshots
controlsend, ahk_class CabinetWClass,%n%
ControlSend,,%n%, ahk_class CabinetWClass
ControlSend,ProgID,%n%, ahk_class CabinetWClass
ControlSend,ProgID,%n%
ControlSend,,%n%,ProgID
ControlSend,,%n%,ClassNN ProgID
ControlSend,ClassNN ProgID,%n%
ControlSend,,%n%, ahk_pid ProgID
ControlSend,ahk_pid ProgID,%n%
ControlSend,ahk_pid ProgID,%n%, ahk_class CabinetWClass
ControlSend,%ProgID%,%n%, ahk_class CabinetWClass
ControlSend,%ProgID%,%n%
ControlSend,,%n%,%ProgID%
ControlSend,,%n%,ClassNN %ProgID%
ControlSend,ClassNN %ProgID%,%n%
ControlSend,,%n%, ahk_pid %ProgID%
ControlSend,ahk_pid %ProgID%,%n%
ControlSend,ahk_pid %ProgID%,%n%, ahk_class CabinetWClass
ControlSend,ahk_pid %ProgID%,%n%,ahk_pid %ProgID%
ControlSend,screenshots,%n%
ControlSend,ahk_class CabinetWClass,%n%
ControlSend,%n%,screenshots
ControlSend,%n%,ahk_class CabinetWClass,
none of the above are able to highlight "TheFileinThisFolder.jpg". cotrolsend -still- cant do the job. No highlighting of the file occurs.
gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: controlsend problems (Help!)

06 May 2019, 23:42

I can't speak for Win7, but on Win10 with AHK 1.1.30.03 this works for me while the explorer window is active:

Code: Select all

controlsend,DirectUIHWND3 ,%n% , ahk_class CabinetWClass
with DirectUIHWND3 being the ClassNN of the control that shows the folder contents/file names and ahk_class CabinetWClass being the class of the explorer window... determined with AHK's WindowSpy.ahk script:
window spy.jpg
window spy.jpg (26.05 KiB) Viewed 2718 times

The control might have a a different name on Win7, but I am pretty sure that it has one.

With the explorer inactive (but not hidden or minimized), this seems to work:

Code: Select all

ControlFocus, DirectUIHWND3 ,ahk_class CabinetWClass
controlsend,DirectUIHWND3 ,%n% , ahk_class CabinetWClass
Edit: Of course, there could be more than one explorer window with this ahk_class - a wintitle including the folder name (in my case jpg, see image above) helped me in this case. The PID that you created with Run would probably be even better.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: controlsend problems (Help!)

06 May 2019, 23:53

- In these types of situations, I'd try sending keys to every control. You can use WinGet ControlList.
- I might also try ControlGetFocus.
- This worked for me:

Code: Select all

q:: ;explorer - send keys
WinGet, hWnd, ID, ahk_class CabinetWClass
ControlFocus, DirectUIHWND3, % "ahk_id " hWnd
ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
ControlSend, % vCtlClassNN, abc, % "ahk_id " hWnd
return

w:: ;testing explorer - send keys
ControlGetFocus, vCtlClassNN, A
;ControlSend, ahk_parent, abc, A ;didn't work
;MsgBox, % vCtlClassNN ;DirectUIHWND3
ControlSend, % vCtlClassNN, abc, A
return
- @gregster: Nice work.

- I would use a COM approach to set the focused/selected file:
- I've added this to my Explorer tutorial.

Code: Select all

q:: ;explorer - select file by name
;where vName can be a name or path
vName := "New Text Document.txt"
;vName := A_Desktop "\New Text Document.txt"
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		;SVSI_FOCUSED := 0x10 ;SVSI_ENSUREVISIBLE := 0x8
		;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
		;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
		oItems := oWin.Document.Folder.Items
		try oWin.Document.SelectItem(vName, 0x1D)
		break
	}
}
oWin := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 02:06

quick reply:

gregster » Yesterday, 23:42
your lines
ControlFocus, DirectUIHWND3 ,ahk_class CabinetWClass
controlsend,DirectUIHWND3 ,%n% , ahk_class CabinetWClass
had an effect, they hilighted the item but caused a whole bunch of tone errors and screen jumping.
so that's progress!

jeeswg ill check your proposals out shortly.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: controlsend problems (Help!)

07 May 2019, 02:14

Re. jumping around: when sending literal text use {Raw} or {Text}. Although, even if you can get it to work, I'd still use the COM approach, as sending keys can be risky.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 02:23

@gregster
i had to add
SplitPath,n,,,,n,
before the controlsend to lop off the extension.
then the error bells stopped ringing and it highlights the intended file nicely.

though if i had a png and a bmp of the same name in there it'd likely not land on the jpg without the extension.
more research required..
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 02:50

@jeeswg

I gave your code a shot, with the slightest modification for my current script, but it appears to do nothing. perhaps the fault of windows 7 or my outdated AHK install. im not sure.. both you and Greg have a different win-spy then me.

My AHK version is Version v1.1.09.03 ill note the last time i updated i had to retool about 35 scripts inside my lib because of the changes. Updates are great accept when they break content. not that a lot has changed but im using a lot of com stuff and calls and code written by others from back in 2016. But manipulating what file is selected in explorer window shouldn't require an update or anything.

as you say, im not a fan of sending keystrokes to a window instead of simply highlighting the element with a win-message or the like. I prefer the clean approach. But your code below didn't hook anything in particular. i might as well just show the actual code i came up with for the whole event and how i installed your method. as my instillation might be at fault.

Code: Select all

#f12::   ; ----Steam Snapshots Open Fldr-------
a:=b:=f:=n:=0
; 99999999 is not my steam id, i changed it for this forum..
Loop,C:\Games\utilities\Steam\userdata\99999999\760\remote\*,2
{
	Loop, %A_LoopFileFullPath%\screenshots\*.jpg,0
	{
		a:=A_LoopFileTimeCreated
		if(a>b)
		{
		f:=A_LoopFileFullPath
		b:=a
		n:=A_LoopFileName
		}
	}
}

Run, explorer /select`,""%f%"",,,ProgID
sleep 3333 ; this sleep is to allow a folder full of images to populate the display. waiting for list population--
;   --is why (Run, explorer /select`,""%f%"") is not automatically highlighting %n%

;TBE's approach... aka lame....~~~~~~Works, but is risky.
;send %n%

;Gregster's approach~~~~~~~~~~~Works, but not with file extensions, less risky.
;SplitPath,n,,,,n, ; removes extension and path from file name.
;controlsend,DirectUIHWND3,%n%,ahk_class CabinetWClass

;jeeswg's approach~~~~~~~~~~~Not working. but Potentially risk-less.
WinGet, hWnd, ID, A
for oWin in ComObjCreate("Shell.Application").Windows
{
	if (oWin.HWND = hWnd)
	{
		;SVSI_FOCUSED := 0x10 ;SVSI_ENSUREVISIBLE := 0x8
		;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
		;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
		oItems := oWin.Document.Folder.Items
		try oWin.Document.SelectItem(n, 0x1D)
		break
	}
}
oWin := ""
return
Last edited by ThumpieBunnyEve on 07 May 2019, 03:05, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: controlsend problems (Help!)

07 May 2019, 03:04

For the WinGet line, try: ahk_class CabinetWClass instead of A.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 03:18

Code: Select all

WinGet, hWnd, ID, DirectUIHWND3
WinGet, hWnd, ID, ClassNN DirectUIHWND3
WinGet, hWnd, ID, ahk_class DirectUIHWND3
WinGet, hWnd, ID, A
WinGet, hWnd, ID, screenshots
WinGet, hWnd, ID, CabinetWClass
WinGet, hWnd, ID, ahk_class CabinetWClass
WinGet, hWnd, ID, %ProgID%
WinGet, hWnd, ID, ahk_id %ProgID%
WinGet, hWnd, ID, WorkerW
WinGet, hWnd, ID, ahk_class WorkerW
WinGet, hWnd, ID, SysListView321
WinGet, hWnd, ID, ahk_class SysListView321
none of these worked so far.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: controlsend problems (Help!)

07 May 2019, 03:24

Try specifying the path instead of the name.
Btw why do you want to select the file in a folder? I'd just open the file directly.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 03:40

after i take an image the purpose is not to open it in a viewer or image editor, but to navigate to that particular files location, so that it can be opened or dragged and dropped to messengers for sending, or emailed, or right clicked and processed through filters and scalers like xnview, or opened in alternate editors.

further more each -folder- might be sorted differently, folder 23451 might be list-view, folder 1216687 might be details-view sorted ascending. folder 776413 might be large view sorted descending.

leaping to the selected file and highlighting it allows me to find it in spite of sorting conventions, and in spite of the taxing 999999/370/######/screenshots dynamic steam uses for user-content cataloging. and allows me options to share, edit, pack up as a set, convert, or delete as i see fit. as well as open too of course.
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 03:45

Code: Select all

WinGet, hWnd, ID, %n%
WinGet, hWnd, ID, %f%
WinGet, hWnd, ID, A_LoopFileDir
WinGet, hWnd, ID, A_LoopFileFullPath
these all failed
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: controlsend problems (Help!)

07 May 2019, 03:53

Did you try my script by itself, on a folder containing say a few files, that was already the active window.

Perhaps you need to wait a while before the folder is ready. Perhaps you could get the file count via Loop Files, and check oWin.Document.Folder.Items.count repeatedly until it matches.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
ThumpieBunnyEve
Posts: 109
Joined: 03 Aug 2016, 19:03

Re: controlsend problems (Help!)

07 May 2019, 03:58

well the 3 second delay is working well enough to get the list to populate and then move to a selection in it. the problem with your script isn't in waiting for the list to populate to proceed. that's covered by the delay.

the problem with yours seems to be it -never- highlights a file even if there is only 3 in the same folder.

as for taking it out and running it in a script solo i can try that tomorrow after some sleep.
i do understand how things like #noenv can affect the ability to call upon elements.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: downstairs, Google [Bot], sebalotek and 192 guests