StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
sery111  
#1 Posted : Thursday, July 18, 2024 4:56:59 AM(UTC)
sery111

Rank: Member

Reputation:

Groups: Approved
Joined: 12/29/2021(UTC)
Posts: 13

This ahk script can get the path of the selected files/folders or of the current folder with a single keystroke,
How to convert this ahk script to StrokesPlus script?



#p::MsgBox % GetSelectedFilePaths()
GetSelectedFilePaths() {
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
if (winClass ~= "Progman|WorkerW|(Cabinet|Explore)WClass") {
shellWindows := ComObjCreate("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW")
shellFolderView := shellWindows.Item( ComObject(VT_UI4 := 0x13, SWC_DESKTOP := 0x8) ).Document
else {
for window in shellWindows
if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
if !result
result := shellFolderView.Folder.Self.Path
} else {
ClipSave := ClipboardAll
Clipboard := ""
SendInput ^c
ClipWait 2
result := Clipboard
Clipboard := ClipSave
}
Return result
}
Rob  
#2 Posted : Sunday, July 21, 2024 7:10:32 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 430 time(s) in 363 post(s)
You can use the built-in method for this:
Code:
var files = sp.GetSelectedFilesInExplorer(sp.ForegroundWindow().HWnd); //or action.Window.HWnd is used in an action
var str = '';
var delim = '';
for(i = 0; i < files.Length; i++)
{
	str = str + delim + files[i];
	delim = '\r\n';
}
if(str.length == 0) str = '(no files selected)';
sp.MessageBox(str, 'Selected File(s)');
sery111  
#3 Posted : Sunday, July 21, 2024 7:11:25 PM(UTC)
sery111

Rank: Member

Reputation:

Groups: Approved
Joined: 12/29/2021(UTC)
Posts: 13

Can this ahk script apply to XYplorer be converted to StrokesPlus script, and apply to other similar software?


/*
XYGetPath() - paths of target window's selected items
XYGetAll() - paths of all items in the target window's folder
XYGetSelected() - path of target window's folder

example:
F10::
path := XYGetPath()
all := XYGetAll()
sel := XYGetSelected()
MsgBox % path
MsgBox % all
MsgBox % sel
return

*/

; Get our own HWND (we have no visible window)
DetectHiddenWindows, On
G_OwnHWND := WinExist("Ahk_PID " DllCall("GetCurrentProcessId"))
G_OwnHWND += 0

; Get messages back from XYplorer
OnMessage(0x4a, "Receive_WM_COPYDATA")

$F10::
path := XYGetPath()
all := XYGetAll()
sel := XYGetSelected()
MsgBox % path
MsgBox % all
MsgBox % sel
return


XYGetPath()
{
return XY_Get()
}


XYGetAll()
{
return XY_Get(true)
}


XYGetSelected()
{
return XY_Get(, true)
}


XY_Get(bAll:=false, bSelection:=false)
{
global dataReceived, G_OwnHWND

xyQueryScript =
( LTrim Join
::
if (!%bAll% && !%bSelection%) {
$return = "<curpath>";
} elseif (%bAll%) {
$return = listpane(, , , "<crlf>");
} elseif (%bSelection%) {
$return = get("SelectedItemsPathNames", "<crlf>");
}
copydata %G_OwnHWND%, "$return", 2;
)

Send_WM_COPYDATA(xyQueryScript)

return dataReceived
}


GetXYHWND() {
IfWinActive, ahk_class ThunderRT6FormDC
{
WinGet, xyHwnd, ID, ahk_class ThunderRT6FormDC
} else {
WinGet, xyHwnd, List, ahk_class ThunderRT6FormDC
if (xyHwnd)
xyHwnd := xyHwnd1
}

return xyHwnd
}


Send_WM_COPYDATA(message) {
xyHwnd := GetXYHWND()

if !(xyHwnd)
return

size := StrLen(message)
if !(A_IsUnicode) {
VarSetCapacity(data, size * 2, 0)
StrPut(message, &data, size, "UTF-16")
} else {
data := message
}
VarSetCapacity(COPYDATA, A_PtrSize * 3, 0)
NumPut(4194305, COPYDATA, 0, "Ptr")
NumPut(size * 2, COPYDATA, A_PtrSize, "UInt")
NumPut(&data, COPYDATA, A_PtrSize * 2, "Ptr")
result := DllCall("User32.dll\SendMessageW", "Ptr", xyHWND, "UInt", 74, "Ptr", 0, "Ptr", &COPYDATA, "Ptr")
return
}


Receive_WM_COPYDATA(wParam, lParam) {
global dataReceived

stringAddress := NumGet(lParam + 2 * A_PtrSize)
copyOfData := StrGet(stringAddress)
cbData := NumGet(lParam + A_PtrSize) / 2
StringLeft, dataReceived, copyOfData, cbData

return
}
Rob  
#4 Posted : Monday, July 22, 2024 2:39:53 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 430 time(s) in 363 post(s)
S+ already uses WM_COPYDATA for other things and would need to be altered to receive XY's data. The best bet here would be to make a plug-in with its own message pump to send and receive messages with XY.

That's a bit complicated though, if you're not familiar with coding and Windows messaging.
sery111  
#5 Posted : Tuesday, July 23, 2024 3:56:58 PM(UTC)
sery111

Rank: Member

Reputation:

Groups: Approved
Joined: 12/29/2021(UTC)
Posts: 13

Thanks Rob. I'm not a programmer,it seems difficult to do this without using the system clipboard.
Syrianux  
#6 Posted : Wednesday, July 24, 2024 1:31:32 PM(UTC)
Syrianux

Rank: Member

Reputation:

Groups: Approved
Joined: 11/17/2023(UTC)
Posts: 15
United Kingdom

Thanks: 4 times
Hello!

If you happen to use Windows 11, you could perform the same action by just choosing Ctrl + Shift + C as your hotkey. This shortcut lets you copy to the clipboard the path of one or more files you select.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.