how send keys to inactive windows explorer? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

how send keys to inactive windows explorer?

27 Oct 2017, 08:46

I'm trying to shift through found movies in a mediaplayer (MPC-HC) found with windows explorer in a library.
So instead of going to the next or previous movie in the same folder, i'd like to browse to the found movies in the windows explorer that are in different folder.

I thought by doing this by sending a UP/DOWN + ENTER to the last active windows explorer where a double clicked movie-file has started the mediaplayer. (MPC-HC has been set to run only once)
But I can't seem to send UP/DOWN + enter to the last active Explorer without activating it first.

Any help welcome. Thank you.

Code: Select all

#IfWinActive, ahk_class MediaPlayerClassicW
{
 	 ^down::
		; WinGet aExplorerList, List, ahk_class CabinetWClass		;;;get array or all explorer windows, first one is the last active one
		; WinActivate ahk_id %aExplorerList1%
		; ControlSend DirectUIHWND3, {down}, ahk_id %aExplorerList1%
		ControlSend DirectUIHWND3, {down}, ahk_class CabinetWClass   ; ahk_id %aExplorerList1%
	return
return
}
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?

11 Nov 2017, 07:21

Isn't there anyone that knows how to send a keystroke to an in-active Windows-explorer?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how send keys to inactive windows explorer?

11 Nov 2017, 07:38

Here's some experimenting, another solution might be COM.

Code: Select all

q::
;these didn't work
;ControlSend, DirectUIHWND3, {Down}, ahk_class CabinetWClass
;ControlSend,, {Down}, ahk_class CabinetWClass
;ControlSend, ahk_parent, {Down}, ahk_class CabinetWClass

;this worked but scrolled down and right
;ControlSend, ScrollBar1, {Down}, ahk_class CabinetWClass

;this worked but also scrolls down a bit
ControlSend, ScrollBar2, {Down}, ahk_class CabinetWClass
return

;w::
WinGet, vCtlList, ControlList, A
Loop, Parse, vCtlList, `n
{
	vCtlClassNN := A_LoopField
	if (vCtlClassNN = "DirectUIHWND3")
		continue
	ControlSend, % vCtlClassNN, {Down}, A
	Sleep, 500
	ToolTip, % vCtlClassNN
}
MsgBox, % "done"
return
[EDIT:] Here's a COM solution:

Code: Select all

q:: ;explorer - focus next file
WinGet, hWnd, ID, ahk_class CabinetWClass
for oWin in ComObjCreate("Shell.Application").Windows
	if (oWin.HWND = hWnd)
	{
		vPath := oWin.Document.FocusedItem.path
		vIsMatch := 0
		for oItem in oWin.Document.Folder.Items
		{
			if vIsMatch
			{
				;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8
				;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
				;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
				oWin.Document.SelectItem(oItem, 0x1D)
				break
			}
			if (oItem.path = vPath)
				vIsMatch := 1
		}
	}
oWin := oItem := ""
return
Last edited by jeeswg on 12 Nov 2017, 17:17, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?

12 Nov 2017, 17:05

Hey,

Thanks Jeeswg !
The COM did it, although it's not that obvious how to send a [enter] or [up] the same way! :(
I was hoping the more obvious and straightforward (Control) Send would be able to be used :(

thanks though, now I need to understand how to send other things with this oWin.Document like enter to start the next selected file....
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how send keys to inactive windows explorer?

12 Nov 2017, 17:15

I would do something like this to run the file, instead of Enter:
Run, "%vPath%"
Run, % Chr(34) vPath Chr(34)

Code: Select all

w:: ;explorer - focus previous file
WinGet, hWnd, ID, ahk_class CabinetWClass
for oWin in ComObjCreate("Shell.Application").Windows
	if (oWin.HWND = hWnd)
	{
		vPath := oWin.Document.FocusedItem.path
		for oItem in oWin.Document.Folder.Items
		{
			if (oItem.path = vPath)
			{
				;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8
				;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
				;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
				if (A_Index > 1)
					oWin.Document.SelectItem(oItem2, 0x1D)
				break
			}
			oItem2 := oItem
		}
	}
oWin := oItem := oItem2 := ""
return
It's possible that there are some better solutions than this.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?

14 Nov 2017, 04:31

If you telling me to capture the next file path from explorer and then just run it, then the example doesn't seem to work. But I'll try to figure it out....
Also, although it moves to the previous file in the explorer-list, I can't seem to go to the next file :(

I'd like to have the played movie to be selected in explorer to be able to do other things with it then just playing it in MPC-HC.

thanks you
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how send keys to inactive windows explorer?

14 Nov 2017, 04:53

Erm so q to move to the next file (down) doesn't work?
But w to move to the previous file (up) does work?
Instead of {Enter}, I would expect Run, % oItem.path to work. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?

14 Nov 2017, 06:37

I'd just figured out how your code works :) Thanks, it helped me a lot.

So it seems there is no way to get the index of the line that has focus in windows explorer. That's why we need to loop through all the files to figure out what is the next or previous file...
This does take a lot of time if you have thousands of files in a library!!!!! Isn't there an other way?

Made my own (for me more readable) code from it:
Just need to find out haw I start the new media, because "RUN moviepath" doesn't do it :(
I could use SEND, but then you'll always see the windows popup in MPC-HC.

Code: Select all

down::
	WinGet, hWnd, ID, ahk_class CabinetWClass 						;;;get last active win-explorer handle
	for oWin in ComObjCreate("Shell.Application").Windows 			;;;find the window-object of that last active win-explorer
		if (oWin.HWND=hWnd)
			break
	for oItem in oWin.Document.Folder.Items							;;;get the focust file-index
		if (oItem.path=oWin.Document.FocusedItem.path)
			n:=A_Index-1
			
	;oItem:=oWin.Document.Folder.Items.item(n-1)					;;;get previous file in windows explorer
	oItem:=oWin.Document.Folder.Items.item(n+1)						;;;get next file in windows explorer
	oWin.Document.SelectItem(oItem, 0x1D)							;;;set focus to only that file
	;;;SVSI_FOCUSED=0x10  _ENSUREVISIBLE:=0x8  _DESELECTOTHERS:=0x4  _EDIT:=0x3  _SELECT:=0x1  _DESELECT:=0x0
	
	;run oItem.path   						;;;doesn't seem to work
return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how send keys to inactive windows explorer?

14 Nov 2017, 06:53

To run a file, I would try something like:

Code: Select all

Run, % Chr(34) oItem.path Chr(34)
Run, % Chr(34) "C:\Program Files (x86)\K-Lite Codec Pack\MPC-HC64\mpc-hc64.exe" Chr(34) " " Chr(34) oItem.path Chr(34)
Your path to Media Player Classic, might be slightly different.

I will try some things at some point, like Acc, and my old attempt to recreate the SendInput function, as an improved version of ControlSend.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?

14 Nov 2017, 09:48

Thank you very much! Run, % Chr(34) oItem.path Chr(34) works
So now I'll try SendInput because of the use list to go through to find the focused file... Or there has to be an other way to find the previous or next file...
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?  Topic is solved

14 Nov 2017, 12:05

SOLVED,

I found the solution to solve the bug with using ControlSend to send keys to an out of focus Windows Explorer!
Seems I need to use ControlFocus DirectUIHWND3 on Windows Explorer, in advance of using ControlSend

So now I can swap and loop through movies in MPC-HC, found within Windows Explorer that has started MPC-HC with playing the selected movie by double clicking it.
After exit of the media-player MPC-HC, Windows Explorer does show the last played movie :) Now i can find the correct movie and have it selected to work with.

Code: Select all

#IfWinActive, ahk_class MediaPlayerClassicW
{
	up::
		ControlFocus DirectUIHWND3, ahk_class CabinetWClass				;;;BUGG: needed before using ControlSend
		ControlFocus DirectUIHWND3, ahk_class MediaPlayerClassicW
		ControlSend DirectUIHWND3, {up}{enter}, ahk_class CabinetWClass
	return
 	down::
		ControlFocus DirectUIHWND3, ahk_class CabinetWClass				;;;BUGG: needed before using ControlSend
		ControlFocus DirectUIHWND3, ahk_class MediaPlayerClassicW
		ControlSend DirectUIHWND3, {down}{enter}, ahk_class CabinetWClass
	return
return
}
Thanks for your help.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: how send keys to inactive windows explorer?

14 Nov 2017, 13:28

- That's very interesting, it's a simple principle, but not really one I'd thought about, I will bear that in mind when doing tests involving ControlSend, and I will do some tests now on Internet Explorer. E.g. you saw my loop above where I tried sending keys to every control, well, I can add a ControlFocus line before each ControlSend to see if it makes a difference.
- I will continue to investigate some of the solutions I mentioned. Cheers.

[EDIT:] This is great, I'm in Notepad, with an Explorer window open to the right, typing like normal, the Notepad window doesn't get deactivated, and I see the selection changing in Explorer:

Code: Select all

~q::
~w::
ControlFocus, DirectUIHWND3, ahk_class CabinetWClass
vKey := InStr(A_ThisHotkey, "q") ? "{Up}" : "{Down}"
ControlSend, DirectUIHWND3, % vKey, ahk_class CabinetWClass
return
[EDIT:] A problem I'd been having for a long time, with reliably sending keys to an inactive Internet Explorer window, was solved instantly. This in fact worked regardless of which control was focused.

Code: Select all

q::
ControlFocus, Internet Explorer_Server1, ahk_class IEFrame
Loop, 9
{
	ControlSend, Internet Explorer_Server1, % "^" A_Index, ahk_class IEFrame
	Sleep, 500
}
return
[EDIT:] I've added a note about ControlSend/ControlFocus to my documentation extension tutorial:
jeeswg's documentation extension tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=33596
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
michel
Posts: 60
Joined: 18 Aug 2016, 02:47

Re: how send keys to inactive windows explorer?

15 Nov 2017, 17:07

:)
Maybe we need to warn all others and the autohotkey development, because it looks like a little bug in ControlSend, isn't it?

Return to “Ask For Help”

Who is online

Users browsing this forum: davegish, dentopolis, Green Astronaut, millansoft, murataygun, sanmaodo, XMCQCX, yalsch and 54 guests