I knew nothing about programming, scripting before using XYplorer, I'm trying to learn more about scripting, AHK v2 looks easier to remember than v1.
i upgraded to AHKv2, but continue to compile into EXE for v1 (set the Base as v1). i did find this converter on their forums - [url wrote:https://github.com/mmikeww/AHK-v2-script-converter/[/url] and used
QuickConvertorV2.ahk to create v2-versions of my scripts and it worked really well for mine (not super complicated scripts).
Yep, this helps convert the little bit I learned in v1, thanks. For this complex script it fails to convert, a lot of errors:
Code: Select all
#Requires AutoHotkey v2.0.2
; Get our own HWND (we have no visible window)
DetectHiddenWindows(true)
G_OwnHWND := WinExist("Ahk_PID " DllCall("GetCurrentProcessId"))
G_OwnHWND += 0
; Get messages back from XYplorer
OnMessage(0x4a, Receive_WM_COPYDATA)
F1::
{ ; V1toV2: Added bracket
path := XYGetPath()
all := XYGetAll()
sel := XYGetSelected()
MsgBox(path)
MsgBox(all)
MsgBox(sel)
return
} ; Added bracket before function
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() {
if WinActive("ahk_class ThunderRT6FormDC")
{
xyHwnd := WinGetID("ahk_class ThunderRT6FormDC")
} else {
oxyHwnd := WinGetList("ahk_class ThunderRT6FormDC")
axyHwnd := Array()
xyHwnd := oxyHwnd.Length
For v in oxyHwnd
{
axyHwnd.Push(v)
}
if (axyHwnd.Length)
xyHwnd := axyHwnd[1]
}
return xyHwnd
}
Send_WM_COPYDATA(message) {
xyHwnd := GetXYHWND()
if !(xyHwnd)
return
size := StrLen(message)
if !(StrLen(Chr(0xFFFF))) {
data := Buffer(size * 2, 0) ; V1toV2: if 'data' is a UTF-16 string, use 'VarSetStrCapacity(&data, size * 2)'
StrPut(message, &data, size, "UTF-16")
} else {
data := message
}
COPYDATA := Buffer(A_PtrSize * 3, 0) ; V1toV2: if 'COPYDATA' is a UTF-16 string, use 'VarSetStrCapacity(©DATA, A_PtrSize * 3)'
NumPut("Ptr", 4194305, COPYDATA, 0)
NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
NumPut("Ptr", &data, COPYDATA, A_PtrSize * 2)
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, "UPtr")
copyOfData := StrGet(stringAddress)
cbData := NumGet(lParam + A_PtrSize, "UPtr") / 2
dataReceived := SubStr(copyOfData, 1, cbData)
return
}
I install two versions and can run two versions of the script, but for beginners like me, it seems that there is no need to continue learning the syntax of v1.
For AHK v2:
Code: Select all
#Requires AutoHotkey v2.0.2
; Get our own HWND (we have no visible window)
DetectHiddenWindows(true)
G_OwnHWND := WinExist("Ahk_PID " DllCall("GetCurrentProcessId"))
G_OwnHWND += 0
; Get messages back from XYplorer
OnMessage(0x4a, Receive_WM_COPYDATA)
global dataReceived := ""
F1::
{
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)
{
xyQueryScript := '::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() {
static xyClass := 'ahk_class ThunderRT6FormDC'
if hwnd := WinActive(xyClass)
return hwnd
else if WinExist(xyClass)
return WinGetList(xyClass)[1]
}
Send_WM_COPYDATA(message) {
xyHwnd := GetXYHWND()
if !(xyHwnd)
return
size := StrLen(message)
if !(StrLen(Chr(0xFFFF))) {
data := Buffer(size * 2, 0)
StrPut(message, &data, size, "UTF-16")
} else {
data := message
}
COPYDATA := Buffer(A_PtrSize * 3)
NumPut("Ptr", 4194305, COPYDATA, 0)
NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
NumPut("Ptr", StrPtr(data), COPYDATA, A_PtrSize * 2)
return DllCall("User32.dll\SendMessageW", "Ptr", xyHwnd, "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "Ptr")
}
Receive_WM_COPYDATA(wParam, lParam, *) {
global dataReceived := StrGet(
NumGet(lParam + 2 * A_PtrSize, 'Ptr'), ; COPYDATASTRUCT.lpData, ptr to a str presumably
NumGet(lParam + A_PtrSize, 'UInt') / 2 ; COPYDATASTRUCT.cbData, count bytes of lpData, /2 to get count chars in unicode str
)
}