7z 的鍵盤快速鍵“新增至檔案…”

7z 的鍵盤快速鍵“新增至檔案…”

我想建立一個鍵盤快捷鍵右鍵> 新增到存檔...7z 的功能,在 Windows 檔案總管中。

幾乎與 AutoHotkey 搭配使用:

#z::
    SendInput {AppsKey}a{Enter}
    Return

確實APPSKEY有時A是可以的:

在此輸入影像描述

但有時不行,例如,當所選檔案是資料夾時:

在此輸入影像描述

將為字母「A」選擇另一個選單項目(此處為「新增至 MPC-HC 播放清單」)。

重要筆記:

  • 我可以在regedit.exe文件、資料夾、每個可能的檔案副檔名(太多可能的副檔名!)的各種上下文選單項目中手動查找,但這太長了......不是嗎? (*)

  • 我已經嘗試過“級聯上下文選單”對於 7z(這可以在7z-檔案管理器 > 工具 > 選項... > 7-Zip菜單),但情況更糟。根據上下文,字母不相同,則無法關聯一致的熱鍵

  • 解決方案是 7z 將註冊,&Add to archive...而不僅僅是Add to archive...在上下文選單中。如果我記得很好的話,&在登錄編輯器上下文選單設定中,可以幫助上下文選單使用字母快捷方式。有這個選擇嗎?遺憾的是,這似乎不能直接在 7-zip 中使用。


(*) 版本少的話還可以嗎regedit?即替換Add to archive...&Add to archive?應該用多少個鍵/值來完成此操作?在:

HKEY_CLASSES_ROOT\Folder\ShellEx\ContextMenuHandlers\7-Zip

我懂了:

{23170F69-40C1-278A-1000-000100020000}

這有用嗎?

答案1

嘗試這個

#IfWinActive ahk_class CabinetWClass    ; explorer

    #z::
        ClipSaved := ClipboardAll       ; save the entire clipboard to the variable ClipSaved
        clipboard := ""                 ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
        Send, ^c                        ; copy selected item
        ClipWait, 1                     ; wait for the clipboard to contain data 
        if (!ErrorLevel)                ; If NOT ErrorLevel ClipWait found data on the clipboard
        {
            ; MsgBox, %clipboard%       ; display the path
            FileGetAttrib A, %clipboard%
            if InStr(A, "D")            ; is a folder
                SendInput {AppsKey}aa{Enter}
            else                        ; is a file
                SendInput {AppsKey}a{Enter}
        }
        else
            MsgBox, No file selected
        Sleep, 300 
        clipboard := ClipSaved         ; restore original clipboard
        VarSetCapacity(ClipSaved, 0)   ; free the memory
    return

#IfWinActive

https://www.autohotkey.com/docs/commands/_IfWinActive.htm https://www.autohotkey.com/docs/misc/Clipboard.htm#ClipboardAll https://www.autohotkey.com/docs/commands/FileGetAttrib.htm

編輯

如果我們選擇多個檔案進行 ZIP,這應該可以工作:

#IfWinActive ahk_class CabinetWClass    ; explorer

    #z::
        folder := false
        file := false
        ClipSaved := ClipboardAll       ; save the entire clipboard to the variable ClipSaved
        clipboard := ""                 ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
        Send, ^c                        ; copy selected item
        ClipWait, 1                     ; wait for the clipboard to contain data 
        if (!ErrorLevel)                ; If NOT ErrorLevel ClipWait found data on the clipboard
        {
            Loop, Parse, Clipboard, `n  ; split by linefeed
            {
                LoopField := trim(A_LoopField, "`r`n") ; trim CRs/LFs
                FileGetAttrib A, %LoopField%
                if InStr(A, "D")        ; is a folder
                    folder := true
                else                    ; is a file
                    file := true
            }
            if (folder) 
            {
                if (file)              ; folders and files
                    SendInput {AppsKey}a{Enter}
                else                   ; only folders
                    SendInput {AppsKey}aa{Enter}
            }
            else if (file)             ; only files     
                SendInput {AppsKey}a{Enter}
        }
        else
            MsgBox, No file selected
        Sleep, 300 
        clipboard := ClipSaved         ; restore original clipboard
        VarSetCapacity(ClipSaved, 0)   ; free the memory
    return
    
#IfWinActive

相關內容