热键不生效求助 Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

silly123
Posts: 2
Joined: 23 Feb 2024, 01:54

热键不生效求助

Post by silly123 » 23 Feb 2024, 01:57

在最新win11的终端wt里,监听不了win+e的快捷键,脚本没有生效,其他窗口是正常的,想问一下,是脚本没对还是大家一样?

Code: Select all

#Requires AutoHotkey v2.0
#NoTrayIcon
#SingleInstance Force

global pathObj := {}

Persistent
OnClipboardChange(ClipChanged)
return

#e::
{
    try {
        ; MsgBox(pathObj.type . "~~~" . pathObj.value . "!!!" . HasProp(pathObj, 'type'))
        if (HasProp(pathObj, 'type')) {
            switch pathObj.type {
                case 'dir':
                    OpenExplore(pathObj.value)
                case 'file': (
                    OpenExplore(pathObj.value, pathObj.file)
                )
                case 'url':
                    Run(pathObj.value)
                default:
                    Run("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
            }
        } else {
            Run("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
        }
    }
    catch Error {
        MsgBox('Error')
        ; Run("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
    }
}

; Open or activate Explore through a folder path, and focus file if you set
OpenExplore(path, focusFile := "") {
    isActived := 0
    SetTitleMatchMode(3)
    If WinExist(path) {
        WinActivate
        isActived := 1
    }
    if(isActived && focusFile = "") {
        return
    }
    Focus(delay := 100){
        if(focusFile){
            Sleep(delay)
            Send(focusFile)
        }
    }
    Activate(window) {
        try explorer_path := window.Document.Folder.Self.Path
        If (explorer_path = "") {
            return 'continue'
        }
        ; 如果存在同路径
        if (RegExMatch(explorer_path, StrReplace(path, "\", "\\"))) {
            if(isActived = 0){
                WinActivate("ahk_id " WinGetID(explorer_path))
                isActived := 1
            }
            if(window.Document.FocusedItem.Name != focusFile){
                Focus()
            }
            return 'break'
        }
    }
    ; 如果没有激活的窗口
    if (LoopWindows(Activate) != "break") {
        ; Open new explore window
        Run("explore " . path)
        Focus()
    }
}

LoopWindows(fn) {
    If WinExist("ahk_class CabinetWClass") ; explorer
    {
        loopResult := ""
        for window in ComObject("Shell.Application").Windows
        {
            ; return break or you want join text
            output := fn(window)
            switch output {
                case 'break':
                    loopResult .= output
                    break
                case 'continue':
                    continue
                default:
                    loopResult .= output
            }
        }
        return loopResult
    }
}

ClipChanged(Type) {
    global
    clipSaved := Trim(A_Clipboard, '`"')
    isFileOrDir := FileExist(clipSaved) != "" && FileGetAttrib(clipSaved) != ""
    ; MsgBox(clipSaved isFileOrDir)
    switch 1 {
        case (isFileOrDir && DirExist(clipSaved) != ""):
            pathObj := { type: 'dir', value: clipSaved }
        case isFileOrDir:
            pathObj := { type: 'file', value: RegExReplace(clipSaved, "i)\\[^\\]+$"), file: RegExReplace(clipSaved, ".+\\(?=[^\\]+$)") }
        case (RegExMatch(clipSaved, "(?:https?:\/\/|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(?:\/\S*)?$") > 0):
            pathObj := { type: 'url', value: clipSaved }
        default:
            pathObj := { value: clipSaved }
    }
    if (HasProp(pathObj, 'type')) {
        ToolTip(pathObj.type . ": " . pathObj.value)
        Sleep(1000)
        ToolTip()  ; 关闭提示.
    }
}

WKen
Posts: 183
Joined: 21 Feb 2023, 00:01

Re: 热键不生效求助  Topic is solved

Post by WKen » 23 Feb 2024, 09:54

需要以管理员身份运行

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force

#e::
{
   msgbox "有权限"
}

silly123
Posts: 2
Joined: 23 Feb 2024, 01:54

Re: 热键不生效求助

Post by silly123 » 25 Feb 2024, 21:17

@WKen
我遇到新的问题,就是我先按住win键不松开,然后再去按e时会触发锁屏,我看了相关文档然后设置了掩码,但好像并没有生效T_T :(

Code: Select all

#Requires AutoHotkey v2.0
#NoTrayIcon
#SingleInstance Force

full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        Run '*RunAs "' A_ScriptFullPath '" /restart'
    }
    ExitApp
}


global pathObj := {}

Persistent
OnClipboardChange(ClipChanged)

A_MenuMaskKey := "vkFF"  ; vkFF 是未映射的.
#e::
{
    try {
        ; MsgBox(pathObj.type . "~~~" . pathObj.value . "!!!" . HasProp(pathObj, 'type'))
        if (HasProp(pathObj, 'type')) {
            switch pathObj.type {
                case 'dir':
                    OpenExplore(pathObj.value)
                case 'file': (
                    OpenExplore(pathObj.value, pathObj.file)
                )
                case 'url':
                    Run(pathObj.value)
                default:
                    Run("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
            }
        } else {
            Run("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
        }
    }
    catch Error {
        MsgBox('Error')
        ; Run("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
    }
}

; Open or activate Explore through a folder path, and focus file if you set
OpenExplore(path, focusFile := "") {
    isActived := 0
    SetTitleMatchMode(3)
    If WinExist(path) {
        WinActivate
        isActived := 1
    }
    if(isActived && focusFile = "") {
        return
    }
    Focus(delay := 100){
        if(focusFile){
            Sleep(delay)
            Send(focusFile)
        }
    }
    Activate(window) {
        try explorer_path := window.Document.Folder.Self.Path
        If (explorer_path = "") {
            return 'continue'
        }
        ; 如果存在同路径
        if (RegExMatch(explorer_path, StrReplace(path, "\", "\\"))) {
            if(isActived = 0){
                WinActivate("ahk_id " WinGetID(explorer_path))
                isActived := 1
            }
            if(window.Document.FocusedItem.Name != focusFile){
                Focus()
            }
            return 'break'
        }
    }
    ; 如果没有激活的窗口
    if (LoopWindows(Activate) != "break") {
        ; Open new explore window
        Run("explore " . path)
        Focus()
    }
}

LoopWindows(fn) {
    If WinExist("ahk_class CabinetWClass") ; explorer
    {
        loopResult := ""
        for window in ComObject("Shell.Application").Windows
        {
            ; return break or you want join text
            output := fn(window)
            switch output {
                case 'break':
                    loopResult .= output
                    break
                case 'continue':
                    continue
                default:
                    loopResult .= output
            }
        }
        return loopResult
    }
}

ClipChanged(Type) {
    global
    clipSaved := Trim(A_Clipboard, '`"')
    isFileOrDir := FileExist(clipSaved) != "" && FileGetAttrib(clipSaved) != ""
    ; MsgBox(clipSaved isFileOrDir)
    switch 1 {
        case (isFileOrDir && DirExist(clipSaved) != ""):
            pathObj := { type: 'dir', value: clipSaved }
        case isFileOrDir:
            pathObj := { type: 'file', value: RegExReplace(clipSaved, "i)\\[^\\]+$"), file: RegExReplace(clipSaved, ".+\\(?=[^\\]+$)") }
        case (RegExMatch(clipSaved, "(?:https?:\/\/|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(?:\/\S*)?$") > 0):
            pathObj := { type: 'url', value: clipSaved }
        default:
            pathObj := { value: clipSaved }
    }
    if (HasProp(pathObj, 'type')) {
        ToolTip(pathObj.type . ": " . pathObj.value)
        Sleep(1000)
        ToolTip()  ; 关闭提示.
    }
}

WKen
Posts: 183
Joined: 21 Feb 2023, 00:01

Re: 热键不生效求助

Post by WKen » 26 Feb 2024, 14:12

这里没有出现你说的情况

Post Reply

Return to “请求帮助”