[AutoHotkey v2] QuickLook

What other productivity software are you working with...
Post Reply
Norn
Posts: 469
Joined: 24 Oct 2021 16:10

[AutoHotkey v2] QuickLook

Post by Norn »

It seems that QuickLook is not as powerful as Seer.

Code: Select all

;AUTHOR   : Ken
;Created  : 2024-05-28
;Version  : v1.1 (2025-01-29)
;============================
#Requires AutoHotkey v2
#SingleInstance Force
Persistent


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


#HotIf winActive('ahk_class ThunderRT6FormDC')
space::QuickLook

#HotIf winActive('ahk_class ThunderRT6FormDC') && winExist('ahk_exe QuickLook.exe')
up::QuickLook
down::QuickLook
left::QuickLook
right::QuickLook


QuickLook(*) {
	send '{' A_ThisHotkey '}'
	sleep 1
    if item := XY_Get() {
        try run '"C:\Program Files\QuickLook\QuickLook.exe" "' item '"'
        catch
            trayTip "Please modify the path of QuickLook in the script!", "QuickLook path does not exist"
    }
}



XY_Get()
{
    xyQueryScript := '::$return = <curitem>`; copydata ' A_ScriptHwnd ', "$return", 2`;'

    if xyHwnd := GetXYHWND()
        Send_WM_COPYDATA(xyHwnd, xyQueryScript)
	else return

    return dataReceived
}


GetXYHWND() {
    static xyClass := 'ahk_class ThunderRT6FormDC'

    if WinExist(xyClass) {
        for xyid in WinGetList(xyClass)
            ;if WinGetControls(xyid).length > 10
                return xyid
    }
}


Send_WM_COPYDATA(xyHwnd, message) {
   size := StrLen(message)

   COPYDATA := Buffer(A_PtrSize * 3)
   NumPut("Ptr", 4194305, COPYDATA, 0)
   NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
   NumPut("Ptr", StrPtr(message), COPYDATA, A_PtrSize * 2)

   return SendMessage(0x004A, 0, COPYDATA,, xyHwnd,,,, TimeOut:=3000) ; 0x004A is WM_COPYDATA.
}


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
    )
}
Windows 11 24H2 @100% 2560x1440

Post Reply