Fix SearchFileForEdit in VimDConfig.ahk

Fix SearchFileForEdit in VimDConfig.ahk

VimDConfig:
    vim.SetPlugin("VimDConfig", "Array", "0.1", "VimDesktop的配置界面")
    vim.SetAction("<vc_plugin>", "显示 VimDesktop 插件信息")
    vim.SetAction("<vc_keymap>", "显示 VimDesktop 热键信息")
return

<vc_plugin>:
{
    GUI, VimDConfig_plugin:Destroy
    GUI, VimDConfig_plugin:Default
    GUI, VimDConfig_plugin:Font, s10, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, ListView, x10 y10 w150 h400 grid altsubmit gVimDConfig_LoadActions, 插件
    for plugin, obj in vim.pluginlist
        LV_Add("", plugin)
    GUI, VimDConfig_plugin:Add, ListView, x170 y10 w650 h400 grid altsubmit, 序号|动作|描述
    LV_ModifyCol(1, "center")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")
    GUI, VimDConfig_plugin:Show
    return
}

VimDConfig_LoadActions:
{
    If A_GuiEvent = I
    {
        if not InStr(ErrorLevel, "S", true)
        {
            return
        }

        GUI, VimDConfig_plugin:ListView, sysListview321
        LV_GetText(plugin, A_EventInfo)
        GUI, VimDConfig_plugin:Default
        GUI, VimDConfig_plugin:ListView, sysListview322
        idx := 1
        LV_Delete()
        for action, type in vim.ActionFromPlugin
        {
            If type = %plugin%
            {
                Desc := vim.GetAction(action)
                LV_Add("", idx, action, Desc.Comment)
                idx++
            }
        }
    }
    return
}

<vc_keymap>:
{
    menu, VimDConfig_keymap_menu, add
    ;menu, VimDConfig_keymap_menu, deleteall
    menu, VimDConfig_keymap_menu, add, &Exit, VimDConfig_keymap_exit

    GUI, VimDConfig_keymap:Destroy
    GUI, VimDConfig_keymap:Default
    GUI, VimDConfig_keymap:Font, s10, Microsoft YaHei

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y10 w300 h270, 窗口(&Q)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y36 w180 R12 center gVimDConfig_keymap_loadmodelist

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y290  w200 h140, 模式(&M)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y316  w180 R5 center gVimDConfig_keymap_loadhotkey

    GUI, VimDConfig_keymap:Add, GroupBox, x225 y10 w650 h420, 热键定义（双击进入对应文件）(&V)
    GUI, VimDConfig_keymap:Add, Listview, glistview x235 y36 w630 h380 grid, 热键|动作|描述

    LV_ModifyCol(1, "left 100")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")

    VimDConfig_keymap_loadwinlist()
    VimDConfig_keymap_loadhotkey(VimDConfig_keymap_loadmodelist(thiswin))

    GUI, VimDConfig_keymap:show
    return
}

VimDConfig_keymap_exit:
{
    GUI, VimDConfig_keymap:Destroy
    return
}

VimDConfig_keymap_loadwinlist()
{
    global vim
    list := "|全局"
    GUI, VimDConfig_keymap:Default
    for win, obj in vim.WinList {
        if vim.ExcludeWinList[win]{
            continue
        }
        list .= "|" win
    }
    GuiControl, , ListBox1, %list%
}

VimDConfig_keymap_loadmodelist:
    VimDConfig_keymap_loadmodelist()
    GUI, VimDConfig_keymap:Default
    LV_delete()
    GuiControl, Choose, ListBox2, |normal
return

VimDConfig_keymap_loadmodelist(win = "")
{
    global vim
    GUI, VimDConfig_keymap:Default
    If not strlen(win)
        ControlGet, win, Choice, , ListBox1
    If win = 全局
        winObj := vim.GetWin()
    Else
        winObj := vim.GetWin(win)
    for mode, obj in winobj.modeList
        mlist .= "|" mode
    GuiControl, , ListBox2, %mlist%
    return win
}

VimDConfig_keymap_loadhotkey:
    GUI, VimDConfig_keymap:Default
    ControlGet, win, Choice, , ListBox1
    win := RegExMatch(win, "^全局$") ? "" : win
    ControlGet, mode, Choice, , ListBox2
    VimDConfig_keymap_loadhotkey(win, mode)
return

VimDConfig_keymap_loadhotkey(win, mode = "")
{
    global vim
    If strlen(mode)
    {
        winObj  := vim.GetWin(win)
        modeobj := winObj.modeList[mode]
    }
    Else
        modeobj := vim.GetMode(win)
    GUI, VimDConfig_keymap:Default
    LV_delete()
    for key, i in modeobj.keymapList
    {
        ; Type = 1 : Function
        if (vim.GetAction(i).Type = 1)
        {
            ActionDescList := vim.GetAction(i).Comment
            actionDesc := StrSplit(%ActionDescList%[key], "|")
            LV_ADD("", Key, actionDesc[1], actionDesc[2])
        }
        else
        {
            LV_Add("", Key, i, vim.GetAction(i).Comment)
        }
    }
}

listview:
    if A_GuiEvent = DoubleClick
    {
        ;~ ToolTip You double-clicked row number %A_EventInfo%.
        LV_GetText(SelectedAction, A_EventInfo, 2)
        LV_GetText(SelectedDesc, A_EventInfo, 3)
        SearchFileForEdit(SelectedAction, SelectedDesc)
    }
return

ToMatch(str)
{
    str := RegExReplace(str,"\+|\?|\.|\*|\{|\}|\(|\)|\||\^|\$|\[|\]|\\","\$0")
    Return RegExReplace(str,"\s","\s")
}

SearchFileForEdit(Action, Desc)
{
    if (Action = "key" || Action = "run")
    {
        SearchLine := Action "|" Desc

        Loop, Read, %A_ScriptDir%\vimd.ini
        {
            if (InStr(A_LoopReadLine, SearchLine))
            {
                EditFile(A_ScriptDir "\vimd.ini", A_Index)
            }
        }
        return
    }

    lable := Action ":"
    funcMatch := ToMatch(Action) "\s*\(\)"
    FileEncoding,
    Loop, %A_ScriptDir%\plugins\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (A_LoopReadLine = lable || RegExMatch(A_LoopReadLine, funcMatch))
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }

    Loop, %A_ScriptDir%\core\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (A_LoopReadLine = lable || RegExMatch(A_LoopReadLine, funcMatch))
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }
}

EditFile(editPath, line := 1)
{
    editorArgs := {}
    editorArgs["notepad"] := "/g $line $file"
    editorArgs["notepad2"] := "/g $line $file"
    editorArgs["sublime_text"] := "$file:$line"
    editorArgs["vim"] := "+$line $file"
    editorArgs["gvim"] := "--remote-silent-tab +$line $file"
    editorArgs["everedit"] := "-n$line $file"
    editorArgs["notepad++"] := "-n$line $file"
    editorArgs["EmEditor"] := "-l $line $file"
    editorArgs["uedit32"] := "$file/$line"
    editorArgs["Editplus"] := "$file -cursor $line"
    editorArgs["textpad"] := "$file($line)"
    editorArgs["pspad"] := "$file /$line"
    editorArgs["ConTEXT"] := "$file /g1:$line"
    editorArgs["scite"] := "$file -goto:$line"

    Global editor

    If not FileExist(editor)
    {
        MsgBox, 请配置 vimd.ini 中 [config] 中的 editor ！
        return
    }

    ; 根据编辑器 exe 名称获取打开参数
    SplitPath, editor, , , OutExtension, OutNameNoExt
    args := editorArgs[OutNameNoExt]
    StringReplace, args, args, $line, %line%
    StringReplace, args, args, $file, "%editPath%"
    target := editor " " args
    if (OutExtension = "sh")
    {
        target := "sh.exe " target
    }

    run, %target%
}

VimDConfig:
    vim.SetPlugin("VimDConfig", "Array", "0.1", "VimDesktop的配置界面")
    vim.SetAction("<vc_plugin>", "显示 VimDesktop 插件信息")
    vim.SetAction("<vc_keymap>", "显示 VimDesktop 热键信息")
return

<vc_plugin>:
{
    GUI, VimDConfig_plugin:Destroy
    GUI, VimDConfig_plugin:Default
    GUI, VimDConfig_plugin:Font, s10, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, ListView, x10 y10 w150 h400 grid altsubmit gVimDConfig_LoadActions, 插件
    for plugin, obj in vim.pluginlist
        LV_Add("", plugin)
    GUI, VimDConfig_plugin:Add, ListView, x170 y10 w650 h400 grid altsubmit, 序号|动作|描述
    LV_ModifyCol(1, "center")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")
    GUI, VimDConfig_plugin:Show
    return
}

VimDConfig_LoadActions:
{
    If A_GuiEvent = I
    {
        if not InStr(ErrorLevel, "S", true)
        {
            return
        }

        GUI, VimDConfig_plugin:ListView, sysListview321
        LV_GetText(plugin, A_EventInfo)
        GUI, VimDConfig_plugin:Default
        GUI, VimDConfig_plugin:ListView, sysListview322
        idx := 1
        LV_Delete()
        for action, type in vim.ActionFromPlugin
        {
            If type = %plugin%
            {
                Desc := vim.GetAction(action)
                LV_Add("", idx, action, Desc.Comment)
                idx++
            }
        }
    }
    return
}

<vc_keymap>:
{
    menu, VimDConfig_keymap_menu, add
    ;menu, VimDConfig_keymap_menu, deleteall
    menu, VimDConfig_keymap_menu, add, &Exit, VimDConfig_keymap_exit

    GUI, VimDConfig_keymap:Destroy
    GUI, VimDConfig_keymap:Default
    GUI, VimDConfig_keymap:Font, s10, Microsoft YaHei

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y10 w300 h270, 窗口(&Q)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y36 w180 R12 center gVimDConfig_keymap_loadmodelist

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y290  w200 h140, 模式(&M)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y316  w180 R5 center gVimDConfig_keymap_loadhotkey

    GUI, VimDConfig_keymap:Add, GroupBox, x225 y10 w650 h420, 热键定义（双击进入对应文件）(&V)
    GUI, VimDConfig_keymap:Add, Listview, glistview x235 y36 w630 h380 grid, 热键|动作|描述

    LV_ModifyCol(1, "left 100")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")

    VimDConfig_keymap_loadwinlist()
    VimDConfig_keymap_loadhotkey(VimDConfig_keymap_loadmodelist(thiswin))

    GUI, VimDConfig_keymap:show
    return
}

VimDConfig_keymap_exit:
{
    GUI, VimDConfig_keymap:Destroy
    return
}

VimDConfig_keymap_loadwinlist()
{
    global vim
    list := "|全局"
    GUI, VimDConfig_keymap:Default
    for win, obj in vim.WinList {
        if vim.ExcludeWinList[win]{
            continue
        }
        list .= "|" win
    }
    GuiControl, , ListBox1, %list%
}

VimDConfig_keymap_loadmodelist:
    VimDConfig_keymap_loadmodelist()
    GUI, VimDConfig_keymap:Default
    LV_delete()
    GuiControl, Choose, ListBox2, |normal
return

VimDConfig_keymap_loadmodelist(win = "")
{
    global vim
    GUI, VimDConfig_keymap:Default
    If not strlen(win)
        ControlGet, win, Choice, , ListBox1
    If win = 全局
        winObj := vim.GetWin()
    Else
        winObj := vim.GetWin(win)
    for mode, obj in winobj.modeList
        mlist .= "|" mode
    GuiControl, , ListBox2, %mlist%
    return win
}

VimDConfig_keymap_loadhotkey:
    GUI, VimDConfig_keymap:Default
    ControlGet, win, Choice, , ListBox1
    win := RegExMatch(win, "^全局$") ? "" : win
    ControlGet, mode, Choice, , ListBox2
    VimDConfig_keymap_loadhotkey(win, mode)
return

VimDConfig_keymap_loadhotkey(win, mode = "")
{
    global vim
    If strlen(mode)
    {
        winObj  := vim.GetWin(win)
        modeobj := winObj.modeList[mode]
    }
    Else
        modeobj := vim.GetMode(win)
    GUI, VimDConfig_keymap:Default
    LV_delete()
    for key, i in modeobj.keymapList
    {
        ; Type = 1 : Function
        if (vim.GetAction(i).Type = 1)
        {
            ActionDescList := vim.GetAction(i).Comment
            actionDesc := StrSplit(%ActionDescList%[key], "|")
            LV_ADD("", Key, actionDesc[1], actionDesc[2])
        }
        else
        {
            LV_Add("", Key, i, vim.GetAction(i).Comment)
        }
    }
}

listview:
    if A_GuiEvent = DoubleClick
    {
        ;~ ToolTip You double-clicked row number %A_EventInfo%.
        LV_GetText(SelectedAction, A_EventInfo, 2)
        LV_GetText(SelectedDesc, A_EventInfo, 3)
        SearchFileForEdit(SelectedAction, SelectedDesc)
    }
return

ToMatch(str)
{
    str := RegExReplace(str,"\+|\?|\.|\*|\{|\}|\(|\)|\||\^|\$|\[|\]|\\","\$0")
    Return RegExReplace(str,"\s","\s")
}

SearchFileForEdit(Action, Desc)
{
    if (Action = "key" || Action = "run")
    {
        SearchLine := Action "|" Desc

        Loop, Read, %A_ScriptDir%\vimd.ini
        {
            if (InStr(A_LoopReadLine, SearchLine))
            {
                EditFile(A_ScriptDir "\vimd.ini", A_Index)
            }
        }
        return
    }

    lable := Action ":"
    funcMatch := ToMatch(Action) "\s*\(\)"
    FileEncoding,
    Loop, %A_ScriptDir%\plugins\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (A_LoopReadLine = lable || RegExMatch(A_LoopReadLine, funcMatch))
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }

    Loop, Read, %A_ScriptDir%\core\VimDConfig.ahk
    {
        if (A_LoopReadLine = lable || RegExMatch(A_LoopReadLine, funcMatch))
        {
            EditFile(A_ScriptDir "\core\VimDConfig.ahk", A_Index)
            return
        }
    }
}

EditFile(editPath, line := 1)
{
    editorArgs := {}
    editorArgs["notepad"] := "/g $line $file"
    editorArgs["notepad2"] := "/g $line $file"
    editorArgs["sublime_text"] := "$file:$line"
    editorArgs["vim"] := "+$line $file"
    editorArgs["gvim"] := "--remote-silent-tab +$line $file"
    editorArgs["everedit"] := "-n$line $file"
    editorArgs["notepad++"] := "-n$line $file"
    editorArgs["EmEditor"] := "-l $line $file"
    editorArgs["uedit32"] := "$file/$line"
    editorArgs["Editplus"] := "$file -cursor $line"
    editorArgs["textpad"] := "$file($line)"
    editorArgs["pspad"] := "$file /$line"
    editorArgs["ConTEXT"] := "$file /g1:$line"
    editorArgs["scite"] := "$file -goto:$line"

    Global editor

    If not FileExist(editor)
    {
        MsgBox, 请配置 vimd.ini 中 [config] 中的 editor ！
        return
    }

    ; 根据编辑器 exe 名称获取打开参数
    SplitPath, editor, , , OutExtension, OutNameNoExt
    args := editorArgs[OutNameNoExt]
    StringReplace, args, args, $line, %line%
    StringReplace, args, args, $file, "%editPath%"
    target := editor " " args
    if (OutExtension = "sh")
    {
        target := "sh.exe " target
    }

    run, %target%
}


I was using the wrong file name for the installer that was downloaded for the truecrypt package.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, RegEx

; Uninstall any previous versions...
ProgramFilesX86 := A_ProgramFiles . (A_PtrSize=8 ? " (x86)" : "")
truecryptUninstaller = %A_ProgramFiles%\TrueCrypt\TrueCrypt Setup.exe
truecryptUninstallerx86 = %ProgramFilesX86%\TrueCrypt\TrueCrypt Setup.exe

IfExist, %truecryptUninstaller%
{
    Sleep, 1000
	Run, "%truecryptUninstaller%" /u
	installed = 1
}

IfExist, %truecryptUninstallerx86%
{
    Sleep, 1000
	Run, "%truecryptUninstallerx86%" /u
	installed = 1
}

if (installed = 1)
{
	WinWait, TrueCrypt Setup,, 30
	IfWinExist
	{
		BlockInput, On
		Sleep, 250
		WinActivate
		Send, {ALTDOWN}r{ALTUP}{ALTDOWN}u{ALTUP}
		BlockInput, Off
	}

    WinWaitActive, TrueCrypt Setup, successfully uninstalled, 30
    IfWinExist
    {
        BlockInput, On
        Sleep, 250
        WinActivate
        Send, {Enter}
		Sleep, 250
		Send, {ENTER}
        BlockInput, Off
    }
}

; Install
truecryptInstaller = %A_Temp%\chocolatey\truecrypt\truecryptInstall.exe
Sleep, 1000
Run, %truecryptInstaller%

WinWait, TrueCrypt Setup [\d\.\w]+,, 30

IfWinExist TrueCrypt Setup [\d\.\w]+
{
    WinActivate
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {ALTDOWN}a{ALTUP}{ALTDOWN}n{ALTUP}
    Sleep, 250
    Send, {ALTDOWN}n{ALTUP}
    Sleep, 250
    Send, {ALTDOWN}r{ALTUP}{ALTDOWN}i{ALTUP}
    BlockInput, Off
}

WinWaitActive, TrueCrypt Setup$,, 30
IfWinExist
{
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {Enter}
    BlockInput, Off
}

WinWaitActive, TrueCrypt Setup [\d\.\w]+,, 30
IfWinExist
{
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {ALTDOWN}f{ALTUP}
    BlockInput, Off
}

WinWaitActive, TrueCrypt Setup$,, 30
IfWinExist
{
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {ALTDOWN}n{ALTUP}
    BlockInput, Off
}

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, RegEx

; Uninstall any previous versions...
ProgramFilesX86 := A_ProgramFiles . (A_PtrSize=8 ? " (x86)" : "")
truecryptUninstaller = %A_ProgramFiles%\TrueCrypt\TrueCrypt Setup.exe
truecryptUninstallerx86 = %ProgramFilesX86%\TrueCrypt\TrueCrypt Setup.exe

IfExist, %truecryptUninstaller%
{
    Sleep, 1000
	Run, "%truecryptUninstaller%" /u
	installed = 1
}

IfExist, %truecryptUninstallerx86%
{
    Sleep, 1000
	Run, "%truecryptUninstallerx86%" /u
	installed = 1
}

if (installed = 1)
{
	WinWait, TrueCrypt Setup,, 30
	IfWinExist
	{
		BlockInput, On
		Sleep, 250
		WinActivate
		Send, {ALTDOWN}r{ALTUP}{ALTDOWN}u{ALTUP}
		BlockInput, Off
	}

    WinWaitActive, TrueCrypt Setup, successfully uninstalled, 30
    IfWinExist
    {
        BlockInput, On
        Sleep, 250
        WinActivate
        Send, {Enter}
		Sleep, 250
		Send, {ENTER}
        BlockInput, Off
    }
}

; Install WinPcap
truecryptInstaller = %A_Temp%\chocolatey\truecrypt\TrueCrypt Setup 7.1a.exe
Sleep, 1000
Run, %truecryptInstaller%

WinWait, TrueCrypt Setup [\d\.\w]+,, 30

IfWinExist TrueCrypt Setup [\d\.\w]+
{
    WinActivate
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {ALTDOWN}a{ALTUP}{ALTDOWN}n{ALTUP}
    Sleep, 250
    Send, {ALTDOWN}n{ALTUP}
    Sleep, 250
    Send, {ALTDOWN}r{ALTUP}{ALTDOWN}i{ALTUP}
    BlockInput, Off
}

WinWaitActive, TrueCrypt Setup$,, 30
IfWinExist
{
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {Enter}
    BlockInput, Off
}

WinWaitActive, TrueCrypt Setup [\d\.\w]+,, 30
IfWinExist
{
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {ALTDOWN}f{ALTUP}
    BlockInput, Off
}

WinWaitActive, TrueCrypt Setup$,, 30
IfWinExist
{
    BlockInput, On
    Sleep, 250
    WinActivate
    Send, {ALTDOWN}n{ALTUP}
    BlockInput, Off
}


cfg/ahk: remove win+l hack

cfg/ahk: remove win+l hack

;Control key Ctrl- ^
;Alt key Alt- !
;Shift key Shift- +
;Windows key Win- #

#Persistent
#SingleInstance Force

A_DetectHiddenWindows := true
A_DetectHiddenText := true
A_TitleMatchMode := "RegEx" ;match titles and classes using regular expressions
A_TitleMatchModeSpeed := "Slow" ;match titles and classes using regular expressions
A_CoordModeMouse := "Screen"
A_CoordModeToolTip := "Screen"

;detect cygwin
CygPath := "C:\Program Files (x86)\cygwin"
if !FileExist(CygPath) {
    CygPath := "C:\Cygwin"
}
If !FileExist(CygPath) {
    CygPath := "C:\Cygwin64"
}

;detect browser
BrowserPath := "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
if !FileExist(BrowserPath) {
    BrowserPath := "C:\Program Files\Mozilla Firefox\firefox.exe"
}
if !FileExist(BrowserPath) {
    BrowserPath := "C:\Users\rr-\AppData\Local\Google\Chrome\Application\chrome.exe"
}

;activate/run a program
FRun(window, path, folder)
{
    if !window || !WinExist(window) {
        Run(path, folder)
    } else {
        WinShow
        WinActivate
    }
    return
}

;fix URLs copied by some browsers so they're clickable in popular programs
ClipboardChanged(type)
{
    if (SubStr(clipboard, 1, 7) == "http://") || SubStr(clipboard, 1, 8) == "https://" {
        clipboard := StrReplace(clipboard, "[", "%5b", All)
        clipboard := StrReplace(clipboard, "\", "%5c", All)
        clipboard := StrReplace(clipboard, "]", "%5d", All)
    }
    return
}
OnClipboardChange("ClipboardChanged")

;enforce same keyboard layout across all programs
global Locale1 := 0x4150415
global Locale2 := 0x4110411
global CurrentLocale := Locale1

GetActiveLocale()
{
    win_id := WinGetID("A")
    thread_id := DllCall("GetWindowThreadProcessId", "Int", win_id, "Int", "0")
    return DllCall("GetKeyboardLayout", "Int", thread_id)
}

ApplyLocale(locale)
{
    global CurrentLocale := locale
    SendMessage(0x50, 0, locale, "", "A")
}

CycleLocale()
{
    if CurrentLocale == Locale1 {
        ApplyLocale(locale2)
    } else if CurrentLocale == Locale2 {
        ApplyLocale(Locale1)
    }
}

ShellMessage(wparam, lparam)
{
    title := WinGetTitle(lparam)
    if wParam == 4 { ;HSHELL_WINDOWACTIVATED
        ApplyLocale(CurrentLocale)
    }
}

gui := GuiCreate("", "")
gui.Opt("+LastFound")
hwnd := WinExist()
DllCall("RegisterShellHookWindow", uint, hwnd)
msgnum := DllCall("RegisterWindowMessage", str, "SHELLHOOK")
OnMessage(msgnum, "ShellMessage")

return

#If FileExist(CygPath)
    ;cygwin - activate/run
    #Enter::
    {
        Run(CygPath . "\\bin\\mintty.exe --title Terminal --class mintty_thetty --exec /bin/zsh -i -l", CygPath)
        return
    }
    +^![::
    {
        Run(CygPath . "\\bin\\mintty.exe --title Terminal --class mintty_thetty --exec /bin/zsh -i -l", CygPath)
        return
    }
    ^![::
    {
        if !WinExist("ahk_class mintty_thetty") {
            Run(CygPath . "\\bin\\mintty.exe --title Terminal --class mintty_thetty --exec /bin/zsh -i -l", CygPath)
            WinWait("ahk_class mintty_thetty")
        } else {
            WinShow
            WinActivate
        }
        return
    }

    ;ssh to cyclone - activate/run
    +^!]::
    {
        Run(CygPath . "\\bin\\mintty.exe --title 'Remote terminal' --class mintty_ssh --exec /bin/ssh cyclone", CygPath . "/bin")
        return
    }
    ^!]::
    {
        if !WinExist("ahk_class mintty_ssh") {
            Run(CygPath . "\\bin\\mintty.exe --title 'Remote terminal' --class mintty_ssh --exec /bin/ssh cyclone", CygPath . "/bin")
            WinWait("ahk_class mintty_ssh")
        } else {
            WinShow
            WinActivate
        }
        return
    }

    ;text editor - activate/run
    +^!N::
    {
        If WinExist("ahk_class Vim") {
            WinShow
            WinActivate
        } else {
            Run(CygPath . "\\bin\\mintty.exe --class Vim --exec /bin/zsh -l -i -c /bin/vim", CygPath . "/bin")
            WinWait("ahk_class Vim")
        }
        return
    }

    ;vifm - activate/run
    #e::
    {
        If WinExist("ahk_class Vifm") {
            WinShow
            WinActivate
        } else {
            Run(CygPath . "\\bin\\mintty.exe --window max --class Vifm --exec /bin/zsh -l -i -c vifm", CygPath . "/bin")
            WinWait("ahk_class Vifm")
        }
        return
    }

    ;vifm - just run
    +#e::
    {
        Run(CygPath . "\\bin\\mintty.exe --window max --class Vifm --exec /bin/zsh -l -i -c vifm", CygPath . "/bin")
        return
    }
#If

;browser
#If FileExist(BrowserPath)
    ;web browser - activate/run
    ^!;::
        if WinExist("Mozilla Firefox") {
            WinShow
            WinActivate
            ;Send("!d")
        } else if WinExist("Vimperator") {
            WinShow
            WinActivate
            ;Send("!d")
        } else if WinExist("ahk_class Chrome_WidgetWin_1") {
            WinActivate
            ControlFocus("Chrome_OmniboxView1")
            ;SendInput("{Home}+{End}")
        } else {
            if FileExist(BrowserPath) {
                Run(BrowserPath)
            }
        }
        return
#If

;adobe products
#IfWinActive ahk_group adobe
    ~LAlt::return
    LAlt UP::Send("{Escape}")
#IfWinActive
#IfWinActive ahk_class illustrator
+wheelup::
    Send("{Ctrl Down}{=}{Ctrl Up}")
    return
+wheeldown::
    Send("{Ctrl Down}-{Ctrl Up}")
    return
#IfWinActive

;close active window
#q::
{
    active_hwnd := WinExist("A")
    WinClose
    return
}

;fullscreen
#f::
{
    if WinGetMinMax("A") {
        WinRestore("A")
    } else {
        WinMaximize("A")
    }
    return
}

;restore active window
#s::
{
    active_hwnd := WinExist("A")
    PostMessage(0x112, 0xf120) ;WM_SYSCOMMAND, SC_RESTORE
    return
}

;minimize active window
#w::
{
    if WinActive("WTW$") {
        WinHide
    } else if WinActive("Buddy List") {
        WinHide
    } else {
        active_hwnd := WinExist("A")
        PostMessage(0x112, 0xF020) ;WM_SYSCOMMAND, SC_MINIMIZE
    }
    return
}

;set active window as always on top
#a::WinSetAlwaysOnTop("Toggle", "A")

;transparency
AddTransparency(delta)
{
    transparency := WinGetTransparent("A")
    if !transparency {
        transparency := 255
    }
    transparency := transparency + delta
    if transparency <= 10 {
        WinSetTransparent(10, "A")
    } else if Transparency >= 255 {
        WinSetTransparent(255, "A")
        WinSetTransparent("OFF", "A")
    } else {
        WinSetTransparent(transparency, "A")
    }
}
#WheelUp::AddTransparency(12)
#WheelDown::AddTransparency(-12)
#z::AddTransparency(-12)
+#z::AddTransparency(12)

;music
#x::Volume_Up
+#x::Volume_Down
#c::Media_Next
+#c::Media_Prev
#v::Media_Play_Pause

;screenshots
+#i::Run(CygPath . "\\bin\\zsh.exe -i -l -c 'shot -w -i --output=Z:/'", , Hide)
#i::Run(CygPath . "\\bin\\zsh.exe -i -l -c 'shot -i --output=Z:/'", , Hide)

;reload autohotkey
!F12::Reload

;linux-compatible useful keys
RAlt & -::Send(GetKeyState("Shift") ? "{U+2014}" : "{U+2013}")
RAlt & k::Send("{U+2026}")

;hepburn macrons
RAlt & =::
{
    key := Input("L1", "{delete}{esc}{home}{end}") ; pressing any of these will terminate the input
    if key == "A" {
        Send("{U+0100}")
    } else if key == "I" {
        Send("{U+012A}")
    } else if key == "U" {
        Send("{U+016A}")
    } else if key == "E" {
        Send("{U+0112}")
    } else if key == "O" {
        Send("{U+014C}")
    } else if key == "a" {
        Send("{U+0101}")
    } else if key == "i" {
        Send("{U+012B}")
    } else if key == "u" {
        Send("{U+016B}")
    } else if key == "e" {
        Send("{U+0113}")
    } else if key == "o" {
        Send("{U+014D}")
    }
     return
}

#n::
{
    CycleLocale()
}

;Control key Ctrl- ^
;Alt key Alt- !
;Shift key Shift- +
;Windows key Win- #

#Persistent
#SingleInstance Force

A_DetectHiddenWindows := true
A_DetectHiddenText := true
A_TitleMatchMode := "RegEx" ;match titles and classes using regular expressions
A_TitleMatchModeSpeed := "Slow" ;match titles and classes using regular expressions
A_CoordModeMouse := "Screen"
A_CoordModeToolTip := "Screen"

;detect cygwin
CygPath := "C:\Program Files (x86)\cygwin"
if !FileExist(CygPath) {
    CygPath := "C:\Cygwin"
}
If !FileExist(CygPath) {
    CygPath := "C:\Cygwin64"
}

;detect browser
BrowserPath := "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
if !FileExist(BrowserPath) {
    BrowserPath := "C:\Program Files\Mozilla Firefox\firefox.exe"
}
if !FileExist(BrowserPath) {
    BrowserPath := "C:\Users\rr-\AppData\Local\Google\Chrome\Application\chrome.exe"
}

;disable windows+l
RegWrite(1, "REG_DWORD", "HKEY_CURRENT_USER\\Software\Microsoft\Windows\CurrentVersion\Policies\System\\DisableLockWorkstation")

;activate/run a program
FRun(window, path, folder)
{
    if !window || !WinExist(window) {
        Run(path, folder)
    } else {
        WinShow
        WinActivate
    }
    return
}

;fix URLs copied by some browsers so they're clickable in popular programs
ClipboardChanged(type)
{
    if (SubStr(clipboard, 1, 7) == "http://") || SubStr(clipboard, 1, 8) == "https://" {
        clipboard := StrReplace(clipboard, "[", "%5b", All)
        clipboard := StrReplace(clipboard, "\", "%5c", All)
        clipboard := StrReplace(clipboard, "]", "%5d", All)
    }
    return
}
OnClipboardChange("ClipboardChanged")

;enforce same keyboard layout across all programs
global Locale1 := 0x4150415
global Locale2 := 0x4110411
global CurrentLocale := Locale1

GetActiveLocale()
{
    win_id := WinGetID("A")
    thread_id := DllCall("GetWindowThreadProcessId", "Int", win_id, "Int", "0")
    return DllCall("GetKeyboardLayout", "Int", thread_id)
}

ApplyLocale(locale)
{
    global CurrentLocale := locale
    SendMessage(0x50, 0, locale, "", "A")
}

CycleLocale()
{
    if CurrentLocale == Locale1 {
        ApplyLocale(locale2)
    } else if CurrentLocale == Locale2 {
        ApplyLocale(Locale1)
    }
}

ShellMessage(wparam, lparam)
{
    title := WinGetTitle(lparam)
    if wParam == 4 { ;HSHELL_WINDOWACTIVATED
        ApplyLocale(CurrentLocale)
    }
}

gui := GuiCreate("", "")
gui.Opt("+LastFound")
hwnd := WinExist()
DllCall("RegisterShellHookWindow", uint, hwnd)
msgnum := DllCall("RegisterWindowMessage", str, "SHELLHOOK")
OnMessage(msgnum, "ShellMessage")

return

#If FileExist(CygPath)
    ;cygwin - activate/run
    #Enter::
    {
        Run(CygPath . "\\bin\\mintty.exe --title Terminal --class mintty_thetty --exec /bin/zsh -i -l", CygPath)
        return
    }
    +^![::
    {
        Run(CygPath . "\\bin\\mintty.exe --title Terminal --class mintty_thetty --exec /bin/zsh -i -l", CygPath)
        return
    }
    ^![::
    {
        if !WinExist("ahk_class mintty_thetty") {
            Run(CygPath . "\\bin\\mintty.exe --title Terminal --class mintty_thetty --exec /bin/zsh -i -l", CygPath)
            WinWait("ahk_class mintty_thetty")
        } else {
            WinShow
            WinActivate
        }
        return
    }

    ;ssh to cyclone - activate/run
    +^!]::
    {
        Run(CygPath . "\\bin\\mintty.exe --title 'Remote terminal' --class mintty_ssh --exec /bin/ssh cyclone", CygPath . "/bin")
        return
    }
    ^!]::
    {
        if !WinExist("ahk_class mintty_ssh") {
            Run(CygPath . "\\bin\\mintty.exe --title 'Remote terminal' --class mintty_ssh --exec /bin/ssh cyclone", CygPath . "/bin")
            WinWait("ahk_class mintty_ssh")
        } else {
            WinShow
            WinActivate
        }
        return
    }

    ;text editor - activate/run
    +^!N::
    {
        If WinExist("ahk_class Vim") {
            WinShow
            WinActivate
        } else {
            Run(CygPath . "\\bin\\mintty.exe --class Vim --exec /bin/zsh -l -i -c /bin/vim", CygPath . "/bin")
            WinWait("ahk_class Vim")
        }
        return
    }

    ;vifm - activate/run
    #e::
    {
        If WinExist("ahk_class Vifm") {
            WinShow
            WinActivate
        } else {
            Run(CygPath . "\\bin\\mintty.exe --window max --class Vifm --exec /bin/zsh -l -i -c vifm", CygPath . "/bin")
            WinWait("ahk_class Vifm")
        }
        return
    }

    ;vifm - just run
    +#e::
    {
        Run(CygPath . "\\bin\\mintty.exe --window max --class Vifm --exec /bin/zsh -l -i -c vifm", CygPath . "/bin")
        return
    }
#If

;browser
#If FileExist(BrowserPath)
    ;web browser - activate/run
    ^!;::
        if WinExist("Mozilla Firefox") {
            WinShow
            WinActivate
            ;Send("!d")
        } else if WinExist("Vimperator") {
            WinShow
            WinActivate
            ;Send("!d")
        } else if WinExist("ahk_class Chrome_WidgetWin_1") {
            WinActivate
            ControlFocus("Chrome_OmniboxView1")
            ;SendInput("{Home}+{End}")
        } else {
            if FileExist(BrowserPath) {
                Run(BrowserPath)
            }
        }
        return
#If

;adobe products
#IfWinActive ahk_group adobe
    ~LAlt::return
    LAlt UP::Send("{Escape}")
#IfWinActive
#IfWinActive ahk_class illustrator
+wheelup::
    Send("{Ctrl Down}{=}{Ctrl Up}")
    return
+wheeldown::
    Send("{Ctrl Down}-{Ctrl Up}")
    return
#IfWinActive

;close active window
#q::
{
    active_hwnd := WinExist("A")
    WinClose
    return
}

;fullscreen
#f::
{
    if WinGetMinMax("A") {
        WinRestore("A")
    } else {
        WinMaximize("A")
    }
    return
}

;restore active window
#s::
{
    active_hwnd := WinExist("A")
    PostMessage(0x112, 0xf120) ;WM_SYSCOMMAND, SC_RESTORE
    return
}

;minimize active window
#w::
{
    if WinActive("WTW$") {
        WinHide
    } else if WinActive("Buddy List") {
        WinHide
    } else {
        active_hwnd := WinExist("A")
        PostMessage(0x112, 0xF020) ;WM_SYSCOMMAND, SC_MINIMIZE
    }
    return
}

;set active window as always on top
#a::WinSetAlwaysOnTop("Toggle", "A")

;transparency
AddTransparency(delta)
{
    transparency := WinGetTransparent("A")
    if !transparency {
        transparency := 255
    }
    transparency := transparency + delta
    if transparency <= 10 {
        WinSetTransparent(10, "A")
    } else if Transparency >= 255 {
        WinSetTransparent(255, "A")
        WinSetTransparent("OFF", "A")
    } else {
        WinSetTransparent(transparency, "A")
    }
}
#WheelUp::AddTransparency(12)
#WheelDown::AddTransparency(-12)
#z::AddTransparency(-12)
+#z::AddTransparency(12)

;music
#x::Volume_Up
+#x::Volume_Down
#c::Media_Next
+#c::Media_Prev
#v::Media_Play_Pause

;screenshots
+#i::Run(CygPath . "\\bin\\zsh.exe -i -l -c 'shot -w -i --output=Z:/'", , Hide)
#i::Run(CygPath . "\\bin\\zsh.exe -i -l -c 'shot -i --output=Z:/'", , Hide)

;reload autohotkey
!F12::Reload

;linux-compatible useful keys
RAlt & -::Send(GetKeyState("Shift") ? "{U+2014}" : "{U+2013}")
RAlt & k::Send("{U+2026}")

;hepburn macrons
RAlt & =::
{
    key := Input("L1", "{delete}{esc}{home}{end}") ; pressing any of these will terminate the input
    if key == "A" {
        Send("{U+0100}")
    } else if key == "I" {
        Send("{U+012A}")
    } else if key == "U" {
        Send("{U+016A}")
    } else if key == "E" {
        Send("{U+0112}")
    } else if key == "O" {
        Send("{U+014C}")
    } else if key == "a" {
        Send("{U+0101}")
    } else if key == "i" {
        Send("{U+012B}")
    } else if key == "u" {
        Send("{U+016B}")
    } else if key == "e" {
        Send("{U+0113}")
    } else if key == "o" {
        Send("{U+014D}")
    }
     return
}

#n::
{
    CycleLocale()
}


Remove FileEncoding, in VimDConfig.ahk

Remove FileEncoding, in VimDConfig.ahk

VimDConfig:
    vim.SetPlugin("VimDConfig", "Array", "0.1", "VimDesktop的配置界面")
    vim.SetAction("<vc_plugin>", "显示 VimDesktop 插件信息")
    vim.SetAction("<vc_keymap>", "显示 VimDesktop 热键信息")
return

<vc_plugin>:
{
    GUI, VimDConfig_plugin:Destroy
    GUI, VimDConfig_plugin:Default
    GUI, VimDConfig_plugin:Font, s10, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, ListView, x10 y10 w150 h400 grid altsubmit gVimDConfig_LoadActions, 插件
    for plugin, obj in vim.pluginlist
        LV_Add("", plugin)
    GUI, VimDConfig_plugin:Add, ListView, glistview x170 y10 w650 h400 grid altsubmit, 序号|动作|描述（双击进入文件）

    GUI, VimDConfig_plugin:Font, s12, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, Text, x180 h25, 搜索：
    GUI, VimDConfig_plugin:Font, s10, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, Edit, gsearch_plugin v_search x+10 w120 h25

    LV_ModifyCol(1, "center")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")
    GUI, VimDConfig_plugin:Show
    return
}

VimDConfig_LoadActions:
{
    If A_GuiEvent = I
    {
        if not InStr(ErrorLevel, "S", true)
        {
            return
        }

        GUI, VimDConfig_plugin:ListView, sysListview321
        LV_GetText(plugin, A_EventInfo)
        GUI, VimDConfig_plugin:Default
        GUI, VimDConfig_plugin:ListView, sysListview322
        idx := 1
        LV_Delete()

        global current_plugin := ""
        for action, type in vim.ActionFromPlugin
        {
            If type = %plugin%
            {
                Desc := vim.GetAction(action)
                LV_Add("", idx, action, Desc.Comment)
                current_plugin .= idx "`t" action "`t" Desc.Comment "`n"
                idx++
            }
        }
    }
    return
}

<vc_keymap>:
{
    menu, VimDConfig_keymap_menu, add
    ;menu, VimDConfig_keymap_menu, deleteall
    menu, VimDConfig_keymap_menu, add, &Exit, VimDConfig_keymap_exit

    GUI, VimDConfig_keymap:Destroy
    GUI, VimDConfig_keymap:Default
    GUI, VimDConfig_keymap:Font, s10, Microsoft YaHei

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y10 w300 h270, 窗口(&Q)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y36 w180 R12 center gVimDConfig_keymap_loadmodelist

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y290  w200 h140, 模式(&M)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y316  w180 R5 center gVimDConfig_keymap_loadhotkey

    GUI, VimDConfig_keymap:Add, GroupBox, x225 y10 w650 h420, 热键定义（双击进入对应文件，右键双击修改键映射）(&V)
    GUI, VimDConfig_keymap:Add, Listview, glistview x235 y36 w630 h380 grid, 热键|动作|描述
    ;GUI, VimDConfig_keymap:Add, Listview, glistview x235 y36 w630 h380 grid, 序号|热键|动作|描述
    GUI, VimDConfig_keymap:Font, s12, Microsoft YaHei
    GUI, VimDConfig_keymap:Add, Text, x230 h25, 搜索：
    GUI, VimDConfig_keymap:Font, s10, Microsoft YaHei
    GUI, VimDConfig_keymap:Add, Edit, gsearch_keymap v_search x+10 w120 h25

    /*
    LV_ModifyCol(1, "left 50")
    LV_ModifyCol(2, "left 100")
    LV_ModifyCol(3, "left 250")
    LV_ModifyCol(4, "left 400")
    */

    LV_ModifyCol(1, "left 100")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")

    VimDConfig_keymap_loadwinlist()
    VimDConfig_keymap_loadhotkey(VimDConfig_keymap_loadmodelist(thiswin))

    GUI, VimDConfig_keymap:show
    return
}

VimDConfig_keymap_exit:
{
    GUI, VimDConfig_keymap:Destroy
    return
}

VimDConfig_keymap_loadwinlist()
{
    global vim
    list := "|全局"
    GUI, VimDConfig_keymap:Default
    for win, obj in vim.WinList {
        if vim.ExcludeWinList[win]{
            continue
        }
        list .= "|" win
    }
    GuiControl, , ListBox1, %list%
}

VimDConfig_keymap_loadmodelist:
    VimDConfig_keymap_loadmodelist()
    GUI, VimDConfig_keymap:Default
    LV_delete()
    GuiControl, Choose, ListBox2, |normal
return

VimDConfig_keymap_loadmodelist(win = "")
{
    global vim
    GUI, VimDConfig_keymap:Default
    If not strlen(win)
        ControlGet, win, Choice, , ListBox1
    If win = 全局
        winObj := vim.GetWin()
    Else
        winObj := vim.GetWin(win)
    for mode, obj in winobj.modeList
        mlist .= "|" mode
    GuiControl, , ListBox2, %mlist%
    return win
}

VimDConfig_keymap_loadhotkey:
    GUI, VimDConfig_keymap:Default
    ControlGet, win, Choice, , ListBox1
    win := RegExMatch(win, "^全局$") ? "" : win
    ControlGet, mode, Choice, , ListBox2
    VimDConfig_keymap_loadhotkey(win, mode)
return

VimDConfig_keymap_loadhotkey_new(win, mode = "")
{
    global vim
    global current_keymap := ""
    if StrLen(mode)
    {
        winObj  := vim.GetWin(win)
        modeobj := winObj.modeList[mode]
    }
    else
        modeobj := vim.GetMode(win)
    Gui, VimDConfig_keymap:Default
    idx := 1
    LV_Delete()

    for key, i in modeobj.keymapList
    {
        if (vim.GetAction(i).Type = 1)
        {
            ActionDescList := vim.GetAction(i).Comment
            actionDesc := StrSplit(%ActionDescList%[key], "|")
            current_keymap .= Key "`t" actionDesc[1]  "`n"
        }
        else
        {
            current_keymap .= Key "`t" i  "`n"
        }
    }

    ;~ msgbox %current_keymap%
    Clipboard:=current_keymap
    for action, type in vim.ActionFromPlugin
    {
        if type = %win%
        {
            Desc := vim.GetAction(action)
            ;~ if RegExMatch(current_keymap, action)
            if InStr(current_keymap, action)
            {
                reg:="(.*)\t" . action
                Loop, Parse, current_keymap, `n, `r
                {
                    if RegExMatch(A_LoopField, reg,m)
                    {
                        LV_Add("", idx, m1 ,action, Desc.Comment)
                        break
                    }
                    else
                        continue
                }
                idx++
                ;~ LV_Add("", idx, "启用",action, Desc.Comment)
            }
            else
            {
                LV_Add("", idx, "未启用" ,action, Desc.Comment)
                idx++
            }
        }
    }
    return
}

VimDConfig_keymap_loadhotkey(win, mode = "")
{
    global vim
    global current_keymap := ""
    If strlen(mode)
    {
        winObj  := vim.GetWin(win)
        modeobj := winObj.modeList[mode]
    }
    Else
        modeobj := vim.GetMode(win)
    GUI, VimDConfig_keymap:Default
    LV_delete()
    for key, i in modeobj.keymapList
    {
        ; Type = 1 : Function
        if (vim.GetAction(i).Type = 1)
        {
            ActionDescList := vim.GetAction(i).Comment
            actionDesc := StrSplit(%ActionDescList%[key], "|")
            LV_ADD("", Key, actionDesc[1], actionDesc[2])
            current_keymap .= Key "`t" actionDesc[1] "`t" actionDesc[2] "`n"
        }
        else
        {
            LV_Add("", Key, i, vim.GetAction(i).Comment)
            current_keymap .= Key "`t" i "`t" vim.GetAction(i).Comment "`n"
        }
    }
}

listview:
    if A_GuiEvent = DoubleClick
    {
        ;~ ToolTip You double-clicked row number %A_EventInfo%.
        LV_GetText(SelectedAction, A_EventInfo, 2)
        LV_GetText(SelectedDesc, A_EventInfo, 3)
        SearchFileForEdit(SelectedAction, SelectedDesc, false)
    }
    else if A_GuiEvent = R
    {
        LV_GetText(SelectedAction, A_EventInfo, 2)
        LV_GetText(SelectedDesc, A_EventInfo, 3)
        SearchFileForEdit(SelectedAction, SelectedDesc, true)
    }

return

SearchFileForEdit(Action, Desc, EditKeyMapping)
{
    if (Action = "key" || Action = "run" || Action = "dir" || EditKeyMapping)
    {
        SearchLine := "=" Action

        if (Action = "key" || Action = "run" || Action = "dir")
        {
            SearchLine := Action "|" Desc
        }

        Loop, Read, %A_ScriptDir%\vimd.ini
        {
            if (InStr(A_LoopReadLine, SearchLine))
            {
                EditFile(A_ScriptDir "\vimd.ini", A_Index)
                return
            }
        }

        EditFile(A_ScriptDir "\vimd.ini")
        return
    }

    label := Action ":"
    Loop, %A_ScriptDir%\plugins\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (InStr(A_LoopReadLine, label) = 1)
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }

    Loop, %A_ScriptDir%\core\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (InStr(A_LoopReadLine, label) = 1)
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }
}

EditFile(editPath, line := 1)
{
    editorArgs := {}
    editorArgs["notepad"] := "/g $line $file"
    editorArgs["notepad2"] := "/g $line $file"
    editorArgs["sublime_text"] := "$file:$line"
    editorArgs["vim"] := "+$line $file"
    editorArgs["gvim"] := "--remote-silent-tab +$line $file"
    editorArgs["everedit"] := "-n$line $file"
    editorArgs["notepad++"] := "-n$line $file"
    editorArgs["EmEditor"] := "-l $line $file"
    editorArgs["uedit32"] := "$file/$line"
    editorArgs["Editplus"] := "$file -cursor $line"
    editorArgs["textpad"] := "$file($line)"
    editorArgs["pspad"] := "$file /$line"
    editorArgs["ConTEXT"] := "$file /g1:$line"
    editorArgs["scite"] := "$file -goto:$line"

    Global editor

    If not FileExist(editor)
    {
        MsgBox, 请配置 vimd.ini 中 [config] 中的 editor ，并重启 vimd ！
        return
    }

    ; 根据编辑器 exe 名称获取打开参数
    SplitPath, editor, , , OutExtension, OutNameNoExt
    args := editorArgs[OutNameNoExt]
    StringReplace, args, args, $line, %line%
    StringReplace, args, args, $file, "%editPath%"
    target := editor " " args
    if (OutExtension = "sh")
    {
        target := "sh.exe " target
    }

    run, %target%
}

search_keymap:
    global current_keymap
    search_to_display(current_keymap)
return

search_plugin:
    global current_plugin
    search_to_display(current_plugin)
return

search_to_display(lines)
{
    Gui Submit, nohide
    GuiControlGet, OutputVar, , _search

    text := StrSplit(lines, "`n")

    LV_Delete() ; 清理不掉，第二次加载后，都成了重复的了，不知道怎么处理
    GuiControl, -Redraw, listview ; 重新启用重绘 (上面把它禁用了)
    for k, v in text
    {
        if v =
            continue
        if Instr(v, OutputVar)
        {
            list := StrSplit(v, "`t")
            LV_Add("", list[1], list[2], list[3])
        }
    }
    GuiControl, +Redraw, listview ; 重新启用重绘 (上面把它禁用了)
}

VimDConfig:
    vim.SetPlugin("VimDConfig", "Array", "0.1", "VimDesktop的配置界面")
    vim.SetAction("<vc_plugin>", "显示 VimDesktop 插件信息")
    vim.SetAction("<vc_keymap>", "显示 VimDesktop 热键信息")
return

<vc_plugin>:
{
    GUI, VimDConfig_plugin:Destroy
    GUI, VimDConfig_plugin:Default
    GUI, VimDConfig_plugin:Font, s10, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, ListView, x10 y10 w150 h400 grid altsubmit gVimDConfig_LoadActions, 插件
    for plugin, obj in vim.pluginlist
        LV_Add("", plugin)
    GUI, VimDConfig_plugin:Add, ListView, glistview x170 y10 w650 h400 grid altsubmit, 序号|动作|描述（双击进入文件）

    GUI, VimDConfig_plugin:Font, s12, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, Text, x180 h25, 搜索：
    GUI, VimDConfig_plugin:Font, s10, Microsoft YaHei
    GUI, VimDConfig_plugin:Add, Edit, gsearch_plugin v_search x+10 w120 h25

    LV_ModifyCol(1, "center")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")
    GUI, VimDConfig_plugin:Show
    return
}

VimDConfig_LoadActions:
{
    If A_GuiEvent = I
    {
        if not InStr(ErrorLevel, "S", true)
        {
            return
        }

        GUI, VimDConfig_plugin:ListView, sysListview321
        LV_GetText(plugin, A_EventInfo)
        GUI, VimDConfig_plugin:Default
        GUI, VimDConfig_plugin:ListView, sysListview322
        idx := 1
        LV_Delete()

        global current_plugin := ""
        for action, type in vim.ActionFromPlugin
        {
            If type = %plugin%
            {
                Desc := vim.GetAction(action)
                LV_Add("", idx, action, Desc.Comment)
                current_plugin .= idx "`t" action "`t" Desc.Comment "`n"
                idx++
            }
        }
    }
    return
}

<vc_keymap>:
{
    menu, VimDConfig_keymap_menu, add
    ;menu, VimDConfig_keymap_menu, deleteall
    menu, VimDConfig_keymap_menu, add, &Exit, VimDConfig_keymap_exit

    GUI, VimDConfig_keymap:Destroy
    GUI, VimDConfig_keymap:Default
    GUI, VimDConfig_keymap:Font, s10, Microsoft YaHei

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y10 w300 h270, 窗口(&Q)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y36 w180 R12 center gVimDConfig_keymap_loadmodelist

    GUI, VimDConfig_keymap:Add, GroupBox, x10 y290  w200 h140, 模式(&M)
    GUI, VimDConfig_keymap:Add, ListBox, x20 y316  w180 R5 center gVimDConfig_keymap_loadhotkey

    GUI, VimDConfig_keymap:Add, GroupBox, x225 y10 w650 h420, 热键定义（双击进入对应文件，右键双击修改键映射）(&V)
    GUI, VimDConfig_keymap:Add, Listview, glistview x235 y36 w630 h380 grid, 热键|动作|描述
    ;GUI, VimDConfig_keymap:Add, Listview, glistview x235 y36 w630 h380 grid, 序号|热键|动作|描述
    GUI, VimDConfig_keymap:Font, s12, Microsoft YaHei
    GUI, VimDConfig_keymap:Add, Text, x230 h25, 搜索：
    GUI, VimDConfig_keymap:Font, s10, Microsoft YaHei
    GUI, VimDConfig_keymap:Add, Edit, gsearch_keymap v_search x+10 w120 h25

    /*
    LV_ModifyCol(1, "left 50")
    LV_ModifyCol(2, "left 100")
    LV_ModifyCol(3, "left 250")
    LV_ModifyCol(4, "left 400")
    */

    LV_ModifyCol(1, "left 100")
    LV_ModifyCol(2, "left 250")
    LV_ModifyCol(3, "left 400")

    VimDConfig_keymap_loadwinlist()
    VimDConfig_keymap_loadhotkey(VimDConfig_keymap_loadmodelist(thiswin))

    GUI, VimDConfig_keymap:show
    return
}

VimDConfig_keymap_exit:
{
    GUI, VimDConfig_keymap:Destroy
    return
}

VimDConfig_keymap_loadwinlist()
{
    global vim
    list := "|全局"
    GUI, VimDConfig_keymap:Default
    for win, obj in vim.WinList {
        if vim.ExcludeWinList[win]{
            continue
        }
        list .= "|" win
    }
    GuiControl, , ListBox1, %list%
}

VimDConfig_keymap_loadmodelist:
    VimDConfig_keymap_loadmodelist()
    GUI, VimDConfig_keymap:Default
    LV_delete()
    GuiControl, Choose, ListBox2, |normal
return

VimDConfig_keymap_loadmodelist(win = "")
{
    global vim
    GUI, VimDConfig_keymap:Default
    If not strlen(win)
        ControlGet, win, Choice, , ListBox1
    If win = 全局
        winObj := vim.GetWin()
    Else
        winObj := vim.GetWin(win)
    for mode, obj in winobj.modeList
        mlist .= "|" mode
    GuiControl, , ListBox2, %mlist%
    return win
}

VimDConfig_keymap_loadhotkey:
    GUI, VimDConfig_keymap:Default
    ControlGet, win, Choice, , ListBox1
    win := RegExMatch(win, "^全局$") ? "" : win
    ControlGet, mode, Choice, , ListBox2
    VimDConfig_keymap_loadhotkey(win, mode)
return

VimDConfig_keymap_loadhotkey_new(win, mode = "")
{
    global vim
    global current_keymap := ""
    if StrLen(mode)
    {
        winObj  := vim.GetWin(win)
        modeobj := winObj.modeList[mode]
    }
    else
        modeobj := vim.GetMode(win)
    Gui, VimDConfig_keymap:Default
    idx := 1
    LV_Delete()

    for key, i in modeobj.keymapList
    {
        if (vim.GetAction(i).Type = 1)
        {
            ActionDescList := vim.GetAction(i).Comment
            actionDesc := StrSplit(%ActionDescList%[key], "|")
            current_keymap .= Key "`t" actionDesc[1]  "`n"
        }
        else
        {
            current_keymap .= Key "`t" i  "`n"
        }
    }

    ;~ msgbox %current_keymap%
    Clipboard:=current_keymap
    for action, type in vim.ActionFromPlugin
    {
        if type = %win%
        {
            Desc := vim.GetAction(action)
            ;~ if RegExMatch(current_keymap, action)
            if InStr(current_keymap, action)
            {
                reg:="(.*)\t" . action
                Loop, Parse, current_keymap, `n, `r
                {
                    if RegExMatch(A_LoopField, reg,m)
                    {
                        LV_Add("", idx, m1 ,action, Desc.Comment)
                        break
                    }
                    else
                        continue
                }
                idx++
                ;~ LV_Add("", idx, "启用",action, Desc.Comment)
            }
            else
            {
                LV_Add("", idx, "未启用" ,action, Desc.Comment)
                idx++
            }
        }
    }
    return
}

VimDConfig_keymap_loadhotkey(win, mode = "")
{
    global vim
    global current_keymap := ""
    If strlen(mode)
    {
        winObj  := vim.GetWin(win)
        modeobj := winObj.modeList[mode]
    }
    Else
        modeobj := vim.GetMode(win)
    GUI, VimDConfig_keymap:Default
    LV_delete()
    for key, i in modeobj.keymapList
    {
        ; Type = 1 : Function
        if (vim.GetAction(i).Type = 1)
        {
            ActionDescList := vim.GetAction(i).Comment
            actionDesc := StrSplit(%ActionDescList%[key], "|")
            LV_ADD("", Key, actionDesc[1], actionDesc[2])
            current_keymap .= Key "`t" actionDesc[1] "`t" actionDesc[2] "`n"
        }
        else
        {
            LV_Add("", Key, i, vim.GetAction(i).Comment)
            current_keymap .= Key "`t" i "`t" vim.GetAction(i).Comment "`n"
        }
    }
}

listview:
    if A_GuiEvent = DoubleClick
    {
        ;~ ToolTip You double-clicked row number %A_EventInfo%.
        LV_GetText(SelectedAction, A_EventInfo, 2)
        LV_GetText(SelectedDesc, A_EventInfo, 3)
        SearchFileForEdit(SelectedAction, SelectedDesc, false)
    }
    else if A_GuiEvent = R
    {
        LV_GetText(SelectedAction, A_EventInfo, 2)
        LV_GetText(SelectedDesc, A_EventInfo, 3)
        SearchFileForEdit(SelectedAction, SelectedDesc, true)
    }

return

SearchFileForEdit(Action, Desc, EditKeyMapping)
{
    if (Action = "key" || Action = "run" || Action = "dir" || EditKeyMapping)
    {
        SearchLine := "=" Action

        if (Action = "key" || Action = "run" || Action = "dir")
        {
            SearchLine := Action "|" Desc
        }

        Loop, Read, %A_ScriptDir%\vimd.ini
        {
            if (InStr(A_LoopReadLine, SearchLine))
            {
                EditFile(A_ScriptDir "\vimd.ini", A_Index)
                return
            }
        }

        EditFile(A_ScriptDir "\vimd.ini")
        return
    }

    label := Action ":"
    FileEncoding,
    Loop, %A_ScriptDir%\plugins\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (InStr(A_LoopReadLine, label) = 1)
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }

    Loop, %A_ScriptDir%\core\*.ahk, , 1
    {
        Loop, Read, %A_LoopFileFullPath%
        {
            if (InStr(A_LoopReadLine, label) = 1)
            {
                EditFile(A_LoopFileFullPath, A_Index)
                return
            }
        }
    }
}

EditFile(editPath, line := 1)
{
    editorArgs := {}
    editorArgs["notepad"] := "/g $line $file"
    editorArgs["notepad2"] := "/g $line $file"
    editorArgs["sublime_text"] := "$file:$line"
    editorArgs["vim"] := "+$line $file"
    editorArgs["gvim"] := "--remote-silent-tab +$line $file"
    editorArgs["everedit"] := "-n$line $file"
    editorArgs["notepad++"] := "-n$line $file"
    editorArgs["EmEditor"] := "-l $line $file"
    editorArgs["uedit32"] := "$file/$line"
    editorArgs["Editplus"] := "$file -cursor $line"
    editorArgs["textpad"] := "$file($line)"
    editorArgs["pspad"] := "$file /$line"
    editorArgs["ConTEXT"] := "$file /g1:$line"
    editorArgs["scite"] := "$file -goto:$line"

    Global editor

    If not FileExist(editor)
    {
        MsgBox, 请配置 vimd.ini 中 [config] 中的 editor ，并重启 vimd ！
        return
    }

    ; 根据编辑器 exe 名称获取打开参数
    SplitPath, editor, , , OutExtension, OutNameNoExt
    args := editorArgs[OutNameNoExt]
    StringReplace, args, args, $line, %line%
    StringReplace, args, args, $file, "%editPath%"
    target := editor " " args
    if (OutExtension = "sh")
    {
        target := "sh.exe " target
    }

    run, %target%
}

search_keymap:
    global current_keymap
    search_to_display(current_keymap)
return

search_plugin:
    global current_plugin
    search_to_display(current_plugin)
return

search_to_display(lines)
{
    Gui Submit, nohide
    GuiControlGet, OutputVar, , _search

    text := StrSplit(lines, "`n")

    LV_Delete() ; 清理不掉，第二次加载后，都成了重复的了，不知道怎么处理
    GuiControl, -Redraw, listview ; 重新启用重绘 (上面把它禁用了)
    for k, v in text
    {
        if v =
            continue
        if Instr(v, OutputVar)
        {
            list := StrSplit(v, "`t")
            LV_Add("", list[1], list[2], list[3])
        }
    }
    GuiControl, +Redraw, listview ; 重新启用重绘 (上面把它禁用了)
}


Code style

Code style

General:
    ; 通用功能
    Global FullScreenID := []
    ; 无任何快捷键定义，退出之前所有模式
    vim.mode("disable","General")

    ;插入模式
    vim.mode("insert","General")
    vim.map("<esc>","<General_mode_normal>","General")
    vim.map("<ctrl><esc>","<General_mode_disable>","General")

    ;normal模式
    vim.mode("normal","General")
    vim.map("<ctrl><esc>","<General_mode_disable>","General")
    vim.map("i","<General_mode_insert>","General")
    vim.map("0","<0>","General")
    vim.map("1","<1>","General")
    vim.map("2","<2>","General")
    vim.map("3","<3>","General")
    vim.map("4","<4>","General")
    vim.map("5","<5>","General")
    vim.map("6","<6>","General")
    vim.map("7","<7>","General")
    vim.map("8","<8>","General")
    vim.map("9","<9>","General")
    vim.map("k","<up>","General")
    vim.map("d","<GoToDesktop>","General")
    vim.map("r","<GoToRun>","General")
    vim.map("e","<GoToExplorer>","General")
    vim.map("j","<down>","General")
    vim.map("k","<up>","General")
    vim.map("h","<left>","General")
    vim.map("l","<right>","General")
    vim.map("zj","<WindowMoveDown>","General")
    vim.map("zk","<WindowMoveUp>","General")
    vim.map("zh","<WindowMoveLeft>","General")
    vim.map("zl","<WindowMoveRight>","General")
    vim.map("zc","<WindowMoveCenter>","General")
    vim.map("zf","<fullscreen>","General")
    vim.map("zm","<WindowMax>","General")
    vim.map("zn","<WindowMin>","General")
    vim.map("zr","<WindowRestore>","General")
    vim.map("t","<NewTab>","General")
    vim.map("x","<CloseTab>","General")
    vim.map("gn","<NextTab>","General")
    vim.map("gp","<PrevTab>","General")
    vim.map("g1","<ActivateTab1>","General")
    vim.map("g2","<ActivateTab2>","General")
    vim.map("g3","<ActivateTab3>","General")
    vim.map("g4","<ActivateTab4>","General")
    vim.map("g5","<ActivateTab5>","General")
    vim.map("g6","<ActivateTab6>","General")
    vim.map("g7","<ActivateTab7>","General")
    vim.map("g8","<ActivateTab8>","General")
    vim.map("g9","<ActivateTab9>","General")
    vim.map("g0","<ActivateTab0>","General")

    vim.comment("<NextTab>","下一个标签")
    vim.comment("<PrevTab>","前一个标签")
    vim.comment("<CloseTab>","关闭当前标签")
    vim.comment("<NewTab>","新建标签")
    vim.comment("<ActivateTab1>","激活第一个标签")
    vim.comment("<ActivateTab2>","激活第二个标签")
    vim.comment("<ActivateTab3>","激活第三个标签")
    vim.comment("<ActivateTab4>","激活第四个标签")
    vim.comment("<ActivateTab5>","激活第五个标签")
    vim.comment("<ActivateTab6>","激活第六个标签")
    vim.comment("<ActivateTab7>","激活第七个标签")
    vim.comment("<ActivateTab8>","激活第八个标签")
    vim.comment("<ActivateTab9>","激活第九个标签")
    vim.comment("<ActivateTab0>","激活最后一个标签")
    vim.Comment("<1>","计数前缀1")
    vim.Comment("<2>","计数前缀2")
    vim.Comment("<3>","计数前缀3")
    vim.Comment("<4>","计数前缀4")
    vim.Comment("<5>","计数前缀5")
    vim.Comment("<6>","计数前缀6")
    vim.Comment("<7>","计数前缀7")
    vim.Comment("<8>","计数前缀8")
    vim.Comment("<9>","计数前缀9")
    vim.Comment("<0>","计数前缀0")
    vim.Comment("<left>","向左移动[Count]次")
    vim.Comment("<Right>","向右移动[Count]次")
    vim.Comment("<Down>","向下移动[Count]次")
    vim.Comment("<Up>","向上移动[Count]次")
    vim.Comment("<windowMoveDown>","窗口移动到下方")
    vim.Comment("<windowMoveUp>","窗口移动到上方")
    vim.Comment("<windowMoveLeft>","窗口移动到左侧")
    vim.Comment("<WindowMoveRight>","窗口移动到右侧")
    vim.Comment("<WindowMoveCenter>","窗口移动到中间")
    vim.Comment("<WindowMax>","最大化窗口")
    vim.Comment("<WindowMin>","最小化窗口")
    vim.Comment("<WindowRestore>","还原当前窗口")
    vim.Comment("<FullScreen>","全屏当前程序")
    vim.Comment("<GoToDesktop>","切换到桌面")
    vim.Comment("<GoToRun>","打开运行窗口")
    vim.Comment("<GoToExplorer>","运行文件管理器")
    vim.Comment("<Reload>","重启脚本")
    vim.Comment("<config>","打开配置界面")
    vim.Comment("<GeneralCopy>","复制General的热键到当前窗口")
    vim.comment("<ToggleShowComment>","切换是否显示快捷键提示")
    vim.comment("<General_mode_normal>","进入VIM普通模式")
    vim.comment("<General_mode_disable>","离开VIM模式")
    vim.comment("<General_mode_insert>","进入VIM插入模式")
    vim.comment("<pgup>","上一页")
    vim.comment("<pgdn>","下一页")
    vim.comment("<home>","按下Home键")
    vim.comment("<end>","按下End键")
    vim.comment("<enter>","按下回车键")
    vim.comment("<Pass>","退出快捷提示")
    vim.comment("<Media_Next>","播放下一首")
    vim.comment("<Media_Prev>","播放上一首")
    vim.comment("<Media_Play_Pause>","播放/停止")
    vim.comment("<Media_Stop>","停止播放")
return

<1>:
<2>:
<3>:
<4>:
<5>:
<6>:
<7>:
<8>:
<9>:
<0>:

return

<down>:
    send {down}
return
<up>:
    send {up}
return
<left>:
    send {left}
return
<right>:
    send {right}
return
<pgup>:
    send {pgup}
return
<pgdn>:
    send {pgdn}
return
<enter>:
    send {enter}
return
<home>:
    send {home}
return
<end>:
    send {end}
return
<Media_Next>:
    send {Media_Next}
return
<Media_Prev>:
    send {Media_Prev}
return
<Media_Stop>:
    send {Media_Stop}
return
<Media_Play_Pause>:
    send {Media_Play_Pause}
return

<ControlOn>:
    vim.control("on")
return

<ControlOff>:
    vim.control("off")
return

<General_mode_normal>:
    WinGetClass,win,A
    vim.mode("normal",win)
return

<General_mode_disable>:
    WinGetClass,win,A
    vim.mode("disable",win)
    WinGet,Path,ProcessPath,A
    Splitpath,Path,,,,name
    Tooltip,%Name%禁用VIM模式
    settimer,VIMOK,-1400
    return

<General_mode_insert>:
    WinGetClass,win,A
    vim.mode("Insert",win)
return

<GeneralCopy>:
    GeneralCopy()
return
GeneralCopy() {
    WinGetClass,win,A
    vim.copy("General",win)
    vim.mode("normal",win)
    WinGet,Path,ProcessPath,A
    Splitpath,Path,,,,name
    Tooltip,%Name%启用VIM模式
    settimer,VIMOK,-1400
}

VIMOK:
    Tooltip
return

<GoToDesktop>:
    Send #d
return

<GoToRun>:
    Send #r
return

<GoToExplorer>:
    Run %A_WinDir%\explorer.exe
return

<WindowMoveDown>:
    WindowPadMove("0, +1,  1.0, 0.5")
Return
<WindowMoveUp>:
    WindowPadMove("0, -1,  1.0, 0.5")
Return
<WindowMoveLeft>:
    WindowPadMove("-1,  0,  0.5, 1.0")
Return
<WindowMoveRight>:
    WindowPadMove("+1,  0,  0.5, 1.0")
Return
<WindowMoveCenter>:
    WindowPadMove("0,  0,  0.5, 0.7")
return
<WindowMax>:
    WinMaximize,A
return
<WindowMin>:
    WinMinimize, A
return
<WindowRestore>:
    WinRestore, A
return

; 全屏当前程序
<FullScreen>:
    FullScreen()
return
FullScreen() {
    WinGet, windowID, ID, A
    WindowState := FullScreenID[windowID]
    If Strlen(windowState) = 0
        WindowState := 0
    If WindowState
    {
        WinSet, Style, ^0xC40000, ahk_id %WindowID%
        Loop,Parse,windowState,`,
        {
            If A_Index = 2
                WinPosX := A_LoopField
            If A_Index = 3
                WinPosY := A_LoopField
            If A_Index = 4
                WindowWidth := A_LoopField
            If A_Index = 5
                WindowHeight := A_LoopField
        }
        WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
        WindowState := 0
    }
    Else
    {
        WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
        WinSet, Style, ^0xC40000, ahk_id %WindowID%
        WinMove, ahk_id %WindowID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
        WindowState := 1 "," WinPosX "," WinPosY "," WindowWidth "," WindowHeight
        Msgbox 再按一下刚刚的热键退出全屏
    }
    FullScreenID[windowID] := WindowState
}

;====================================================================================
;
; WindowPad.ahk
; Version: 0.4
; Last Updated: 11/5/2009
;
; This file contains functions which are useful for manipulating and moving windows.
; This is a stripped down version of WindowPad v.1.56 by Lexikos.
; Downloaded from http://www.autohotkey.com/forum/topic21703.html
;

WindowPadMove(P)
{
    StringSplit, P, P, `,, %A_Space%%A_Tab%
    ; Params: 1:dirX, 2:dirY, 3:widthFactor, 4:heightFactor, 5:window

    if P1 =
        P1 = R
    if P2 =
        P2 = R

    WindowPad_WinExist(P5)

    if !WinExist()
        return

    ; Determine width/height factors.
    if (P1 or P2)
    {
        ; to a side
        widthFactor  := P3+0 ? P3 : (P1 ? 0.5 : 1.0)
        heightFactor := P4+0 ? P4 : (P2 ? 0.5 : 1.0)
    }
    else
    {
        ; to center
        widthFactor  := P3+0 ? P3 : 1.0
        heightFactor := P4+0 ? P4 : 1.0
    }

    ; Move the window!
    MoveWindowInDirection(P1, P2, widthFactor, heightFactor)
}

MaximizeToggle(P)
{
    WindowPad_WinExist(P)

    WinGet, state, MinMax
    if state
        WinRestore
    else
        WinMaximize
}

; Does the grunt work of the script.
MoveWindowInDirection(sideX, sideY, widthFactor, heightFactor)
{
    WinGetPos, x, y, w, h

    hwnd:=WinExist()
    if (can_restore := GetWindowProperty(hwnd,"wpHasRestorePos"))
    {
        ; Window has restore info. Check if it is where we last put it.
        last_x := GetWindowProperty(hwnd,"wpLastX")
        last_y := GetWindowProperty(hwnd,"wpLastY")
        last_w := GetWindowProperty(hwnd,"wpLastW")
        last_h := GetWindowProperty(hwnd,"wpLastH")
    }
    if (can_restore && last_x = x && last_y = y && last_w = w && last_h = h)
    {
        ; Window is where we last put it. Check if user wants to restore.
        if SubStr(sideX,1,1) = "R"
        {
            ; Restore on X-axis.
            restore_x := GetWindowProperty(hwnd,"wpRestoreX")
            restore_w := GetWindowProperty(hwnd,"wpRestoreW")
            StringTrimLeft, sideX, sideX, 1
        }
        if SubStr(sideY,1,1) = "R"
        {
            ; Restore on Y-axis.
            restore_y := GetWindowProperty(hwnd,"wpRestoreY")
            restore_h := GetWindowProperty(hwnd,"wpRestoreH")
            StringTrimLeft, sideY, sideY, 1
        }
        if (restore_x != "" || restore_y != "")
        {
            ; If already at the "restored" size and position, do the normal thing instead.
            if ((restore_x = x || restore_x = "") && (restore_y = y || restore_y = "")
                && (restore_w = w || restore_w = "") && (restore_h = h || restore_h = ""))
            {
                restore_x =
                restore_y =
                restore_w =
                restore_h =
            }
        }
    }
    else
    {
        ; Next time user requests the window be "restored" use this position and size.
        SetWindowProperty(hwnd,"wpHasRestorePos",true)
        SetWindowProperty(hwnd,"wpRestoreX",x)
        SetWindowProperty(hwnd,"wpRestoreY",y)
        SetWindowProperty(hwnd,"wpRestoreW",w)
        SetWindowProperty(hwnd,"wpRestoreH",h)

        if SubStr(sideX,1,1) = "R"
            StringTrimLeft, sideX, sideX, 1
        if SubStr(sideY,1,1) = "R"
            StringTrimLeft, sideY, sideY, 1
    }

    ; If no direction specified, restore or only switch monitors.
    if (sideX+0 = "" && restore_x = "")
        restore_x := x, restore_w := w
    if (sideY+0 = "" && restore_y = "")
        restore_y := y, restore_h := h

    ; Determine which monitor contains the center of the window.
    m := GetMonitorAt(x+w/2, y+h/2)

    ; Get work area of active monitor.
    gosub CalcMonitorStats
    ; Calculate possible new position for window.
    gosub CalcNewSizeAndPosition

    ; If the window is already there,
    if (newx "," newy "," neww "," newh) = (x "," y "," w "," h)
    {
        ; ..move to the next monitor along instead.
        if (sideX or sideY)
        {
            ; Move in the direction of sideX or sideY.
            SysGet, monB, Monitor, %m% ; get bounds of entire monitor (vs. work area)
            x := (sideX=0) ? (x+w/2) : (sideX>0 ? monBRight : monBLeft) + sideX
            y := (sideY=0) ? (y+h/2) : (sideY>0 ? monBBottom : monBTop) + sideY
            newm := GetMonitorAt(x, y, m)
        }
        else
        {
            ; Move to center (Numpad5)
            newm := m+1
            SysGet, mon, MonitorCount
            if (newm > mon)
                newm := 1
        }

        if (newm != m)
        {
            m := newm
            ; Move to opposite side of monitor (left of a monitor is another monitor's right edge)
            sideX *= -1
            sideY *= -1
            ; Get new monitor's work area.
            gosub CalcMonitorStats
        }
        else
        {
            ; No monitor to move to, alternate size of window instead.
            if sideX
                widthFactor /= 2
            else if sideY
                heightFactor /= 2
            else
                widthFactor *= 1.5
            gosub CalcNewSizeAndPosition
        }

        ; Calculate new position for window.
        gosub CalcNewSizeAndPosition
    }

    ; Restore before resizing...
    WinGet, state, MinMax
    if state
        WinRestore

    WinDelay := A_WinDelay
    SetWinDelay, 0

    ; Move the window!
    WinMove,,, newx, newy, neww, newh

    ; For console windows and other windows which have size restrictions, check
    ; that the window was actually resized. If not, reposition based on actual size.
    WinGetPos, newx, newy, realw, realh
    if (neww != realw || newh != realh)
    {
        neww := realw
        newh := realh
        gosub CalcNewPosition
        if ((newm = "" || newm = m) && (newx "," newy "," realw "," realh)=(x "," y "," w "," h))
        {
            if sideX
                neww //= 2
            else if sideY
                newh //= 2
            else
                neww := Round(neww*1.5)
            ; Size first, since the window size will probably be restricted in some way.
            WinMove,,,,, neww, newh
            WinGetPos,,, neww, newh
            gosub CalcNewPosition
        }
        WinMove,,, newx, newy
    }

    ; Explorer uses WM_EXITSIZEMOVE to detect when a user finishes moving a window
    ; in order to save the position for next time. May also be used by other apps.
    PostMessage, 0x232

    SetWinDelay, WinDelay

    ; Remember where we put it, to detect if the user moves it.
    SetWindowProperty(hwnd,"wpLastX",newx)
    SetWindowProperty(hwnd,"wpLastY",newy)
    SetWindowProperty(hwnd,"wpLastW",neww)
    SetWindowProperty(hwnd,"wpLastH",newh)
    return

CalcNewSizeAndPosition:
    ; Calculate new size.
    if (IsResizable()) {
        neww := restore_w != "" ? restore_w : Round(monWidth * widthFactor)
        newh := restore_h != "" ? restore_h : Round(monHeight * heightFactor)
    } else {
        neww := w
        newh := h
    }
CalcNewPosition:
    ; Calculate new position.
    newx := restore_x != "" ? restore_x : Round(monLeft + (sideX+1) * (monWidth  - neww)/2)
    newy := restore_y != "" ? restore_y : Round(monTop  + (sideY+1) * (monHeight - newh)/2)
    return

CalcMonitorStats:
    ; Get work area (excludes taskbar-reserved space.)
    SysGet, mon, MonitorWorkArea, %m%
    monWidth  := monRight - monLeft
    monHeight := monBottom - monTop
    return
}

; Get/set window property. type should be int, uint or float.
GetWindowProperty(hwnd, property_name, type="int") {
    return DllCall("GetProp", "uint", hwnd, "str", property_name, type)
}
SetWindowProperty(hwnd, property_name, data, type="int") {
    return DllCall("SetProp", "uint", hwnd, "str", property_name, type, data)
}

; Get the index of the monitor containing the specified x and y co-ordinates.
GetMonitorAt(x, y, default=1)
{
    SysGet, m, MonitorCount
    ; Iterate through all monitors.
    Loop, %m%
    {
        ; Check if the window is on this monitor.
        SysGet, Mon, Monitor, %A_Index%
        if (x >= MonLeft && x <= MonRight && y >= MonTop && y <= MonBottom)
            return A_Index
    }

    return default
}

IsResizable()
{
    WinGetClass, Class
    if Class = Chrome_XPFrame
        return true
    if Class = ConsoleWindowClass
        return false
    WinGet, Style, Style
    return (Style & 0x40000) ; WS_SIZEBOX
}

WindowPad_WinExist(WinTitle)
{
    if WinTitle = P
        return WinPreviouslyActive()
    if WinTitle = M
    {
        MouseGetPos,,, win
        return WinExist("ahk_id " win)
    }
    return WinExist(WinTitle!="" ? WinTitle : "A")
}

; Note: This may not work properly with always-on-top windows. (Needs testing)
WinPreviouslyActive()
{
    active := WinActive("A")
    WinGet, win, List

    ; Find the active window.
    ; (Might not be win1 if there are always-on-top windows?)
    Loop, %win%
        if (win%A_Index% = active)
        {
            if (A_Index < win)
                N := A_Index+1

            ; hack for PSPad: +1 seems to get the document (child!) window, so do +2
            ifWinActive, ahk_class TfPSPad
                N += 1

            break
        }

    ; Use WinExist to set Last Found Window (for consistency with WinActive())
    return WinExist("ahk_id " . win%N%)
}

;
; Switch without moving/resizing (relative to screen)
;
WindowScreenMove(P)
{
    SetWinDelay, 0

    StringSplit, P, P, `,, %A_Space%%A_Tab%
    ; 1:Next|Prev|Num, 2:Window

    WindowPad_WinExist(P2)

    WinGet, state, MinMax
    if state = 1
        WinRestore

    WinGetPos, x, y, w, h

    ; Determine which monitor contains the center of the window.
    ms := GetMonitorAt(x+w/2, y+h/2)

    SysGet, mc, MonitorCount

    ; Determine which monitor to move to.
    if P1 in ,N,Next
    {
        md := ms+1
        if (md > mc)
            md := 1
    }
    else if P1 in P,Prev,Previous
    {
        md := ms-1
        if (md < 1)
            md := mc
    }
    else if P1 is integer
        md := P1

    if (md=ms or (md+0)="" or md<1 or md>mc)
        return

    ; Get source and destination work areas (excludes taskbar-reserved space.)
    SysGet, ms, MonitorWorkArea, %ms%
    SysGet, md, MonitorWorkArea, %md%
    msw := msRight - msLeft, msh := msBottom - msTop
    mdw := mdRight - mdLeft, mdh := mdBottom - mdTop

    ; Calculate new size.
    if (IsResizable()) {
        w := Round(w*(mdw/msw))
        h := Round(h*(mdh/msh))
    }

    ; Move window, using resolution difference to scale co-ordinates.
    WinMove,,, mdLeft + (x-msLeft)*(mdw/msw), mdTop + (y-msTop)*(mdh/msh), w, h

    if state = 1
        WinMaximize
}

;
; "Gather" windows on a specific screen.
;
GatherWindows(md=1)
{
    global ProcessGatherExcludeList

    SetWinDelay, 0

    ; List all visible windows.
    WinGet, win, List

    ; Copy bounds of all monitors to an array.
    SysGet, mc, MonitorCount
    Loop, %mc%
        SysGet, mon%A_Index%, MonitorWorkArea, %A_Index%

    if md = M
    {
        ; Special exception for 'M', since the desktop window
        ; spreads across all screens.
        CoordMode, Mouse, Screen
        MouseGetPos, x, y
        md := GetMonitorAt(x, y, 0)
    }
    else if md is not integer
    {
        ; Support A, P and WinTitle.
        ; (Gather at screen containing specified window.)
        WindowPad_WinExist(md)
        WinGetPos, x, y, w, h
        md := GetMonitorAt(x+w/2, y+h/2, 0)
    }
    if (md<1 or md>mc)
        return

    ; Destination monitor
    mdx := mon%md%Left
    mdy := mon%md%Top
    mdw := mon%md%Right - mdx
    mdh := mon%md%Bottom - mdy

    Loop, %win%
    {
        ; If this window matches the GatherExclude group, don't touch it.
        if (WinExist("ahk_group GatherExclude ahk_id " . win%A_Index%))
            continue

        ; Set Last Found Window.
        if (!WinExist("ahk_id " . win%A_Index%))
            continue

        WinGet, procname, ProcessName
        ; Check process (program) exclusion list.
        if procname in %ProcessGatherExcludeList%
            continue

        WinGetPos, x, y, w, h

        ; Determine which monitor this window is on.
        xc := x+w/2, yc := y+h/2
        ms := 0
        Loop, %mc%
            if (xc >= mon%A_Index%Left && xc <= mon%A_Index%Right
                && yc >= mon%A_Index%Top && yc <= mon%A_Index%Bottom)
            {
                ms := A_Index
                break
            }
        ; If already on destination monitor, skip this window.
        if (ms = md)
            continue

        WinGet, state, MinMax
        if (state = 1) {
            WinRestore
            WinGetPos, x, y, w, h
        }

        if ms
        {
            ; Source monitor
            msx := mon%ms%Left
            msy := mon%ms%Top
            msw := mon%ms%Right - msx
            msh := mon%ms%Bottom - msy

            ; If the window is resizable, scale it by the monitors' resolution difference.
            if (IsResizable()) {
                w *= (mdw/msw)
                h *= (mdh/msh)
            }

            ; Move window, using resolution difference to scale co-ordinates.
            WinMove,,, mdx + (x-msx)*(mdw/msw), mdy + (y-msy)*(mdh/msh), w, h
        }
        else
        {
            ; Window not on any monitor, move it to center.
            WinMove,,, mdx + (mdw-w)/2, mdy + (mdh-h)/2
        }

        if state = 1
            WinMaximize
    }
}

GetLastMinimizedWindow()
{
    WinGet, w, List

    Loop %w%
    {
        wi := w%A_Index%
        WinGet, m, MinMax, ahk_id %wi%
        if m = -1 ; minimized
        {
            lastFound := wi
            break
        }
    }

    return "ahk_id " . (lastFound ? lastFound : 0)
}

;================================== 功能代码 :由北风一叶提供
;下一个标签
<NextTab>:
    send ^{tab}
return

;上一个标签
<PrevTab>:
    send ^+{tab}
return

;关闭当前标签
<CloseTab>:
    send ^{w}
return

;新建标签
<NewTab>:
    send ^{t}
return

;激活第一个标签
<ActivateTab1>:
    send ^{1}
return

;激活第二个标签
<ActivateTab2>:
    send ^{2}
return

;激活第三个标签
<ActivateTab3>:
    send ^{3}
return

;激活第四个标签
<ActivateTab4>:
    send ^{4}
return

;激活第五个标签
<ActivateTab5>:
    send ^{5}
return

;激活第六个标签
<ActivateTab6>:
    send ^{6}
return

;激活第七个标签
<ActivateTab7>:
    send ^{7}
return

;激活第八个标签
<ActivateTab8>:
    send ^{8}
return

;激活第九个标签
<ActivateTab9>:
    send ^{8}^{tab}
return

;激活最后一个标签
<ActivateTab0>:
    send ^{9}
return

;设置是否显示快捷键提示
<ToggleShowComment>:
    ToShowComment := not ToShowComment
    IniWrite %ToShowComment%, %A_ScriptDir%\vimd.ini, Config, ToShowComment
return

;空操作
<Pass>:
return


Added no-op shortcuts for win+hjkl to ahk

;Control key Ctrl- ^
;Alt key Alt- !
;Shift key Shift- +
;Windows key Win- #

#Persistent
;#NoTrayIcon
#SingleInstance Force
DetectHiddenWindows, On
DetectHiddenText, On
SetTitleMatchMode, RegEx ;match titles and classes using regular expressions
SetTitleMatchMode Slow ;match titles and classes using regular expressions
CoordMode, Mouse, Screen
CoordMode, ToolTip, Screen
OldTicks = 0

;check for cygwin path
global CygPath
CygPath = C:\Program Files (x86)\cygwin
IfNotExist %CygPath%
	CygPath = C:\Cygwin

global BrowserPath
BrowserPath = C:\Program Files (x86)\Mozilla Firefox\firefox.exe
IfNotExist %BrowserPath%
	BrowserPath = "C:\Users\rr-\AppData\Local\Google\Chrome\Application\chrome.exe"

global IMClass
global IMPath

;pidgin
IMClass := "Buddy List"
IMPath := "C:\Program Files (x86)\pidgin\pidgin.exe"
If !FileExist(IMPath) {
	;wtw
	IMClass := "ahk_class {B993D471-D465-43f2-BBA5-DEEA18A1789E}"
	IMPath := "C:\Program Files\WTW\WTW.exe"
	If !FileExist(IMPath) {
		IMPath := "C:\Program Files\K2T\WTW\WTW.exe"
	}
}

global MonitorWorkAreaLeft
global MonitorWorkAreaRight
global MonitorWorkAreaTop
global MonitorWorkAreaBottom
SysGet, MonitorPrimary, MonitorPrimary
SysGet, MonitorWorkArea, MonitorWorkArea, %MonitorPrimary%

;disable windows+l
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1

TermX := MonitorWorkAreaRight - 920
TermY := 45
RemoteTermX := 45
RemoteTermY := 45

;GroupAdd, adobe, ahk_class OWL.DocumentWindow
;GroupAdd, adobe, ahk_class illustrator
;GroupAdd, adobe, ahk_class PSViewC
;GroupAdd, adobe, ahk_class Photoshop
;GroupAdd, adobe, Photoshop

return

;replace stuff in clipboard when it changes
OnClipboardChange:
{
	if (A_EventInfo == 1) and (SubStr(clipboard, 1, 7) == "http://")
	{
		StringReplace, clipboard, clipboard, [, `%5b, All
		StringReplace, clipboard, clipboard, \, `%5c, All
		StringReplace, clipboard, clipboard, ], `%5d, All
	}
	return
}

;declare some fun functions...

;activate/run a program
FRun(window, path, folder)
{
	if (!window or !WinExist(window))
	{
		Run, %path%, %folder%
	}
	else
	{
		WinShow
		WinActivate
	}
	return
}

;create random file name
RandomFileName()
{
	FormatTime, fileName,, yyyyMMdd_HHmmss_
	characters := "abcdefghijklmnopqrstuvwxyz"
	Loop 3
	{
		Random, rand, 1, strlen(characters)
		fileName := fileName . substr(characters, rand, 1)
	}
	return fileName
}

;calling screen script
MakeScreen(arguments)
{
	baseFileName := "Z:\" . RandomFileName() . ".png"
	RunWait, % "Z:\software\utilities\scrsh.exe --path " . baseFileName . " " . arguments, "Z:\", Hide
	SoundPlay, Z:\clutter\sounds\ping.wav
	return baseFileName
}

#If FileExist(CygPath)
	;cygwin - activate/run
	#Enter::
	{
		Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%TermX%`,%TermY%" --class "mintty_thetty" --exec /bin/zsh -l, %CygPath%
		return
	}
	+^![::
	{
		Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%TermX%`,%TermY%" --class "mintty_thetty" --exec /bin/zsh -l, %CygPath%
		return
	}
	^![::
	{
		if (!WinExist("ahk_class mintty_thetty"))
		{
			Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%TermX%`,%TermY%" --class "mintty_thetty" --exec /bin/zsh -c 'while /bin/true`; do /bin/zsh -l`; cygstart "%A_AhkPath%" "Z:\src\dotfiles\hide.ahk"`; clear; done', %CygPath%
			WinWait ahk_class mintty_thetty
		}
		else
		{
			WinShow
			WinActivate
		}
		return
	}
	;ssh to burza - activate/run
	+^!]::
	{
		Run, %CygPath%\bin\mintty.exe --title "Remote terminal" --size "190`,65" --position "%RemoteTermX%`,%RemoteTermY%" --class mintty_ssh --exec /bin/ssh -p 65000 rr-@sakuya.pl, %CygPath%/bin
		return
	}
	^!]::
	{
		if (!WinExist("ahk_class mintty_ssh"))
		{
			Run, %CygPath%\bin\mintty.exe --title "Remote terminal" --size "190`,65" --position "%RemoteTermX%`,%RemoteTermY%" --class mintty_ssh --exec /bin/ssh -p 65000 rr-@sakuya.pl, %CygPath%/bin
			WinWait ahk_class mintty_ssh
		}
		else
		{
			WinShow
			WinActivate
		}
		return
	}
	;text editor - activate/run + fix screen position
	+^!N::
	{
		IfWinExist, ahk_class Vim
		{
			WinShow
			WinActivate
		}
		else
		{
			Run, %CygPath%\bin\mintty.exe --size "240`,90" --position "100`,45" --class "Vim" --exec /bin/zsh -l -i -c /bin/vim, %CygPath%/bin
			WinWait, ahk_class Vim
		}
		WinMove, , , 100, 100, 1600, 900
		return
	}
	+PrintScreen::MakeScreen("-g")
	!PrintScreen::MakeScreen("-r active-window --shift -8,-8,+16,+16 --force-gui")
	!#PrintScreen::MakeScreen("-r active-monitor")
	#PrintScreen::MakeScreen("-r all-monitors")

;explorer - activate/run
#E::FRun("ahk_class CabinetWClass", "Z:\", "Z:\")

;foobar - activate/run
#If FileExist("C:\program files (x86)\foobar2000\foobar2000.exe")
	Launch_Media::FRun("ahk_class {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}", "C:\program files (x86)\foobar2000\foobar2000.exe", "C:\Program Files (x86)\foobar2000")

;foobar - media shortcuts
AppsKey::Send {AppsKey}
+AppsKey::Send +{AppsKey}
AppsKey & Insert::Send {Launch_Media}
AppsKey & Home::Send {Media_Prev}
AppsKey & End::Send {Media_Next}
AppsKey & Del::Send {Media_Play_Pause}
AppsKey & PgUp::Send {Volume_Up}
AppsKey & PgDn::Send {Volume_Down}

;im
#If FileExist(IMPath)
	;im - activate/run
	+^!M::
		if (!WinExist(IMClass))
		{
			Run, %IMPath% -x
		}
		else
		{
			WinShow
			WinActivate
		}
		return

;cdisplayex - activate/run
#If FileExist("C:\Program Files (x86)\CDisplayEx\cdisplayex.exe")
	^!/::FRun("CDisplayEx", "C:\Program Files (x86)\CDisplayEx\cdisplayex.exe", "Z:\")

;browser
#If FileExist(BrowserPath)
	;web browser - activate/run
	^!;::
		if WinExist("Mozilla Firefox")
		{
			WinShow
			WinActivate
			Send, !d
		}
		else if WinExist("Vimperator")
		{
			WinShow
			WinActivate
			Send, !d
		}
		else if WinExist("ahk_class Chrome_WidgetWin_1")
		{
			WinActivate
			ControlFocus, Chrome_OmniboxView1
			SendInput, {Home}+{End}
		}
		else
		{
			IfExist %BrowserPath%
				Run, %BrowserPath%
		}
		return

;mintty functionalities
#IfWinActive ahk_class mintty*
	^!PgUp::SendInput +{PgUp} ;scroll on ctrl+alt+page up
	^!PgDn::SendInput +{PgDn} ;scroll on ctrl+alt+page down
#IfWinActive

;windows powershell / cmd functionalities
#IfWinActive ahk_class ConsoleWindowClass
	^V::SendInput {Raw}%clipboard% ;paste on ctrl+v
	^!PgUp::SendInput ! {Up}{Up}{Up}{Right}{Up}{Up}{Enter}{PgUp}{Enter} ;scroll on ctrl+alt+page up
	^!PgDn::SendInput ! {Up}{Up}{Up}{Right}{Up}{Up}{Enter}{PgDn}{Enter} ;scroll on ctrl+alt+page down
#IfWinActive

;acdsee functionalities
#IfWinActive ahk_class ACDBrowser
	WheelDown::Send, ^{Down}^{Space}
	WheelUp::Send, ^{Up}^{Space}
	^!X::
		SendInput {Left 10}{Shift down}{Right 10}{Shift up}
		return
#IfWinActive
#IfWinActive ACDSee
	WheelDown::
		if (A_TickCount - OldTicks >= 80)
		{
			Send, {WheelDown}
			OldTicks := A_TickCount
		}
		return
	]:: ;send to document folder
	RButton & ~LButton::
		FormatTime, Folder,, 'Z:\'
		Send {LAlt down}c
		Send {LAlt up}
		SendInput %Folder%
		Send {Return}
		return
	[:: ;send to upload folder
	~LButton & RButton::
		Send {LAlt down}c
		Send {LAlt up}
		SendInput Z:\hub\yume.pl
		Send {Return}
		Sleep 100
		return
	XButton1::
		WinGet, Transparency, Transparent, A
		if ! Transparency
			WinSet, Transparent, 255, A
		else if Transparency = 255
			WinSet, Transparent, 0, A
		return
	XButton2:: ;start slideshow
		Send {Pause}
		return
#IfWinActive

;other functionalities

;autohotkey - reload this script
!F11::
{
	Process, Close, Rainmeter.exe
	Run, C:\Program Files \Rainmeter\Rainmeter.exe
	return
}
!F12::Reload

;maximize active window
!M::
	ActiveHwnd := WinExist("A")
	PostMessage 0x112, 0xf030 ;WM_SYSCOMMAND, SC_MAXIMIZE
	return

;restore active window
!R::
	ActiveHwnd := WinExist("A")
	PostMessage 0x112, 0xf120 ;WM_SYSCOMMAND, SC_RESTORE
	return

;minimize active window
!W::
	if WinActive("WTW$")
	{
		WinHide
	}
	else if WinActive("Buddy List")
	{
		WinHide
	}
	else
	{
		ActiveHwnd := WinExist("A")
		PostMessage 0x112, 0xF020 ;WM_SYSCOMMAND, SC_MINIMIZE
	}
	return

;always on top
!A::WinSet, AlwaysOnTop, Toggle, A

;transparency
#WheelUp::
	WinGet, Transparency, Transparent, A
	if ! Transparency
		Transparency = 255
	Transparency := Transparency + 16
	if Transparency <= 10
	{
		WinSet, Transparent, 10, A
	}
	else if Transparency >= 255
	{
		WinSet, Transparent, 255, A
		WinSet, Transparent, OFF, A
	}
	else
	{
		WinSet, Transparent, %Transparency%, A
	}
	return
#WheelDown::
	WinGet, Transparency, Transparent, A
	if ! Transparency
		Transparency = 255
	Transparency := Transparency - 16
	if Transparency <= 10
	{
		WinSet, Transparent, 10, A
	}
	else if Transparency >= 255
	{
		WinSet, Transparent, 255, A
		WinSet, Transparent, OFF, A
	}
	else
	{
		WinSet, Transparent, %Transparency%, A
	}
	return

;explorer
#IfWinActive ahk_class CabinetWClass
	;new folder
	^n::
		SendInput {Up}{Ctrl Down}{Space}{Ctrl Up}{AppsKey}{Up}{Up}{Right}{Enter}
		return
#IfWinActive

;adobe products
#IfWinActive ahk_group adobe
	~LAlt::return
	LAlt UP::Send {Escape}
#IfWinActive

;shortcuts like in i3
;close active window
#Q::
	ActiveHwnd := WinExist("A")
	WinClose
	return
#D::
	SendInput, {LWin down}r{LWin up}
	return
#F::
	ActiveHwnd := WinExist("A")
	PostMessage 0x112, 0xf030 ;WM_SYSCOMMAND, SC_MAXIMIZE
	return
#H::return
#J::return
#K::return
#L::return