2 скрипта в одном ахк файле не работают, но работают один за другим? - PullRequest
0 голосов
/ 12 февраля 2019

Они работают по одному.Тем не менее, они не работают в одном файле ахк.Подскажите что нужно исправить?

; 1) скрипт копирует текст и ссылку в браузере в буфер обмена с помощью кнопки; F2

; Allow partial titlebar text matches.
SetTitleMatchMode, 2

; Create a window title group to match on for our hotkey. 
GroupAdd, myBrowsers, Mozilla Firefox
GroupAdd, myBrowsers, Google Chrome


#IfWinActive, ahk_group myBrowsers
{
F2::
{
    ; Copy user selection to a variable.
    SendInput, ^c
Sleep, 50
    myText := Clipboard
    Sleep, 100

    ; Switch to address bar in browser and copy URL to another variable.
    SendInput, ^l
    Sleep, 100
    SendInput, ^c
    Sleep, 100
    myURL := Clipboard
    Sleep, 100

    ; Format data bits.     
    ;myData := myURL . "`r`n`r`n" .
    myData := myText . "`r`n`r`n" . myURL
    Sleep, 100

    ; Put formatted data back onto clipboard.
    Clipboard := myData
}
Return
} 
#IfWinActive
return

; 2) скрипт Откройте любой файлв проводнике в блокноте по alt + n

; AutoExecute Section must be on the top of the script
#NoEnv
SetWorkingDir %A_ScriptDir%
GroupAdd, Explore, ahk_class CabinetWClass         ; Add a class to the 
group
GroupAdd, Explore, ahk_class ExploreWClass         ; Add a other class to 
the group


; Always on Top CTRL+SPACE on current window
; http://www.labnol.org/software/tutorials/keep-window-always-on- 
top/5213/
^SPACE::  Winset, Alwaysontop, , A


; Open file With Notepad++ from Explorer using Alt+N hotkey
; https://autohotkey.com/board/topic/77665-open-files-with-portable- 
notepad/

#ifWinActive,ahk_group Explore              ; Set hotkeys to work in 
explorer only
; Alt+N
!n::
ClipSaved := ClipboardAll
Clipboard := ""
 Send ^c
ClipWait, 0.5
file := Clipboard
Clipboard := ClipSaved
Run C:\Program Files (x86)\Notepad++\notepad++.exe "%file%"
return

почему один за другим эти скрипты работают нормально, но не в одном файле.Что вы можете порекомендовать?

1 Ответ

0 голосов
/ 12 февраля 2019

Вы не можете иметь секцию AutoExecute дважды или в разных местах в одном скрипте.

; AutoExecute Section must be on the top of the script

#NoEnv
SetWorkingDir %A_ScriptDir%

; Create a window title group to match on for our hotkey. 
GroupAdd, myBrowsers, Mozilla Firefox
GroupAdd, myBrowsers, Google Chrome

GroupAdd, Explore, ahk_class CabinetWClass        ; Add a class to the group
GroupAdd, Explore, ahk_class ExploreWClass         ; Add a other class to the group

; Allow partial titlebar text matches.
SetTitleMatchMode, 2

 ; === end of auto-execute section ===



; Always on Top CTRL+SPACE on current window
; http://www.labnol.org/software/tutorials/keep-window-always-on-top/5213/

^SPACE::  Winset, Alwaysontop, , A



; https://autohotkey.com/docs/commands/_IfWinActive.htm

#IfWinActive,ahk_group Explore  ; Set hotkeys to work in explorer only

    ; Open any file in explorer in notepad by alt + n
    !n::
        ClipSaved := ClipboardAll
        Clipboard := ""
         Send ^c
        ClipWait, 0.5
        file := Clipboard
        Clipboard := ClipSaved
        Run C:\Program Files (x86)\Notepad++\notepad++.exe "%file%"
    return

#IfWinActive, ahk_group myBrowsers

    ; copies the text and link in the browser to the clipboard using the F2 button
    F2::
        ; Copy user selection to a variable.
        SendInput, ^c
        Sleep, 50
        myText := Clipboard
        Sleep, 100
        ; Switch to address bar in browser and copy URL to another variable.
        SendInput, ^l
        Sleep, 100
        SendInput, ^c
        Sleep, 100
        myURL := Clipboard
        Sleep, 100
        ; Format data bits.     
        ;myData := myURL . "`r`n`r`n" .
        myData := myText . "`r`n`r`n" . myURL
        Sleep, 100
        ; Put formatted data back onto clipboard.
        Clipboard := myData
    Return

#IfWinActive  ; turn off context sensitivity
...