Add -l param to open-wsl

Add -l param to open-wsl

#NoTrayIcon
#NoEnv

args = %1%
IniRead, title, %A_ScriptDir%\etc\wsl-terminal.conf, config, title, "        "
IniRead, shell, %A_ScriptDir%\etc\wsl-terminal.conf, config, shell, "bash"
IniRead, use_cbwin, %A_ScriptDir%\etc\wsl-terminal.conf, config, use_cbwin, 0
IniRead, use_tmux, %A_ScriptDir%\etc\wsl-terminal.conf, config, use_tmux, 0
IniRead, attach_tmux_locally, %A_ScriptDir%\etc\wsl-terminal.conf, config, attach_tmux_locally, 0
IniRead, icon, %A_ScriptDir%\etc\wsl-terminal.conf, config, icon, ""

icon_string = -i "%A_ScriptFullPath%"
if (icon != "" && FileExist(icon))
{
    icon_string = -i "%icon%"
}

if (args = "-a" && WinExist(title))
{
    WinActivate, %title%
}
else if (!use_tmux)
{
    cmd = %shell%
    if (args = "-l")
    {
        cmd = %shell% -c "cd; %shell% -l"
    }

    Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -t %cmd%
}
else
{
    if (args = "-a" && !WinExist(title))
    {
        if (attach_tmux_locally)
        {
            Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -e USE_TMUX=1 -e ATTACH_ONLY=1 -t %shell%
        }
        else
        {
            Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -t %shell% -c "tmux a 2>/dev/null || tmux"
        }
    }
    else
    {
        if (WinExist(title))
        {
            Run, c:\windows\sysnative\bash -c 'tmux new-window -c "$PWD"', , Hide
            WinActivate, %title%
        }
        else
        {
            if (attach_tmux_locally)
            {
                Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -e USE_TMUX=1 -t %shell%
            }
            else
            {
                Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -t %shell% -c 'tmux new-window -c "$PWD" \; a 2>/dev/null || tmux'
            }
        }
    }
}

Loop, 5
{
    WinActivate, %title%
    if (WinActive(title))
    {
        break
    }

    Sleep, 50
}

if (use_cbwin)
{
    Process, Exist, outbash.exe

    if (ErrorLevel = 0)
    {
        Run, %A_ScriptDir%\bin\outbash --outbash-session -c 'exec sleep 10000000d', , Hide
    }
}
else if (use_tmux)
{
    ; Run a sleep to avoid tmux being killed.
    Process, Exist, sleep

    if (ErrorLevel = 0)
    {
        Run, c:\windows\sysnative\bash -c 'exec sleep 10000000d', , Hide
    }
}

#NoTrayIcon
#NoEnv

args = %1%
IniRead, title, %A_ScriptDir%\etc\wsl-terminal.conf, config, title, "        "
IniRead, shell, %A_ScriptDir%\etc\wsl-terminal.conf, config, shell, "bash"
IniRead, use_cbwin, %A_ScriptDir%\etc\wsl-terminal.conf, config, use_cbwin, 0
IniRead, use_tmux, %A_ScriptDir%\etc\wsl-terminal.conf, config, use_tmux, 0
IniRead, attach_tmux_locally, %A_ScriptDir%\etc\wsl-terminal.conf, config, attach_tmux_locally, 0
IniRead, icon, %A_ScriptDir%\etc\wsl-terminal.conf, config, icon, ""

icon_string = -i "%A_ScriptFullPath%"
if (icon != "" && FileExist(icon))
{
    icon_string = -i "%icon%"
}

if (args = "-a" && WinExist(title))
{
    WinActivate, %title%
}
else if (!use_tmux)
{
    Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -t %shell%
}
else
{
    if (args = "-a" && !WinExist(title))
    {
        if (attach_tmux_locally)
        {
            Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -e USE_TMUX=1 -e ATTACH_ONLY=1 -t %shell%
        }
        else
        {
            Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -t %shell% -c "tmux a 2>/dev/null || tmux"
        }
    }
    else
    {
        if (WinExist(title))
        {
            Run, c:\windows\sysnative\bash -c 'tmux new-window -c "$PWD"', , Hide
            WinActivate, %title%
        }
        else
        {
            if (attach_tmux_locally)
            {
                Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -e USE_TMUX=1 -t %shell%
            }
            else
            {
                Run, %A_ScriptDir%\bin\mintty %icon_string% -t "%title%" -e /bin/wslbridge -t %shell% -c 'tmux new-window -c "$PWD" \; a 2>/dev/null || tmux'
            }
        }
    }
}

Loop, 5
{
    WinActivate, %title%
    if (WinActive(title))
    {
        break
    }

    Sleep, 50
}

if (use_cbwin)
{
    Process, Exist, outbash.exe

    if (ErrorLevel = 0)
    {
        Run, %A_ScriptDir%\bin\outbash --outbash-session -c 'exec sleep 10000000d', , Hide
    }
}
else if (use_tmux)
{
    ; Run a sleep to avoid tmux being killed.
    Process, Exist, sleep

    if (ErrorLevel = 0)
    {
        Run, c:\windows\sysnative\bash -c 'exec sleep 10000000d', , Hide
    }
}


Update MBWindow.ahk

Update MBWindow.ahk

s

#IfWinActive ahk_exe MapInfoPro.exe ;THIS WILL NEED EXTENSION THROUGH "isMapBasicWindow()"
mbWin_enterBehaviour = 1

$Enter::    ;$ so Enter can be re-used
    If Not isMapBasicWindow() {
        send, {Enter}
        return
    }

    If (mbWin_enterBehaviour > 1) {
    	send, ^a{Enter}
    )

    ;Get the MapBasic source from the MapBasic Window
    old_clipboard := ClipboardAll
	Clipboard=
	send, ^c
	clipwait,0.1
	MBSource := clipboard
	clipboard := old_clipboard

	If (needsCompiling(MBSource)) {
	    Compile(MBSource)
	} else {
	    send,{Enter}
	}

return

isMapBasicWindow(){
    ;TO DO: This should have more (fast) checks.
    MapInfo = ComObjGet("MapInfo.Application.x64")
    return MapInfo.Eval("ActiveWindow()") = 1002
}

needsCompiling(src){
	;Separated RegEx - This may require simplifying...:
	i := 0
	i := i + regexmatch(src,"i)\bAlter\b\s+\b(Control|MapInfoDialog)\b")			;matches {Alter Control,Alter MapInfoDialog}
	i := i + regexmatch(src,"i)\bCall\b")						        ;matches Call
	i := i + regexmatch(src,"i)\bDeclare\b\s+\b(Function|Sub)\b")				;matches {Declare Function, Declare Sub}
	i := i + regexmatch(src,"i)\bDefine\b")						        ;matches Define
	i := i + regexmatch(src,"i)\bDialog\b")						        ;matches {Dialog, Dialog Preserve, Dialog Remove}
	i := i + regexmatch(src,"i)\bDim\s+\w+\s*(,\s*\w+\s*)+\s+as\b")				;matches Dim {2 variable declarations} as
	i := i + regexmatch(src,"i)\bDo\s+Case\s+(.|\s)*?\bEnd\s+Case\b")			;matches Do Case … End Case,
	i := i + regexmatch(src,"i)\bDo\b\s+(.|\s)*?\bLoop\b")				    	;matches Do … Loop
	i := i + regexmatch(src,"i)\bEnd\s+Program\b")					        ;matches End Program
	i := i + regexmatch(src,"i)\bExit\s+(Do|For|Function|Sub)\b")				;matches {Exit Do, Exit For, Exit Function, Exit Sub}
	i := i + regexmatch(src,"i)\bFor\b(.|\s)*?\bNext\b")				    	;matches For … Next,
	i := i + regexmatch(src,"i)\bFunction\b(.|\s)*\bEnd\s+Function\b")			;matches Function … End Function
	i := i + regexmatch(src,"i)\bGoTo\b")			            			;matches GoTo
	i := i + regexmatch(src,"i)\bSub\b(.|\s)*\bEnd\s+Sub\b")				;matches Sub … End Sub
	i := i + regexmatch(src,"i)\bIf\b(.|\s)*?\bThen\b(.|\s)*?\bEnd\s+If\b")			;matches If .*? then … End If
	i := i + regexmatch(src,"i)\bInclude\b\s+\b"".*""\b")				    	;matches Include “…”
	i := i + regexmatch(src,"i)\bOnError\s+GoTo\b")					        ;matches OnError GoTo
	i := i + regexmatch(src,"i)\bOpen\s+File\b")					    	;matches Open File
	i := i + regexmatch(src,"i)\bProgressBar\b")    					;matches ProgressBar
	i := i + regexmatch(src,"i)\bResume\b")			    				;matches Resume
	i := i + regexmatch(src,"i)\bSet\s+Handler\b")		    				;matches Set Handler
	i := i + regexmatch(src,"i)\bType\b(.|\s)*?\bEnd\s+Type\b") 				;matches Type … End Type
	i := i + regexmatch(src,"i)\bWhile\b(.|\s)*?\bWend\b")		    			;matches While … Wend
	return i > 0
}


switch xmind to MindMaster

switch xmind to MindMaster

^Tab::
Send #{Tab}
return

^`::
IfWinActive, ahk_exe ubuntu1804.exe
    Send !{Tab}
else
    WinActivate ahk_exe ubuntu1804.exe
return

^!`::
IfWinActive, ahk_exe vcxsrv.exe
    Send !{Tab}
else
    WinActivate ahk_exe vcxsrv.exe
return

^!1::
IfWinActive, ahk_exe powershell.exe
    Send !{Tab}
else
    WinActivate ahk_exe powershell.exe
return

^!t::
IfWinActive, ahk_exe mintty.exe
    Send !{Tab}
else
    WinActivate ahk_exe mintty.exe
return

^!m::
IfWinActive, ahk_exe C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    Send !{Tab}
else
    WinActivate ahk_exe C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
return

^!w::
IfWinActive, ahk_exe C:\Users\yjpark\AppData\Local\Google\Chrome SxS\Application\chrome.exe
    Send !{Tab}
else
    WinActivate ahk_exe C:\Users\yjpark\AppData\Local\Google\Chrome SxS\Application\chrome.exe
return

^!r::
IfWinActive, ahk_exe firefox.exe
    Send !{Tab}
else
    WinActivate ahk_exe firefox.exe
return

^!u::
IfWinActive, ahk_exe Unity.exe
    Send !{Tab}
else
    WinActivate ahk_exe Unity.exe
return

^!a::
IfWinActive, ahk_exe Code - Insiders.exe
    Send !{Tab}
else
    WinActivate ahk_exe Code - Insiders.exe
return

^!v::
IfWinActive, ahk_exe devenv.exe
    Send !{Tab}
else
    WinActivate ahk_exe devenv.exe
return

^!x::
IfWinActive, ahk_exe devenv.exe
    Send !{Tab}
else
    WinActivate ahk_exe devenv.exe
return

^!s::
IfWinActive, ahk_exe ApplicationFrameHost.exe
    Send !{Tab}
else
    WinActivate ahk_exe ApplicationFrameHost.exe
return

^!i::
IfWinActive, ahk_exe idea.exe
    Send !{Tab}
else
    WinActivate ahk_exe idea.exe
return

^!h::
IfWinActive, ahk_exe zeal.exe
    Send !{Tab}
else
    WinActivate ahk_exe zeal.exe
return

^!e::
IfWinActive, ahk_exe Evernote.exe
    Send !{Tab}
else
    WinActivate ahk_exe Evernote.exe
return

^!n::
IfWinActive, ahk_exe MindMaster.exe
    Send !{Tab}
else
    WinActivate ahk_exe MindMaster.exe
return

^!d::
IfWinActive, ahk_exe code.exe
    Send !{Tab}
else
    WinActivate ahk_exe code.exe
return

^!Space::
Process,close,explorer.exe
sleep, 50 ;This sleep 5000 is to let you see what actually happens. Decrease it later
run, explorer.exe
WinWait, ahk_class CabinetWClass
WinClose ;close the new explorer window
return

^Tab::
Send #{Tab}
return

^`::
IfWinActive, ahk_exe ubuntu1804.exe
    Send !{Tab}
else
    WinActivate ahk_exe ubuntu1804.exe
return

^!`::
IfWinActive, ahk_exe vcxsrv.exe
    Send !{Tab}
else
    WinActivate ahk_exe vcxsrv.exe
return

^!1::
IfWinActive, ahk_exe powershell.exe
    Send !{Tab}
else
    WinActivate ahk_exe powershell.exe
return

^!t::
IfWinActive, ahk_exe mintty.exe
    Send !{Tab}
else
    WinActivate ahk_exe mintty.exe
return

^!m::
IfWinActive, ahk_exe C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    Send !{Tab}
else
    WinActivate ahk_exe C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
return

^!w::
IfWinActive, ahk_exe C:\Users\yjpark\AppData\Local\Google\Chrome SxS\Application\chrome.exe
    Send !{Tab}
else
    WinActivate ahk_exe C:\Users\yjpark\AppData\Local\Google\Chrome SxS\Application\chrome.exe
return

^!r::
IfWinActive, ahk_exe firefox.exe
    Send !{Tab}
else
    WinActivate ahk_exe firefox.exe
return

^!u::
IfWinActive, ahk_exe Unity.exe
    Send !{Tab}
else
    WinActivate ahk_exe Unity.exe
return

^!a::
IfWinActive, ahk_exe Code - Insiders.exe
    Send !{Tab}
else
    WinActivate ahk_exe Code - Insiders.exe
return

^!v::
IfWinActive, ahk_exe devenv.exe
    Send !{Tab}
else
    WinActivate ahk_exe devenv.exe
return

^!x::
IfWinActive, ahk_exe devenv.exe
    Send !{Tab}
else
    WinActivate ahk_exe devenv.exe
return

^!s::
IfWinActive, ahk_exe ApplicationFrameHost.exe
    Send !{Tab}
else
    WinActivate ahk_exe ApplicationFrameHost.exe
return

^!i::
IfWinActive, ahk_exe idea.exe
    Send !{Tab}
else
    WinActivate ahk_exe idea.exe
return

^!h::
IfWinActive, ahk_exe zeal.exe
    Send !{Tab}
else
    WinActivate ahk_exe zeal.exe
return

^!e::
IfWinActive, ahk_exe Evernote.exe
    Send !{Tab}
else
    WinActivate ahk_exe Evernote.exe
return

^!n::
IfWinActive, ahk_exe xmind.exe
    Send !{Tab}
else
    WinActivate ahk_exe xmind.exe
return

^!d::
IfWinActive, ahk_exe code.exe
    Send !{Tab}
else
    WinActivate ahk_exe code.exe
return

^!Space::
Process,close,explorer.exe
sleep, 50 ;This sleep 5000 is to let you see what actually happens. Decrease it later
run, explorer.exe
WinWait, ahk_class CabinetWClass
WinClose ;close the new explorer window
return


tc_dialog排除自定义窗体时增加标题排除

TotalCommander_Dialog:
;本插件尝试将TotalCommander作为文件打开对话框
; * 默认添加快捷键<lwin>o ,在文件对话框或任意文字编辑界面按下快捷键跳转至TC--TC中选定文件后再次按下快捷键可实现文件打开功能
; * 尝试在打开文件对话框时，自动跳转到TC进行文件选择：#32770，焦点Edit1且内无文字,对话框内不含密码、password等内容
; * 增加select模式，按下回车或Ctrl+回车均可直接选定文件;未多选情况下在文件夹上按下回车时，进入该文件夹而非选定

vim.comment("<OpenTCDialog>","激活TC选择文件,需再次按下快捷键触发对话框打开事件")

;初始化设置：全局快捷键跳转到TC
IniWriteIfNullValue(ConfigPath,"Global","*<lwin>o","<OpenTCDialog>")

;初始化设置：自动跳转到TC作为文件选择对话框
IniWriteIfNull(ConfigPath,"TotalCommander_Config","AsOpenFileDialog","1")

;初始化设置：还有下面文字的窗口将排除TC作为文件选择对话框--由于不支持中文，无法初始化"密码"，在后面代码中添加
IniWriteIfNull(ConfigPath,"TotalCommander_Config","OpenFileDialogExclude","password,pwd")

;读取配置参数，禁用时直接跳过
IniRead,AsOpenFileDialog,%ConfigPath%,TotalCommander_Config,AsOpenFileDialog,1
if AsOpenFileDialog <> 1
	return

;读取排除窗体文字
;IniRead,OpenFileDialogExclude,%ConfigPath%,TotalCommander_Config,OpenFileDialogExclude,"密码,password"
Loop, read, %ConfigPath%
{
	ifInString, A_LoopReadLine, OpenFileDialogExclude
	{
		OpenFileDialogExclude := SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"=")+1)
		IfNotInString, OpenFileDialogExclude, 密码
			OpenFileDialogExclude .= ",密码"
		break
	}
}

;未发现TC路径时自动禁用该功能
if StrLen(TCPath) = 0
	return

;用于记录文件打开对话框所属窗体
global CallerId := 0

;等待OpenFileDialog出现
SetTimer, <CheckFileDialog>, 1000

return

;===============================================

;仅在执行文件选定时，开启select模式
;拷贝normal全部快捷键，并增加回车确认功能
<Select_Mode_TC>:
	vim.mode("select","TTOTAL_CMD")

	if Select_Copyed = 1
		return

	Select_Copyed := 1
	vim.CopyMode("TTOTAL_CMD","normal","select")
	vim.map("<enter>","<TC_PreSelected>","TTOTAL_CMD")
	vim.map("<ctrl><enter>","<TC_Selected>","TTOTAL_CMD")
	vim.map("<esc>","<Return_To_Caller>","TTOTAL_CMD")
	return

;返回调用者
<Return_To_Caller>:
	gosub,<Normal_Mode_TC>
	;未发现可激活的调用窗体时，最小化TC
	if CallerId = 0
	{
		Winminimize,AHK_CLASS TTOTAL_CMD
		sleep,500
		CallerId := WinExist("A")
		if CallerId = 0
			return
	}

	WinActivate,ahk_id %CallerId%
	return

;发现标准打开文件对话框，未记录，焦点控件为Edit1=>记录，并激活TC
<CheckFileDialog>:
{
	WinGetClass, class, A
	if class <> #32770
		return

	ControlGetFocus,ct, ahk_class #32770
	if ct <> Edit1
		return

	;以此排除“另存为”，或其它已经包含文字的对话框
	ControlGetText,str,Edit1,ahk_class #32770
	if StrLen(str) > 0
		return

	;排除用户自定义窗体
	WinGetText,str,ahk_class #32770
	WinGetTitle,title,ahk_class #32770
	str .= title
	Loop, parse, OpenFileDialogExclude, `,, %A_Space%%A_Tab%
	{
		If StrLen(A_LoopField) = 0
			continue
		IfInString,str,%A_LoopField%
			return
	}

	id := WinExist("A")
	if id = 0
		return
	if id = %CallerId%
		return

	CallerId := id
	gosub,<FocusTC>
	gosub,<Select_Mode_TC>
	return
}

; * 非TC窗口按下后激活TC窗口
; * TC窗口按下后复制当前选中文件返回原窗口后粘贴
<OpenTCDialog>:
{
	WinGetClass, class, A

	;在Total Commander按下快捷键时，激活调用窗体并执行粘贴操作
	if class = TTOTAL_CMD
	{
		gosub,<TC_Selected>
		return
	}

	if class <> TTOTAL_CMD
	{
		CallerId := WinExist("A")
		if CallerId = 0
			return

		gosub,<FocusTC>
		gosub,<Select_Mode_TC>
		return
	}

	return
}

<TC_PreSelected>:
	SendPos(2021)
	sleep,100 ; 此处用clipwait貌似会出错？

	;未多选
	IfNotInString,clipboard,`n
	{
		;当前复制项为文件夹时
		StringRight,str,clipboard,1
		IfInString,str,\
			{
				SendPos(2003)
				return
			}
	}

	;return 注意，此处无需return

<TC_Selected>:
{
	vim.mode("normal","TTOTAL_CMD")
	SendPos(2021)
	sleep,100

	;仅在多选时两侧增加双引号
	IfInString,clipboard,`n
	{
		files := ""
		Loop, parse, clipboard, `n, `r
			files .= """" A_LoopField  """ "
		clipboard := files
	}

	;未发现可激活的调用窗体时，最小化TC
	if CallerId = 0
	{
		Winminimize,AHK_CLASS TTOTAL_CMD
		sleep,500
		CallerId := WinExist("A")
		if CallerId = 0
			return
	}

	WinActivate,ahk_id %CallerId%
	WinWait,ahk_id %CallerId%
	send, ^v
	send, {Enter}
	return
}

TotalCommander_Dialog:
;本插件尝试将TotalCommander作为文件打开对话框
; * 默认添加快捷键<lwin>o ,在文件对话框或任意文字编辑界面按下快捷键跳转至TC--TC中选定文件后再次按下快捷键可实现文件打开功能
; * 尝试在打开文件对话框时，自动跳转到TC进行文件选择：#32770，焦点Edit1且内无文字,对话框内不含密码、password等内容
; * 增加select模式，按下回车或Ctrl+回车均可直接选定文件;未多选情况下在文件夹上按下回车时，进入该文件夹而非选定

vim.comment("<OpenTCDialog>","激活TC选择文件,需再次按下快捷键触发对话框打开事件")

;初始化设置：全局快捷键跳转到TC
IniWriteIfNullValue(ConfigPath,"Global","*<lwin>o","<OpenTCDialog>")

;初始化设置：自动跳转到TC作为文件选择对话框
IniWriteIfNull(ConfigPath,"TotalCommander_Config","AsOpenFileDialog","1")

;初始化设置：还有下面文字的窗口将排除TC作为文件选择对话框--由于不支持中文，无法初始化"密码"，在后面代码中添加
IniWriteIfNull(ConfigPath,"TotalCommander_Config","OpenFileDialogExclude","password,pwd")

;读取配置参数，禁用时直接跳过
IniRead,AsOpenFileDialog,%ConfigPath%,TotalCommander_Config,AsOpenFileDialog,1
if AsOpenFileDialog <> 1
	return

;读取排除窗体文字
;IniRead,OpenFileDialogExclude,%ConfigPath%,TotalCommander_Config,OpenFileDialogExclude,"密码,password"
Loop, read, %ConfigPath%
{
	ifInString, A_LoopReadLine, OpenFileDialogExclude
	{
		OpenFileDialogExclude := SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"=")+1)
		IfNotInString, OpenFileDialogExclude, 密码
			OpenFileDialogExclude .= ",密码"
		break
	}
}

;未发现TC路径时自动禁用该功能
if StrLen(TCPath) = 0
	return

;用于记录文件打开对话框所属窗体
global CallerId := 0

;等待OpenFileDialog出现
SetTimer, <CheckFileDialog>, 1000

return

;===============================================

;仅在执行文件选定时，开启select模式
;拷贝normal全部快捷键，并增加回车确认功能
<Select_Mode_TC>:
	vim.mode("select","TTOTAL_CMD")

	if Select_Copyed = 1
		return

	Select_Copyed := 1
	vim.CopyMode("TTOTAL_CMD","normal","select")
	vim.map("<enter>","<TC_PreSelected>","TTOTAL_CMD")
	vim.map("<ctrl><enter>","<TC_Selected>","TTOTAL_CMD")
	vim.map("<esc>","<Return_To_Caller>","TTOTAL_CMD")
	return

;返回调用者
<Return_To_Caller>:
	gosub,<Normal_Mode_TC>
	;未发现可激活的调用窗体时，最小化TC
	if CallerId = 0
	{
		Winminimize,AHK_CLASS TTOTAL_CMD
		sleep,500
		CallerId := WinExist("A")
		if CallerId = 0
			return
	}

	WinActivate,ahk_id %CallerId%
	return

;发现标准打开文件对话框，未记录，焦点控件为Edit1=>记录，并激活TC
<CheckFileDialog>:
{
	WinGetClass, class, A
	if class <> #32770
		return

	ControlGetFocus,ct, ahk_class #32770
	if ct <> Edit1
		return

	;以此排除“另存为”，或其它已经包含文字的对话框
	ControlGetText,str,Edit1,ahk_class #32770
	if StrLen(str) > 0
		return

	;排除用户自定义窗体
	WinGetText,str,ahk_class #32770
	Loop, parse, OpenFileDialogExclude, `,, %A_Space%%A_Tab%
	{
		If StrLen(A_LoopField) = 0
			continue
		IfInString,str,%A_LoopField%
			return
	}

	id := WinExist("A")
	if id = 0
		return
	if id = %CallerId%
		return

	CallerId := id
	gosub,<FocusTC>
	gosub,<Select_Mode_TC>
	return
}

; * 非TC窗口按下后激活TC窗口
; * TC窗口按下后复制当前选中文件返回原窗口后粘贴
<OpenTCDialog>:
{
	WinGetClass, class, A

	;在Total Commander按下快捷键时，激活调用窗体并执行粘贴操作
	if class = TTOTAL_CMD
	{
		gosub,<TC_Selected>
		return
	}

	if class <> TTOTAL_CMD
	{
		CallerId := WinExist("A")
		if CallerId = 0
			return

		gosub,<FocusTC>
		gosub,<Select_Mode_TC>
		return
	}

	return
}

<TC_PreSelected>:
	SendPos(2021)
	sleep,100 ; 此处用clipwait貌似会出错？

	;未多选
	IfNotInString,clipboard,`n
	{
		;当前复制项为文件夹时
		StringRight,str,clipboard,1
		IfInString,str,\
			{
				SendPos(2003)
				return
			}
	}

	;return 注意，此处无需return

<TC_Selected>:
{
	vim.mode("normal","TTOTAL_CMD")
	SendPos(2021)
	sleep,100

	;仅在多选时两侧增加双引号
	IfInString,clipboard,`n
	{
		files := ""
		Loop, parse, clipboard, `n, `r
			files .= """" A_LoopField  """ "
		clipboard := files
	}

	;未发现可激活的调用窗体时，最小化TC
	if CallerId = 0
	{
		Winminimize,AHK_CLASS TTOTAL_CMD
		sleep,500
		CallerId := WinExist("A")
		if CallerId = 0
			return
	}

	WinActivate,ahk_id %CallerId%
	WinWait,ahk_id %CallerId%
	send, ^v
	send, {Enter}
	return
}


OneStyle теперь использует woscript

OneStyle теперь использует woscript

actionShowMethodsList() {
	Global

	RunWait, system\OneScript\bin\woscript.exe scripts\\.os
	if (ErrorLevel = 0) {
		return
	}

	nStr := ErrorLevel
	SendInput ^%KeyG%
	WinWait,
	SendInput, %nStr%{ENTER}

	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowRegionsList() {
	Global

	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel = 0) {
		return
	}

	nStr := ErrorLevel
	SendInput, ^%KeyG%
	WinWait,
	SendInput, %nStr%{ENTER}

	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowExtFilesList() {
	Global

	; RunWait, wscript scripts\ExtFiles.js
	RunWait, system\OneScript\bin\woscript.exe scripts\ExtFiles.os,,

	NewText := getTextFromFile()
	If (NewText <> "") {
		ClipWait
		Sleep 1
		set_locale_ru()
		SendInput, !%KeyA%
		SendInput, {DOWN}{DOWN}{Enter}
		WinWait,
		SendInput, ^%KeyV%{Enter}
	}
}

actionShowScriptManager() {
	RunWait, system\OneScript\bin\woscript.exe scripts\.os,,
}

actionShowPrevWords() {
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os allwords,,
	pasteTextFromFile()
}

actionGotoMethodBegin() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput, {CtrlDown}%KeyG%{CtrlUp}
		WinWait,
		SendInput,%nStr%{ENTER}
	}
	SendInput, {home}
}

actionGotoMethodEnd() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
		SendInput ^{SC01A}
	}
	SendInput, {home}
}

actionShowRegExSearch() {
	Global

	RunWait, system\OneScript\bin\woscript.exe scripts\\.os RegExSearch,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		Sleep 1
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowRegExSearchLastResult() {
	Global

	SendInput, {home}
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowLastSelect() {
	Global

	SendInput, {home}
	; RunWait, wscript scripts.js null last
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionRunAuthorComments(data) {
	RunWait, system\OneScript\bin\oscript.exe scripts\.os %data%,,hide
}

actionRunLinksToItems() {
	putSelectionInFile()
	RunWait, wscript scripts\generator.js null simple-managment
	pasteTextFromFile()
}

actionShowCodeGenerator() {
	RunWait, wscript scripts\generator.js null generator
	pasteTextFromFile()
}

actionShowPreprocMethod() {
	RunWait, system\OneScript\bin\woscript.exe scripts\.os ,,
}

actionShowSimpleMetaSearch() {
	Global

	SendInput, ^+%KeyC%
	Sleep 10
	SendInput ^%KeyF%
}

actionShowIncomingObjectTypes() {
	Global
try {
	SendInput, %KeyContextMenu%
	SendInput, {UP}{UP}{UP}{ENTER}
	Sleep 100
	SendInput, {Enter}
	; Sleep 1
	SendInput, ^!%KeyO%
	ActivateWindowByTitle(" ")
	SendInput, ^%KeyA%
	; ClipWait
	Sleep 1
	putTextFromResultWindowInFile(0)
	module = tmp\module.txt

	RunWait, wscript scripts\scripts.js %module% gototype
	;RunWait, system\OneScript\bin\oscript.exe scripts\\.os
		; MsgBox %ErrorLevel%
		Sleep 1
	if (ErrorLevel > 0) {
		SendInput, ^{END}
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {UP}
		}
		SendInput, {ENTER}
	}
	SendInput, {HOME}

	}  Catch, er {
		MsgBox, er
    Reload
}
}

actionShowMetadataNavigator() {
	Global

	module = tmp\module.txt

	; clear old data
	FileDelete %module%
	FileAppend,, %module%
	RunWait, system\inputbox.exe %module%

	NewText := getTextFromFile()
	If (NewText <> "") {
		; go to service msgs
		SendInput, ^!%KeyO%
		SendInput, ^+%KeyC%
		ActivateWindowByTitle(" ")
		Sleep 1
		;
		ControlGetFocus, WinType

		If (WinType <> "V8Grid1") {
			;     -    ,  .
			SendInput, {Tab}
		}

		; show search dlg
		SendInput, ^%KeyF%
		WinWait,
		pasteTextFromFile()
		SendInput, {Enter}

		Sleep 2000

		ActivateWindowByTitle(" ")

		SendInput, ^%KeyA%
		ClipWait
		SendInput, {Left}{Enter}
		putTextFromResultWindowInFile(0)
		NewText := getTextFromFile()
		If (NewText <> "") {
			SendInput, ^{END}
			RunWait, wscript scripts\scripts.js %module% gotoobject
			NewText := getTextFromFile()
			If (NewText <> "") {
				SendInput, {Home}
				SendInput, ^%KeyF%
				SendInput +{ins}

				SendInput, !{Insert}
				ClipWait
				SendInput, {Enter}
				SendInput, {Enter}
			}
		}
	}
}

showMenu() {
	createMenuItems()
	Menu, Popup, Show
}

actionRun1Script() {
	module = tmp\module.os

	SendInput ^{SC01E}^{ins}{Left}
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, cmd "/K system\OneScript\bin\oscript.exe tmp/module.os"

}

actionGoToPrevContainedWord() {

	clipboard =

	SendInput ^+{left}^{ins}{right}
	RunWait, system\OneScript\bin\woscript.exe scripts\.os prev,,
}

actionGoToNextContainedWord() {

	clipboard =

	SendInput ^+{right}^{ins}{left}
	RunWait, system\OneScript\bin\woscript.exe scripts\.os next,,
}

actionShowMethodName() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,

}

actionGenerateServerMethodFromCurMethod() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide

}

actionOneStyleSelection() {
    ;    1, ..
    global
    SendInput, !+%KeyF%
	RunWait, system\OneScript\bin\woscript.exe scripts\OneStyle\Main.os,,Hide
}

actionWindowsManager() {
	detect_hidden = 0
	WinGet controls, ControlListHwnd
	static WINDOW_TEXT_SIZE := 32767 ; Defined in AutoHotkey source.
	VarSetCapacity(buf, WINDOW_TEXT_SIZE * (A_IsUnicode ? 2 : 1))
	text := ""
	Loop Parse, controls, `n
	{
		if !detect_hidden && !DllCall("IsWindowVisible", "ptr", A_LoopField)
			continue
		if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
			continue
		if (buf = "") {
			continue
		}
		text .= buf "`r`n"
	}

	module = tmp\module.txt
	FileDelete %module%
	FileAppend, %text%, %module%, UTF-8

	RunWait, system\SelectValueSharp.exe %module%
	FileRead, text, tmp\module.txt
	Loop Parse, controls, `n
	{
		if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
			continue
		 if (buf = text) {
		 	WinActivate, ahk_id %A_LoopField%
		 }
	}
}

actionResultSearchFilter() {

	;
	ActivateWindowByTitle(" ")

	clipboard =
	;
	SendInput, ^%KeyA%^{ins}
	;SendInput, ^{ins}
	ClipWait
	SendInput, {home}

	module = tmp\module.txt
	FileDelete %module%
	FileAppend, %Clipboard%, %module%, UTF-8

	SendInput, {home}
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		ActivateWindowByTitle(" ")
		Loop %UpCount%
		{
			SendInput, {down}
		}
		SendInput, {ENTER}
	}

}

actionContinueRow() {
	SendInput, {SHIFTDOWN}{up}{up}{up}{SHIFTUP}^{Insert}
	ClipWait
	SendInput, {Right}
	RunWait, system\OneScript\bin\woscript.exe scripts\.os
}

actionTextWinExt() {
	; MsgBox go
	RunWait, system\OneScript\bin\woscript.exe scripts\WinExtTest.os,,
}

actionShowMethodsList() {
	Global

	RunWait, system\OneScript\bin\woscript.exe scripts\\.os
	if (ErrorLevel = 0) {
		return
	}

	nStr := ErrorLevel
	SendInput ^%KeyG%
	WinWait,
	SendInput, %nStr%{ENTER}

	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowRegionsList() {
	Global

	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel = 0) {
		return
	}

	nStr := ErrorLevel
	SendInput, ^%KeyG%
	WinWait,
	SendInput, %nStr%{ENTER}

	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionShowExtFilesList() {
	Global

	; RunWait, wscript scripts\ExtFiles.js
	RunWait, system\OneScript\bin\woscript.exe scripts\ExtFiles.os,,

	NewText := getTextFromFile()
	If (NewText <> "") {
		ClipWait
		Sleep 1
		set_locale_ru()
		SendInput, !%KeyA%
		SendInput, {DOWN}{DOWN}{Enter}
		WinWait,
		SendInput, ^%KeyV%{Enter}
	}
}

actionShowScriptManager() {
	RunWait, system\OneScript\bin\woscript.exe scripts\.os,,
}

actionShowPrevWords() {
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os allwords,,
	pasteTextFromFile()
}

actionGotoMethodBegin() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput, {CtrlDown}%KeyG%{CtrlUp}
		WinWait,
		SendInput,%nStr%{ENTER}
	}
	SendInput, {home}
}

actionGotoMethodEnd() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
		SendInput ^{SC01A}
	}
	SendInput, {home}
}

actionShowRegExSearch() {
	Global

	RunWait, system\OneScript\bin\woscript.exe scripts\\.os RegExSearch,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		Sleep 1
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowRegExSearchLastResult() {
	Global

	SendInput, {home}
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
	}
	SendInput, {home}
}

actionShowLastSelect() {
	Global

	SendInput, {home}
	; RunWait, wscript scripts.js null last
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		nStr := ErrorLevel
		SendInput ^%KeyG%
		WinWait,
		SendInput %nStr%{ENTER}
	}
	SendInput, {home}
	SendInput, ^{NumpadAdd}
}

actionRunAuthorComments(data) {
	RunWait, system\OneScript\bin\oscript.exe scripts\.os %data%,,hide
}

actionRunLinksToItems() {
	putSelectionInFile()
	RunWait, wscript scripts\generator.js null simple-managment
	pasteTextFromFile()
}

actionShowCodeGenerator() {
	RunWait, wscript scripts\generator.js null generator
	pasteTextFromFile()
}

actionShowPreprocMethod() {
	RunWait, system\OneScript\bin\woscript.exe scripts\.os ,,
}

actionShowSimpleMetaSearch() {
	Global

	SendInput, ^+%KeyC%
	Sleep 10
	SendInput ^%KeyF%
}

actionShowIncomingObjectTypes() {
	Global
try {
	SendInput, %KeyContextMenu%
	SendInput, {UP}{UP}{UP}{ENTER}
	Sleep 100
	SendInput, {Enter}
	; Sleep 1
	SendInput, ^!%KeyO%
	ActivateWindowByTitle(" ")
	SendInput, ^%KeyA%
	; ClipWait
	Sleep 1
	putTextFromResultWindowInFile(0)
	module = tmp\module.txt

	RunWait, wscript scripts\scripts.js %module% gototype
	;RunWait, system\OneScript\bin\oscript.exe scripts\\.os
		; MsgBox %ErrorLevel%
		Sleep 1
	if (ErrorLevel > 0) {
		SendInput, ^{END}
		UpCount := ErrorLevel
		Loop %UpCount%
		{
			SendInput, {UP}
		}
		SendInput, {ENTER}
	}
	SendInput, {HOME}

	}  Catch, er {
		MsgBox, er
    Reload
}
}

actionShowMetadataNavigator() {
	Global

	module = tmp\module.txt

	; clear old data
	FileDelete %module%
	FileAppend,, %module%
	RunWait, system\inputbox.exe %module%

	NewText := getTextFromFile()
	If (NewText <> "") {
		; go to service msgs
		SendInput, ^!%KeyO%
		SendInput, ^+%KeyC%
		ActivateWindowByTitle(" ")
		Sleep 1
		;
		ControlGetFocus, WinType

		If (WinType <> "V8Grid1") {
			;     -    ,  .
			SendInput, {Tab}
		}

		; show search dlg
		SendInput, ^%KeyF%
		WinWait,
		pasteTextFromFile()
		SendInput, {Enter}

		Sleep 2000

		ActivateWindowByTitle(" ")

		SendInput, ^%KeyA%
		ClipWait
		SendInput, {Left}{Enter}
		putTextFromResultWindowInFile(0)
		NewText := getTextFromFile()
		If (NewText <> "") {
			SendInput, ^{END}
			RunWait, wscript scripts\scripts.js %module% gotoobject
			NewText := getTextFromFile()
			If (NewText <> "") {
				SendInput, {Home}
				SendInput, ^%KeyF%
				SendInput +{ins}

				SendInput, !{Insert}
				ClipWait
				SendInput, {Enter}
				SendInput, {Enter}
			}
		}
	}
}

showMenu() {
	createMenuItems()
	Menu, Popup, Show
}

actionRun1Script() {
	module = tmp\module.os

	SendInput ^{SC01E}^{ins}{Left}
	ClipWait

	FileDelete %module%

	FileAppend, %Clipboard%, %module%, UTF-8
	RunWait, cmd "/K system\OneScript\bin\oscript.exe tmp/module.os"

}

actionGoToPrevContainedWord() {

	clipboard =

	SendInput ^+{left}^{ins}{right}
	RunWait, system\OneScript\bin\woscript.exe scripts\.os prev,,
}

actionGoToNextContainedWord() {

	clipboard =

	SendInput ^+{right}^{ins}{left}
	RunWait, system\OneScript\bin\woscript.exe scripts\.os next,,
}

actionShowMethodName() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,

}

actionGenerateServerMethodFromCurMethod() {
	Global

	getTextUp()
	RunWait, system\OneScript\bin\oscript.exe scripts\\.os ,,Hide

}

actionOneStyleSelection() {
    ;    1, ..
    global
    SendInput, !+%KeyF%
	RunWait, system\OneScript\bin\oscript.exe scripts\OneStyle\Main.os,,Hide
}

actionWindowsManager() {
	detect_hidden = 0
	WinGet controls, ControlListHwnd
	static WINDOW_TEXT_SIZE := 32767 ; Defined in AutoHotkey source.
	VarSetCapacity(buf, WINDOW_TEXT_SIZE * (A_IsUnicode ? 2 : 1))
	text := ""
	Loop Parse, controls, `n
	{
		if !detect_hidden && !DllCall("IsWindowVisible", "ptr", A_LoopField)
			continue
		if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
			continue
		if (buf = "") {
			continue
		}
		text .= buf "`r`n"
	}

	module = tmp\module.txt
	FileDelete %module%
	FileAppend, %text%, %module%, UTF-8

	RunWait, system\SelectValueSharp.exe %module%
	FileRead, text, tmp\module.txt
	Loop Parse, controls, `n
	{
		if !DllCall("GetWindowText", "ptr", A_LoopField, "str", buf, "int", WINDOW_TEXT_SIZE)
			continue
		 if (buf = text) {
		 	WinActivate, ahk_id %A_LoopField%
		 }
	}
}

actionResultSearchFilter() {

	;
	ActivateWindowByTitle(" ")

	clipboard =
	;
	SendInput, ^%KeyA%^{ins}
	;SendInput, ^{ins}
	ClipWait
	SendInput, {home}

	module = tmp\module.txt
	FileDelete %module%
	FileAppend, %Clipboard%, %module%, UTF-8

	SendInput, {home}
	RunWait, system\OneScript\bin\woscript.exe scripts\\.os ,,Hide
	if (ErrorLevel > 0) {
		UpCount := ErrorLevel
		ActivateWindowByTitle(" ")
		Loop %UpCount%
		{
			SendInput, {down}
		}
		SendInput, {ENTER}
	}

}

actionContinueRow() {
	SendInput, {SHIFTDOWN}{up}{up}{up}{SHIFTUP}^{Insert}
	ClipWait
	SendInput, {Right}
	RunWait, system\OneScript\bin\woscript.exe scripts\.os
}

actionTextWinExt() {
	; MsgBox go
	RunWait, system\OneScript\bin\woscript.exe scripts\WinExtTest.os,,
}


Update firstauto.ahk

Update firstauto.ahk

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance
#InstallMouseHook
#MaxHotkeysPerInterval 300

SetNumlockState, AlwaysOn
SetCapsLockState, AlwaysOff
SetScrollLockState, AlwaysOff

;#Persistent
;SetTimer, CheckIdle, 60000    ; 60 sec / 1 min
;Return

;CheckIdle:
;If (A_TimeIdle > 60000)
;{
;    Send {RShift}
;}
;Return

; hotkey (Meh + Left Click) function (Focus on window under mouse - without sending keystroke)
^+!LButton::
  MouseGetPos,,, hwnd
  WinActivate, ahk_id %hwnd%
Return

; hotkey (SUPER2 + z) function (Refresh AHK script in workspace)
^+!z::
  Send ^s
  Run, "C:\Users\gordon\workspace\firstauto.ahk"
  Sleep 200
  Send {enter}
Return

; hotkey (SUPER2 + z) function (Refresh AHK script in workspace)
^+!x::
  Send ^s
  Run, "C:\Users\gordon\workspace\dictionary.ahk"
  Sleep 200
  Send {enter}
Return

; ############################# MAPPING REFERENCE #############################
; ^ = Control Key
; Tab = Tab
; CapsLock = CapsLock
; Enter = Enter
; Esc = Escape
; BS = Backspace
; Shift or + = Shift
; Alt or ! = Alt
; <# = Left Windows Key ># = Right Windows Key
; <^ or >^ = Left or Right Control
; <+ or >+ = Left or Right Shift
; <! or >! = Left or Right Alt
;
; Browser_Back = Back
; Browser_Forward = Forward
;
; Sending keystrokes:
;   Send {enter}   // will send the enter key
; #############################################################################

; ################################## EXAMPLES #################################
;
; 1. Run some arbitrary program
;   +<#o::Run "C:\Path\to\exe.exe"
;
; #############################################################################

; ################################ OPENING APPS ###############################

; hotkey (ALT + WIN + C) function (Open Calculator)
^#c::Run, calc.exe

; hotkey (WIN + V) function (Open VPN Apps)
#v::
    Run, "C:\Program Files (x86)\Symantec\VIP Access Client\VIPUIManager.exe"
    Sleep 150
    Run, "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
Return

; hotkey (CTRL + WIN + j) function (Open Git Bash)
^<#j:: Run, "C:\Program Files\Git\git-bash.exe"

; ########################### CHROME RELATED HOTKEYS ###########################

; hotkey (SHIFT + MOUSE_BACK) function (Go to previous tab)
+XButton1:: Send {LCtrl down}{LShift down}{Tab}{LCtrl up}{LShift up}
; hotkey (SHIFT + MOUSE_FORWARD) function (Go to next tab)
+XButton2::Send {LCtrl down}{Tab}{LCtrl up}

; Meh + V, copy highlighted text, open new chrome tab, and go.
^+!#z::
{
 Send, ^c
 Sleep 50
 Run, http://www.google.com/search?q=%clipboard%
 Return
 ; TODO - if context is a terminal, if so, use ctfrl + insert.
}

; #############################################################################

;CapsLock::LCtrl
;LCtrl::CapsLock

; ################### MOUSE SENSITIVITY SETTINGS #########################

; hotkey (CTRL + WIN + m) function(Set mouse speed to 10)
^<#m::
  ; 'UInt' is the type of the first parm
  ; The first param VALUE is "0x71", which is just hexidecimal for 113
  ; The next param is (UInt, 0), where '0' is required for "0x71"
  ; The pvParam parameter is an integer between 1 (slowest) and 20 (fastest).
  DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 10, UInt, 0)
Return

; hotkey (CTRL + WIN + n) function(Set mouse speed to 4)
^<#n::
  DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 4, UInt, 0)
Return

;##########################################################################

; ################### AUTO HOT KEY IDEAS #################
;
; Moving the Mouse

; hotkey (CTRL + SHIFT + q) function(Move the mouse 2560 pixels over to the right)
^+!#F14::MouseMove, 2560, 0, 2, R

; hotkey (CTRL + SHIFT + q) function(Move the mouse 2560 pixels over to the right)
^+!#F13::MouseMove, -2560, 0, 2, R

^+!#F15::SendRaw, %Clipboard%
^+!F12::SendRaw, %Clipboard%

; Make F9 the "SUPER" key
; If you need F9, just do control + F9
; Ideally, this would actually be something like F18 - a button that never gets used.
; I believe this can be done on the new kinesis advantage versions (2015)
; ^F9:: send {F9}

; Open current page in inCognito mode
^+!#b::
  send ^l
  sleep 100
  send ^c
  sleep 100
  send ^+{n}
  sleep 300
  send ^l
  sleep 100
  send ^v
  send {Enter}
return

^+!#F11::WinMove, A,, 0, 0,1430,1280
^+!#F8::WinMove, A,, 0, 0,1300,700
^+!#F9::WinMove, A,, 0, 1280,1430,1280

; --IDEAS. QMK included--

;Custom window management. 1/3rd of size, etc.
;all caps and _ mode. for NT_SOME_TABLE

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance

;hotkey (CTRL + WIN + z) function (Refresh AHK script in workspace)
^<#z::
   Run, "C:\Users\gordon\workspace\firstauto.ahk"
   Sleep 50
   Send {enter}
Return
;
; ############################# MAPPING REFERENCE #############################
; ^ = Control Key
; Tab = Tab
; CapsLock = CapsLock
; Enter = Enter
; Esc = Escape
; BS = Backspace
; Shift or + = Shift
; Alt or ! = Alt
; <# = Left Windows Key ># = Right Windows Key
; <^ or >^ = Left or Right Control
; <+ or >+ = Left or Right Shift
; <! or >! = Left or Right Alt
;
; Browser_Back = Back
; Browser_Forward = Forward
;
; Sending keystrokes:
;   Send {enter}   // will send the enter key
; #############################################################################

; ################################## EXAMPLES #################################
;
; 1. Run some arbitrary program
;   +<#o::Run "C:\Path\to\exe.exe"
;
; #############################################################################

; ################################ OPENING APPS ###############################

;hotkey (ALT + WIN + C) function (Open Calculator)
!<#c::Run calc.exe

;hotkey (WIN + V) function (Open VPN Apps)
<#v::
    Run, "C:\Program Files (x86)\Symantec\VIP Access Client\VIPUIManager.exe"
    Sleep 150
    Run, "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"
Return

;hotkey (CTRL + WIN + j) function (Open Git Bash)
^<#j:: Run, "C:\Program Files\Git\git-bash.exe"

; #############################################################################

; ########################### CHROME RELATED HOTKEYS ###########################

; Cannot properly map anything to "^Tab". For some reason, it always adds a shift
+XButton1:: Send {LCtrl down}{LShift down}{Tab}{LCtrl up}{LShift up}
+XButton2::Send {LCtrl down}{Tab}{LCtrl up}

; Open new tab in chrome and paste link from clipboard
^<#x::
  Send ^C
  Sleep 50
  Send #2
  Sleep 50
  Send ^t
  sleep 50
  Send ^l
  sleep 50
  Send ^v
  sleep 50
  Send {Enter}
Return

;; Jenkins Launch Arbitrary Shell Command
;^Xbutton2::
;  send {^l}
;  SendRaw {https://cme-pmob.jenkins.release.in.here.com/job/GDF_EXTRACTION/job/Run%20Arbitrary%20Shell%20Command/build?delay=0sec}
;  send {enter}
;Return

; #############################################################################

;############################### TERMINAL HOTKEYS #############################

; ################### Code Generators ####################
::listgen::val sampleList = Vector("This","is","a","vector","of","strings")
::forcomp::
    Send val sampleCollection = List("sample","hi")`n
    Send val someVar = for {{}`n
    Send     string <- sampleCollection`n
    Send     if string == "hi"{Down}{Space}yield string
Return

::shebang::{#}{!}/bin/bash
::scalalsgrep::val javaProcs = ("ls" {#}| "grep sbt").lineStream.toList
::gitger::git push origin HEAD:refs/for/master

; Create case match template
;::casematches::
;(
;def listAnalysis(list: List[Any]) = list match {
;  case Nil => "empty"
;  case 'a' :: tail => "starting by 'a'"
;  case (head:Int) :: _ if head > 3 => "starting by an int greater than 3"
;  case (head:Int) :: _ => "starting by an int"
;  case _ => "whatever"
;}
;)

::Teusday::Tuesday
::btw::By the way

^+d::
    Send, logout
    Send {Enter}
Return

;##########################################################################

; ################### MOUSE SENSITIVITY SETTINGS #########################

^<#m::
  ; 'UInt' is the type of the first parm
  ; The first param VALUE is "0x71", which is just hexidecimal for 113
  ; The next param is (UInt, 0), where '0' is required for "0x71"
  ; The pvParam parameter is an integer between 1 (slowest) and 20 (fastest).
  DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 10, UInt, 0)
Return

; When Roccat is plugged in
^<#n::
  DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 4, UInt, 0)
Return
;##########################################################################

; ################### AUTO HOT KEY IDEAS #################
;
; Remap ^] to +tab in gmail so I can just use +tab to indent a list
; Remap "casematch + tab" to generate a case match template
;

; Type the date using "]d"
:*:]d::  ; This hotstring replaces "]d" with the current date and time via the commands below.
FormatTime, CurrentDateTime,, M/d/yyyy h:mm tt  ; It will look like 9/1/2005 3:53 PM
SendInput %CurrentDateTime%
return

; ########################### CAPSLOCK REMAPPING ###########################
; >^ is right control
; Remap Capslock because you never use it
; Now Capslock can be used as control
; >^Capslock::Capslock
; Capslock::Ctrl
; ##########################################################################


AutoHotkey.ahk, from darwin11

AutoHotkey.ahk, from darwin11

; Tips {{{
; #: win
; !: alt
; ^: ctrl
; +: shift
; &: and
; <: only left, >: only right
; *: wildecard
; ~: pass through
; }}}

; Auto-execute section {{{
; Auto execute section is the region before any return/hotkey

; Windows size
TMargin=5
BMargin=5
LMargin=5
RMargin=155 ; sidebar = 150px
MinSize=0.7

; For Terminal/Vim
GroupAdd Terminal, ahk_class PuTTY
GroupAdd Terminal, ahk_class mintty ; cygwin
GroupAdd Terminal, ahk_class Vim

#Include  %A_ScriptDir%\vim.ahk

Return
; }}}

; Basic Settings, HotKeys, Functions {{{
; Settings

#UseHook On ; Make it a bit slow, but can avoid infinitude loop
            ; Same as "$" for each hotkey
#InstallKeybdHook ; For checking key history
                  ; Use ~500kB memory?

#HotkeyInterval 2000 ; Hotkey inteval (default 2000 milliseconds).
#MaxHotkeysPerInterval 70 ; Max hotkeys perinterval (default 50).

; For HHK
;vkFFsc079::RAlt
;vkFFsc07b::LAlt
vkFFsc079::RCtrl
vkFFsc07b::LCtrl

;; Ref for IME: http://www6.atwiki.jp/eamat/pages/17.html
;; Get IME Status. 0: Off, 1: On
;IME_GET(WinTitle="A")  {
;  ControlGet,hwnd,HWND,,,%WinTitle%
;  if (WinActive(WinTitle)) {
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI,  0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
;        ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
;  }
;
;  Return DllCall("SendMessage"
;      , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hwnd)
;      , UInt, 0x0283  ;Message : WM_IME_CONTROL
;      ,  Int, 0x0005  ;wParam  : IMC_GETOPENSTATUS
;      ,  Int, 0)      ;lParam  : 0
;}
;; Get input status. 1: Converting, 2: Have converting window, 0: Others
;IME_GetConverting(WinTitle="A",ConvCls="",CandCls="") {
;  ; Input windows, candidate windows (Add new IME with "|")
;  ConvCls .= (ConvCls ? "|" : "")                 ;--- Input Window ---
;    .  "ATOK\d+CompStr"                           ; ATOK
;    .  "|imejpstcnv\d+"                           ; MS-IME
;    .  "|WXGIMEConv"                              ; WXG
;    .  "|SKKIME\d+\.*\d+UCompStr"                 ; SKKIME Unicode
;    .  "|MSCTFIME Composition"                    ; Google IME
;  CandCls .= (CandCls ? "|" : "")                 ;--- Candidate Window ---
;    .  "ATOK\d+Cand"                              ; ATOK
;    .  "|imejpstCandList\d+|imejpstcand\d+"       ; MS-IME 2002(8.1)XP
;    .  "|mscandui\d+\.candidate"                  ; MS Office IME-2007
;    .  "|WXGIMECand"                              ; WXG
;    .  "|SKKIME\d+\.*\d+UCand"                    ; SKKIME Unicode
; CandGCls := "GoogleJapaneseInputCandidateWindow" ; Google IME
;
;  ControlGet,hwnd,HWND,,,%WinTitle%
;  if (WinActive(WinTitle)) {
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI,  0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
;      ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
;  }
;
;  WinGet, pid, PID,% "ahk_id " hwnd
;  tmm:=A_TitleMatchMode
;  SetTitleMatchMode, RegEx
;  ret := WinExist("ahk_class " . CandCls . " ahk_pid " pid) ? 2
;      :  WinExist("ahk_class " . CandGCls                 ) ? 2
;      :  WinExist("ahk_class " . ConvCls . " ahk_pid " pid) ? 1
;      :  0
;  SetTitleMatchMode, %tmm%
;  Return ret
;}
;; Set IME, SetSts=0: Off, 1: On, return 0 for success, others for non-success
;IME_SET(SetSts=0, WinTitle="A")    {
;  ControlGet,hwnd,HWND,,,%WinTitle%
;  if(WinActive(WinTitle)){
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI,  0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
;        ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
;  }
;
;  Return DllCall("SendMessage"
;    , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hwnd)
;    , UInt, 0x0283  ;Message : WM_IME_CONTROL
;    ,  Int, 0x006   ;wParam  : IMC_SETOPENSTATUS
;    ,  Int, SetSts) ;lParam  : 0 or 1
;}

; }}}

; Terminal/Vim {{{
; On Terminal/Vim
#IfWInActive, ahk_group Terminal
Esc:: ; Just send Esc at converting.
  if (IME_GET(A)) {
    if (IME_GetConverting(A)) {
      Send,{Esc}
    } else {
      IME_SET()
    }
  } else {
    Send,{Esc}
  }
  Return
^[:: ; Go to Normal mode (for vim) with IME off even at converting.
  if (IME_GET(A)) {
    Send,{Esc}
    Sleep 1 ; wait 1 ms (Need to stop converting)
    IME_SET()
    Send,{Esc}
  } else {
    Send,{Esc}
  }
  Return
#IfWInActive

; Other than Terminal/Vim
#IfWInNotActive, ahk_group Terminal
^[::Send,{Esc}             ; Always C-[ to ESC, like vim
#IfWInNotActive
; }}} Terminal/Vim

; Power Point {{{
#IfWInActive, ahk_class PP12FrameClass
; Select one character
^Space::Send,{Right}+{Left}

; Subscript/Superscript
^=::Send,^tb{Enter}
^+=::Send,^tp{Enter}
; For JP keyboards
;^-::Send,^tb{Enter}
;^+-::Send,^tp{Enter}

; Fonts
^+s::Send,^tfsymbol{Enter}
^+a::Send,^tfarial{Enter}
^+h::Send,^tfhelvetica{Enter}
#IfWInActive
; }}} Power Point

; Word {{{
#IfWInActive, ahk_class OpusApp
^Space::Send,{Right}+{Left}
^=::Send,^tb{Enter}
^+=::Send,^tp{Enter}
; for JP keyboards
;^-::Send,^tb{Enter}
;^+-::Send,^tp{Enter}
#IfWInActive
; }}} Word

; Explorer {{{
#IfWInActive, ahk_class CabinetWClas
; Next/Previous page
^i::Send,!{Right}
^o::Send,!{Left}
#IfWInActive
; }}} Explorer

; CLCL {{{
;#IfWInActive, ahk_class CLCLMain
#IfWInActive, CLCL
j::
  Msgbox, clcl_down
  Send,{Down}
  Return
k::Send,{Up}
#IfWInActive
; }}} Explorer

; Global Settings {{{
#if
; Basic Settings {{{

; Suspend
;Esc & Tab::
;  Suspend, Toggle
;  Return
; For Alt-Ctrl Swap (swapped by KeySwap)
LCtrl & Tab::AltTab
Alt & Tab::
  if GetKeyState("Shift","P") {
    Send,^+{Tab} ; dosen't work ()
  }else{
    Send,^{Tab}
  }
  Return

;!m::Send,^m
;^m::Send,!m
^m::Send,!m
Ctrl & Left::Send,!{Left}
Ctrl & Right::Send,!{Right}

; Other basic settings
!Space::Send,{vkF3sc029}   ; IME by A-Space
^Space::Send,{vkF3sc029}   ; IME by C-Space
; {vkF3sc029}              ; 変換
; {vk1Dsc07B}              ; 無変換
^h::Send,{BS}              ; Always BS with C-h
!a::Send,^{Space}n        ; Minimize window
!4::Send,!{F4}             ; Close window
^4::Send,!{F4}             ; Close window
!d::Send,{Del}             ; Always Delete with A-d
;^o::Send,!{Left}           ; Go to previous page
;^i::Send,!{Right}          ; Go to nexe page
^Space::!`                 ; IME

; For HHK
; ESC to ` like normal keyboard (ESC is placed on the left of 1 in HHK)
!1::!`                ; IME
; }}} Basic Settings

; Cursor, Mouse, Window move/size {{{
; Cursor {{{
!^h::Send,{Left}
!^j::Send,{Down}
!^k::Send,{Up}
!^l::Send,{Right}
; }}} Cursor

; Mouse {{{
; Mouse Move
!^y::MouseMove, -10, 0, 0, R
!^u::MouseMove, 0, 10, 0, R
!^i::MouseMove, 0, -10, 0, R
!^o::MouseMove, 10, 0, 0, R

; Click
!^n::MouseClick, Left
!^p::MouseClick, Right
; Right click on current window
!v::
  MouseMove, 50, 50, 0
  MouseClick, Right
  Return

; Mouse wheel
!^m::MouseClick, WheelDown,,,  2
!^,::MouseClick, WheelUp,,,  2
; }}} Mouse

; Window move {{{
^+y::
  WinGetPos, X, Y, , , A ;A for Active Window
  ;Msgbox, Pos At %X% %Y%
  WinMove, A, ,X-20, Y,
  ;Msgbox, Moved At %X%-20 %Y%
  Return ; Necessary for mapping which has at least 2 commands
^+u::
  WinGetPos, X, Y, , , A
  WinMove, A, ,X, Y+20
  Return
^+i::
  WinGetPos, X, Y, , , A
  WinMove, A, ,X, Y-20
  Return
^+o::
  WinGetPos, X, Y, , , A
  WinMove, A, ,X+20, Y
  Return
; }}} Window move

; Window size {{{
^!Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, ,MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , MWABottom-MWATop-TMargin-BMargin
  Return
^!+Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, ,MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*MinSize
    , (MWABottom-MWATop-TMargin-BMargin)*MinSize
  Return
; }}} Window size
; }}} Cursor, Mouse, Window move
; }}} Global Settings

; Tips {{{
; #: win
; !: alt
; ^: ctrl
; +: shift
; &: and
; <: only left, >: only right
; *: wildecard
; ~: pass through
; }}}

; Auto-execute section {{{
; Auto execute section is the region before any return/hotkey

; Windows size
TMargin=5
BMargin=5
LMargin=5
RMargin=155 ; sidebar = 150px
MinSize=0.7

; For Terminal/Vim
GroupAdd Terminal, ahk_class PuTTY
GroupAdd Terminal, ahk_class mintty ; cygwin
GroupAdd Terminal, ahk_class Vim

#Include  %A_ScriptDir%\vim.ahk

Return
; }}}

; Basic Settings, HotKeys, Functions {{{
; Settings

#UseHook On ; Make it a bit slow, but can avoid infinitude loop
            ; Same as "$" for each hotkey
#InstallKeybdHook ; For checking key history
                  ; Use ~500kB memory?

#HotkeyInterval 2000 ; Hotkey inteval (default 2000 milliseconds).
#MaxHotkeysPerInterval 70 ; Max hotkeys perinterval (default 50).

; For HHK
;vkFFsc079::RAlt
;vkFFsc07b::LAlt
vkFFsc079::RCtrl
vkFFsc07b::LCtrl

;; Ref for IME: http://www6.atwiki.jp/eamat/pages/17.html
;; Get IME Status. 0: Off, 1: On
;IME_GET(WinTitle="A")  {
;  ControlGet,hwnd,HWND,,,%WinTitle%
;  if (WinActive(WinTitle)) {
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI,  0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
;        ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
;  }
;
;  Return DllCall("SendMessage"
;      , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hwnd)
;      , UInt, 0x0283  ;Message : WM_IME_CONTROL
;      ,  Int, 0x0005  ;wParam  : IMC_GETOPENSTATUS
;      ,  Int, 0)      ;lParam  : 0
;}
;; Get input status. 1: Converting, 2: Have converting window, 0: Others
;IME_GetConverting(WinTitle="A",ConvCls="",CandCls="") {
;  ; Input windows, candidate windows (Add new IME with "|")
;  ConvCls .= (ConvCls ? "|" : "")                 ;--- Input Window ---
;    .  "ATOK\d+CompStr"                           ; ATOK
;    .  "|imejpstcnv\d+"                           ; MS-IME
;    .  "|WXGIMEConv"                              ; WXG
;    .  "|SKKIME\d+\.*\d+UCompStr"                 ; SKKIME Unicode
;    .  "|MSCTFIME Composition"                    ; Google IME
;  CandCls .= (CandCls ? "|" : "")                 ;--- Candidate Window ---
;    .  "ATOK\d+Cand"                              ; ATOK
;    .  "|imejpstCandList\d+|imejpstcand\d+"       ; MS-IME 2002(8.1)XP
;    .  "|mscandui\d+\.candidate"                  ; MS Office IME-2007
;    .  "|WXGIMECand"                              ; WXG
;    .  "|SKKIME\d+\.*\d+UCand"                    ; SKKIME Unicode
; CandGCls := "GoogleJapaneseInputCandidateWindow" ; Google IME
;
;  ControlGet,hwnd,HWND,,,%WinTitle%
;  if (WinActive(WinTitle)) {
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI,  0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
;      ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
;  }
;
;  WinGet, pid, PID,% "ahk_id " hwnd
;  tmm:=A_TitleMatchMode
;  SetTitleMatchMode, RegEx
;  ret := WinExist("ahk_class " . CandCls . " ahk_pid " pid) ? 2
;      :  WinExist("ahk_class " . CandGCls                 ) ? 2
;      :  WinExist("ahk_class " . ConvCls . " ahk_pid " pid) ? 1
;      :  0
;  SetTitleMatchMode, %tmm%
;  Return ret
;}
;; Set IME, SetSts=0: Off, 1: On, return 0 for success, others for non-success
;IME_SET(SetSts=0, WinTitle="A")    {
;  ControlGet,hwnd,HWND,,,%WinTitle%
;  if(WinActive(WinTitle)){
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI,  0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint,&stGTI)
;        ? NumGet(stGTI,8+PtrSize,"UInt") : hwnd
;  }
;
;  Return DllCall("SendMessage"
;    , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hwnd)
;    , UInt, 0x0283  ;Message : WM_IME_CONTROL
;    ,  Int, 0x006   ;wParam  : IMC_SETOPENSTATUS
;    ,  Int, SetSts) ;lParam  : 0 or 1
;}

; }}}

; Terminal/Vim {{{
; On Terminal/Vim
#IfWInActive, ahk_group Terminal
Esc:: ; Just send Esc at converting.
  if (IME_GET(A)) {
    if (IME_GetConverting(A)) {
      Send,{Esc}
    } else {
      IME_SET()
    }
  } else {
    Send,{Esc}
  }
  Return
^[:: ; Go to Normal mode (for vim) with IME off even at converting.
  if (IME_GET(A)) {
    Send,{Esc}
    Sleep 1 ; wait 1 ms (Need to stop converting)
    IME_SET()
    Send,{Esc}
  } else {
    Send,{Esc}
  }
  Return
#IfWInActive

; Other than Terminal/Vim
#IfWInNotActive, ahk_group Terminal
^[::Send,{Esc}             ; Always C-[ to ESC, like vim
#IfWInNotActive
; }}} Terminal/Vim

; Power Point {{{
#IfWInActive, ahk_class PP12FrameClass
^Space::Send,{Right}+{Left}
^=::Send,^tb{Enter}
^+=::Send,^tp{Enter}
; for JP keyboards
;^-::Send,^tb{Enter}
;^+-::Send,^tp{Enter}
^+s::Send,^tfsymbol{Enter}
^+a::Send,^tfarialEnter
^+h::Send,^tfhelveticaEnter
#IfWInActive
; }}} Power Point

; Word {{{
#IfWInActive, ahk_class OpusApp
^Space::Send,{Right}+{Left}
^=::Send,^tb{Enter}
^+=::Send,^tp{Enter}
; for JP keyboards
;^-::Send,^tb{Enter}
;^+-::Send,^tp{Enter}
#IfWInActive
; }}} Word

; Explorer {{{
#IfWInActive, ahk_class CabinetWClas
^o::Send,!{Left}
^i::Send,!{Right}
#IfWInActive
; }}} Explorer

; Global Settings {{{
#if
; Basic Settings {{{

; Suspend
;Esc & Tab::
;  Suspend, Toggle
;  Return
; For Alt-Ctrl Swap (swapped by KeySwap)
LCtrl & Tab::AltTab
Alt & Tab::
  if GetKeyState("Shift","P") {
    msgbox, "A-S-Tab"
    ;Send,^+{Tab} ; dosen't work ()
  }else{
    Send,^{Tab}
  }
  Return

;!m::Send,^m
;^m::Send,!m
^m::Send,!m
Ctrl & Left::Send,!{Left}
Ctrl & Right::Send,!{Right}

; Other basic settings
!Space::Send,{vkF3sc029}   ; IME by A-Space
^Space::Send,{vkF3sc029}   ; IME by C-Space
; {vkF3sc029}              ; 変換
; {vk1Dsc07B}              ; 無変換
^h::Send,{BS}              ; Always BS with C-h
!a::Send,^{Space}n        ; Minimize window
!4::Send,!{F4}             ; Close window
^4::Send,!{F4}             ; Close window
!d::Send,{Del}             ; Always Delete with A-d
;^o::Send,!{Left}           ; Go to previous page
;^i::Send,!{Right}          ; Go to nexe page
^Space::!`                 ; IME

; For HHK
; ESC to ` like normal keyboard (ESC is placed on the left of 1 in HHK)
!1::!`                ; IME
; }}} Basic Settings

; Cursor, Mouse, Window move/size {{{
; Cursor {{{
!^h::Send,{Left}
!^j::Send,{Down}
!^k::Send,{Up}
!^l::Send,{Right}
; }}} Cursor

; Mouse {{{
; Mouse Move
!^y::MouseMove, -10, 0, 0, R
!^u::MouseMove, 0, 10, 0, R
!^i::MouseMove, 0, -10, 0, R
!^o::MouseMove, 10, 0, 0, R

; Click
!^n::MouseClick, Left
!^p::MouseClick, Right
; Right click on current window
!v::
  ;MouseMove, 50, 50, 0
  MouseClick, Right
  Return

; Mouse wheel
!^m::MouseClick, WheelDown,,,  2
!^,::MouseClick, WheelUp,,,  2
; }}} Mouse

; Window move {{{
^+y::
  WinGetPos, X, Y, , , A ;A for Active Window
  ;Msgbox, Pos At %X% %Y%
  WinMove, A, ,X-20, Y,
  ;Msgbox, Moved At %X%-20 %Y%
  Return ; Necessary for mapping which has at least 2 commands
^+u::
  WinGetPos, X, Y, , , A
  WinMove, A, ,X, Y+20
  Return
^+i::
  WinGetPos, X, Y, , , A
  WinMove, A, ,X, Y-20
  Return
^+o::
  WinGetPos, X, Y, , , A
  WinMove, A, ,X+20, Y
  Return
; }}} Window move

; Window size {{{
^!Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, ,MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , MWABottom-MWATop-TMargin-BMargin
  Return
^!+Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, ,MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*MinSize
    , (MWABottom-MWATop-TMargin-BMargin)*MinSize
  Return
; }}} Window size
; }}} Cursor, Mouse, Window move
; }}} Global Settings


(commit or discard the untracked or modified content in submodules)    AutoHotkey.ahk    submodules/vim_ahk (untracked content), from darwin16

; Tips {{{
; #: win
; !: alt
; ^: ctrl
; +: shift
; &: and
; <: only left, >: only right
; *: wildecard
; ~: pass through
; }}}

; Auto execute section is the region before any return/hotkey {{{
; Windows size
TMargin := 5
BMargin := 5
LMargin := 5
RMargin := 5 ; sidebar = 150px
MinSize := 0.7

; For Terminal/Vim
GroupAdd Terminal, ahk_class PuTTY
GroupAdd Terminal, ahk_class mintty ; cygwin
GroupAdd Terminal, ahk_class TMobaXtermForm
GroupAdd Terminal, ahk_class TFormDetachedTab
GroupAdd Terminal, ahk_class ConsoleWindowClass
GroupAdd Terminal, ahk_exe powershell.exe
GroupAdd Terminal, ahk_exe vim.exe
GroupAdd TerminalVim, ahk_group Terminal
GroupAdd TerminalVim, ahk_class Vim

VimIcon := 1
#Include %A_LineFile%\..\submodules\vim_ahk\vim.ahk
#Include %A_LineFile%\..\AutoCorrect.ahk

Return
; }}}

;; Basic Settings, HotKeys, Functions {{{
; Settings

#UseHook On ; Make it a bit slow, but can avoid infinitude loop
            ; Same as "$" for each hotkey
#InstallKeybdHook ; For checking key history
                  ; Use ~500kB memory?

#HotkeyInterval 1000 ; Hotkey inteval (default 2000 milliseconds).
#MaxHotkeysPerInterval 100 ; Max hotkeys perinterval (default 50).

; For HHKB
vkFFsc079::RCtrl
vkFFsc07b::LCtrl
; }}}

; Terminal/Vim {{{
; ESC + IME
#IfWInActive, ahk_group TerminalVim
Esc:: ; Just send Esc at converting.
  if(VIM_IME_GET(A)){
    if(VIM_IME_GetConverting(A)){
      Send, {Esc}
    }else{
      VIM_IME_SET()
    }
  }else{
    Send, {Esc}
  }
Return

^[:: ; Go to Normal mode (for vim) with IME off even at converting.
  if(VIM_IME_GetConverting(A)){
    Send, {Esc}
    Sleep 1 ; wait 1 ms (Need to stop converting)
  }
  if(VIM_IME_GET(A)){
    VIM_IME_SET()
    Send, {Esc}
  }else{
    Send, {Esc}
  }
Return

^m::Send, ^m ; Use Ctrl-m as is

; Paste
#IfWInActive, ahk_group Terminal
!v::
  ;StringSplit, strout, clipboard, `n
  ;If(strout0>1 or InStr(clipboard, "sudo")>0){
  ;  MsgBox, 308, Clipboard, %clipboard%`n`n Do you want to paste?
  ;  IfMsgBox, No
  ;  {
  ;    Return
  ;  }
  ;}
  ;SendInput %clipboard%
  ;Return
  Sleep,200
  MouseClick, Right, 50, 50, 1
Return

#IfWInActive, ahk_class Vim
!v::Send, {Alt}ep

; Command Promp, PowerShell, Bash on Ubuntu on Windows {{{
#IfWinActive ahk_class ConsoleWindowClass
^v::Send, ^q
!v::
  SendInput %clipboard%
Return
; }}} Command Prompt

; Other than Terminal/Vim
#IfWInNotActive, ahk_group TerminalVim
^[::Send, {Esc}             ; Always C-[ to ESC, like vim
^d::Send, {Del}             ; Always Delete with C-d
; }}} Terminal/Vim

; Power Point {{{
#IfWInActive, ahk_class PP12FrameClass
; Subscript/Superscript
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; For JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}

; Fonts
^!+s::Send, ^tfsymbol{Enter}
^!+a::Send, ^tfarial{Enter}
^!+h::Send, ^tfhelvetica{Enter}
; }}} Power Point

; Word {{{
#IfWInActive, ahk_class OpusApp
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; for JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}
; }}} Word

; Explorer {{{
#IfWInActive, ahk_class CabinetWClass
; Next/Previous page
^i::Send, !{Right}
^o::Send, !{Left}
; }}} Explorer

; CLCL {{{
;#IfWInActive, ahk_class CLCLMain
#IfWInActive, CLCL ; both window/title do not working...
j::
  Msgbox, clcl_down
  Send, {Down}
Return

K::Send, {Up}
; }}} Explorer

; Everthing {{{
#IfWInActive, ahk_class EVERYTHING
Return::
  Send, {Enter}
  Sleep, 200
  IfWinActive, ahk_class EVERYTHING
  {
    Send,{Enter}
    Sleep, 500
  }
  WinActivate, ahk_class EVERYTHING
  Sleep, 200
  Send, {Esc}
Return
; }}} Everything

; Global Settings {{{
#if
; Basic Settings {{{

; Suspend
;Esc & Tab::
;  Suspend, Toggle
;  Return
; For Alt-Ctrl Swap (swapped by KeySwap)
<^Tab::AltTab
;<+<^Tab::ShiftAltTab ; can not assigned...
;LCtrl & Tab::
;  if GetKeyState("Shift","P"){
;    Send, {ShiftAltTab}
;  }else{
;    Send, {AltTab}
;  }
;Return
;Alt & Tab::
;  if GetKeyState("Shift","P"){
;    Send, ^+{taB}
;  }else{
;    Send, ^{Tab}
;  }
;Return
!Tab::Send, ^{Tab}
!+Tab::Send, ^+{Tab}

;!m::Send, ^m
;^m::Send, !m
;>^m::Send, !m
;Ctrl & Left::Send, !{Left}
;Ctrl & Right::Send, !{Right}

; Virtual desktop
^!+h::Send, #^{Left}
^!+l::Send, #^{Right}

; Cortana
!^f::Send, #s

; CLCL
#c::Send, !c

; Other basic settings
!Space::Send, {vkF3sc029} ; IME by A-Space
^Space::Send, {vkF3sc029} ; IME by C-Space
;{vkF3sc029}               ; 変換
;{vk1Dsc07B}               ; 無変換
!^a::Send, !{Space}n       ; Minimize window
!4::Send, !{F4}           ; Close window
^4::Send, !{F4}           ; Close window
!d::Send, {Del}           ; Always Delete with A-d
;^o::Send,!{Left}          ; Go to previous page
;^i::Send,!{Right}         ; Go to nexe page
^Space::!`                ; IME

^h::Send, {BS}            ; Always BS with C-h
;^h::
;  While GetKeyState("h","p"){
;    Send {BS}
;    TrayTip,Start:,%n%,10,,
;    Sleep 50
;  }
;  return

;^j::Send,{Enter}      ; C-j to Enter

; For HHKB
; ESC to ` like normal keyboard (ESC is placed on the left of 1 in HHKB)
!1::!`                ; IME
; }}} Basic Settings

; Cursor, Mouse, Window move/size {{{
; Cursor {{{
!^h::Send, {Left}
!^j::Send, {Down}
!^k::Send, {Up}
!^l::Send, {Right}
; }}} Cursor

; Mouse {{{
; Mouse Move
^+h::MouseMove, -10, 0, 0, R
^+j::MouseMove, 0, 10, 0, R
^+k::MouseMove, 0, -10, 0, R
^+l::MouseMove, 10, 0, 0, R

; Click
^+n::MouseClick, Left
^+p::MouseClick, Right
; Right click on current window

; Mouse wheel
!^m::MouseClick, WheelDown, , , 2
!^,::MouseClick, WheelUp, , , 2
; }}} Mouse

; Window move {{{

; Move a little
^+y::
  WinGetPos, X, Y, , , A ;A for Active Window
  WinMove, A, ,X-20, Y,
Return

^+u::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y+20
Return

^+i::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y-20
Return

^+o::
  WinGetPos, X, Y, , , A
  WinMove, A, , X+20, Y
Return

; Move to a different screen
!^+y:: Send, #+{Left}
!^+u:: Send, #+{Down}
!^+i:: Send, #+{Up}
!^+o:: Send, #+{Right}

; }}} Window move

; Window size {{{

; Almost full
^!Enter::
!+Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , MWABottom-MWATop-TMargin-BMargin
Return

; Minsize
^!+Enter::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*Minsize
    , (MWABottom-MWATop-TMargin-BMargin)*Minsize
Return

; Half size
!+h::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

!+j::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin
    , MWATop+(MWABottom-MWATop)*0.5
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+k::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+l::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+(MWARight-MWALeft)*0.5
    , MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

; Resize
!+y::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W-20, H
Return

!+u::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H+20
Return

!+i::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H-20
Return

!+o::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W+20, H
Return

; }}} Window size
; }}} Cursor, Mouse, Window move
; }}} Global Settings

; Tips {{{
; #: win
; !: alt
; ^: ctrl
; +: shift
; &: and
; <: only left, >: only right
; *: wildecard
; ~: pass through
; }}}

; Auto-execute section {{{
; Auto execute section is the region before any return/hotkey

; Windows size
TMargin := 5
BMargin := 5
LMargin := 5
RMargin := 5 ; sidebar = 150px
MinSize := 0.7

; For Terminal/Vim
GroupAdd Terminal, ahk_class PuTTY
GroupAdd Terminal, ahk_class mintty ; cygwin
GroupAdd Terminal, ahk_class TMobaXtermForm
GroupAdd Terminal, ahk_class TFormDetachedTab
GroupAdd Terminal, ahk_class ConsoleWindowClass
GroupAdd Terminal, ahk_exe powershell.exe
GroupAdd Terminal, ahk_exe vim.exe
GroupAdd TerminalVim, ahk_group Terminal
GroupAdd TerminalVim, ahk_class Vim

; Vim mode
VimIcon := 1
#Include %A_LineFile%\..\submodules\vim_ahk\vim.ahk

; Auto correct
#Include %A_LineFile%\..\AutoCorrect.ahk

Return
; }}}

;; Basic Settings, HotKeys, Functions {{{
; Settings

#UseHook On ; Make it a bit slow, but can avoid infinitude loop
            ; Same as "$" for each hotkey
#InstallKeybdHook ; For checking key history
                  ; Use ~500kB memory?

#HotkeyInterval 1000 ; Hotkey inteval (default 2000 milliseconds).
#MaxHotkeysPerInterval 100 ; Max hotkeys perinterval (default 50).

; For HHKB
;vkFFsc079::RAlt
;vkFFsc07b::LAlt
vkFFsc079::RCtrl
vkFFsc07b::LCtrl

;; Ref for IME: http://www6.atwiki.jp/eamat/pages/17.html
;; Get IME Status. 0: Off, 1: On
;VIM_IME_GET(WinTitle="A"){
;  ControlGet, hwnd,HWND , , , %WinTitle%
;  if(WinActive(WinTitle)){
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint, 0, Uint, &stGTI)
;        ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd
;  }
;
;  Return DllCall("SendMessage"
;      , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint, hwnd)
;      , UInt, 0x0283  ;Message : WM_IME_CONTROL
;      ,  Int, 0x0005  ;wParam  : IMC_GETOPENSTATUS
;      ,  Int, 0)      ;lParam  : 0
;}
;
;; Get input status. 1: Converting, 2: Have converting window, 0: Others
;VIM_IME_GetConverting(WinTitle="A", ConvCls="", CandCls=""){
;  ; Input windows, candidate windows (Add new IME with "|")
;  ConvCls .= (ConvCls ? "|" : "")                 ;--- Input Window ---
;    .  "ATOK\d+CompStr"                           ; ATOK
;    .  "|imejpstcnv\d+"                           ; MS-IME
;    .  "|WXGIMEConv"                              ; WXG
;    .  "|SKKIME\d+\.*\d+UCompStr"                 ; SKKIME Unicode
;    .  "|MSCTFIME Composition"                    ; Google IME
;  CandCls .= (CandCls ? "|" : "")                 ;--- Candidate Window ---
;    .  "ATOK\d+Cand"                              ; ATOK
;    .  "|imejpstCandList\d+|imejpstcand\d+"       ; MS-IME 2002(8.1)XP
;    .  "|mscandui\d+\.candidate"                  ; MS Office IME-2007
;    .  "|WXGIMECand"                              ; WXG
;    .  "|SKKIME\d+\.*\d+UCand"                    ; SKKIME Unicode
; CandGCls := "GoogleJapaneseInputCandidateWindow" ; Google IME
;
;  ControlGet, hwnd, HWND, , , %WinTitle%
;  if(WinActive(WinTitle)){
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI, 0, "UInt")   ;   DWORD   cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint, 0, Uint, &stGTI)
;      ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd
;  }
;
;  WinGet, pid, PID, % "ahk_id " hwnd
;  tmm := A_TitleMatchMode
;  SetTitleMatchMode, RegEx
;  ret := WinExist("ahk_class " . CandCls . " ahk_pid " pid) ? 2
;      :  WinExist("ahk_class " . CandGCls                 ) ? 2
;      :  WinExist("ahk_class " . ConvCls . " ahk_pid " pid) ? 1
;      :  0
;  SetTitleMatchMode, %tmm%
;  Return ret
;}
;
;; Set IME, SetSts=0: Off, 1: On, return 0 for success, others for non-success
;VIM_IME_SET(SetSts=0, WinTitle="A"){
;  ControlGet, hwnd, HWND, , , %WinTitle%
;  if(WinActive(WinTitle)){
;    ptrSize := !A_PtrSize ? 4 : A_PtrSize
;    VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0)
;    NumPut(cbSize, stGTI, 0, "UInt") ; DWORD  cbSize;
;    hwnd := DllCall("GetGUIThreadInfo", Uint, 0, Uint, &stGTI)
;        ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd
;  }
;
;  Return DllCall("SendMessage"
;    , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hwnd)
;    , UInt, 0x0283  ;Message : WM_IME_CONTROL
;    ,  Int, 0x006   ;wParam  : IMC_SETOPENSTATUS
;    ,  Int, SetSts) ;lParam  : 0 or 1
;}

; }}}

; Terminal/Vim {{{
; ESC + IME
#IfWInActive, ahk_group TerminalVim
Esc:: ; Just send Esc at converting.
  if(VIM_IME_GET(A)){
    if(VIM_IME_GetConverting(A)){
      Send, {Esc}
    }else{
      VIM_IME_SET()
    }
  }else{
    Send, {Esc}
  }
Return

^[:: ; Go to Normal mode (for vim) with IME off even at converting.
  if(VIM_IME_GetConverting(A)){
    Send, {Esc}
    Sleep 1 ; wait 1 ms (Need to stop converting)
  }
  if(VIM_IME_GET(A)){
    VIM_IME_SET()
    Send, {Esc}
  }else{
    Send, {Esc}
  }
Return

^m::Send, ^m ; Use Ctrl-m as is
#IfWInActive

; Paste
#IfWInActive, ahk_group Terminal
!v::
  ;StringSplit, strout, clipboard, `n
  ;If(strout0>1 or InStr(clipboard, "sudo")>0){
  ;  MsgBox, 308, Clipboard, %clipboard%`n`n Do you want to paste?
  ;  IfMsgBox, No
  ;  {
  ;    Return
  ;  }
  ;}
  ;SendInput %clipboard%
  ;Return
  Sleep,200
  MouseClick, Right, 50, 50, 1
Return

#IfWInActive
#IfWInActive, ahk_class Vim
!v::Send, {Alt}ep
#IfWInActive

; Command Promp, PowerShell, Bash on Ubuntu on Windows {{{
#IfWinActive ahk_class ConsoleWindowClass
^v::Send, ^q
!v::
  SendInput %clipboard%
Return
#IfWInActive
; }}} Command Prompt

; Other than Terminal/Vim
#IfWInNotActive, ahk_group TerminalVim
^[::Send, {Esc}             ; Always C-[ to ESC, like vim
^d::Send, {Del}             ; Always Delete with C-d
#IfWInNotActive
; }}} Terminal/Vim

; Power Point {{{
#IfWInActive, ahk_class PP12FrameClass

; Subscript/Superscript
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; For JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}

; Fonts
^!+s::Send, ^tfsymbol{Enter}
^!+a::Send, ^tfarial{Enter}
^!+h::Send, ^tfhelvetica{Enter}
#IfWInActive
; }}} Power Point

; Word {{{
#IfWInActive, ahk_class OpusApp
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; for JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}
#IfWInActive
; }}} Word

; Explorer {{{
#IfWInActive, ahk_class CabinetWClass
; Next/Previous page
^i::Send, !{Right}
^o::Send, !{Left}
#IfWInActive
; }}} Explorer

; CLCL {{{
;#IfWInActive, ahk_class CLCLMain
#IfWInActive, CLCL ; both window/title do not working...
j::
  Msgbox, clcl_down
  Send, {Down}
Return

K::Send, {Up}
#IfWInActive
; }}} Explorer

; Everthing {{{
#IfWInActive, ahk_class EVERYTHING
Return::
  Send, {Enter}
  Sleep, 200
  IfWinActive, ahk_class EVERYTHING
  {
    Send,{Enter}
    Sleep, 500
  }
  WinActivate, ahk_class EVERYTHING
  Sleep, 200
  Send, {Esc}
Return

#IfWInActive
; }}} Everything

; Fiefox {{{
;#IfWinActive ahk_exe firefox.exe
;^j::Send, ^j
;#IfWInActive
; }}} Firefox

; Global Settings {{{
#if
; Basic Settings {{{

; Suspend
;Esc & Tab::
;  Suspend, Toggle
;  Return
; For Alt-Ctrl Swap (swapped by KeySwap)
<^Tab::AltTab
;<+<^Tab::ShiftAltTab ; can not assigned...
;LCtrl & Tab::
;  if GetKeyState("Shift","P"){
;    Send, {ShiftAltTab}
;  }else{
;    Send, {AltTab}
;  }
;Return
;Alt & Tab::
;  if GetKeyState("Shift","P"){
;    Send, ^+{taB}
;  }else{
;    Send, ^{Tab}
;  }
;Return
!Tab::Send, ^{Tab}
!+Tab::Send, ^+{Tab}

;!m::Send, ^m
;^m::Send, !m
;>^m::Send, !m
;Ctrl & Left::Send, !{Left}
;Ctrl & Right::Send, !{Right}

; Virtual desktop
^!+h::Send, #^{Left}
^!+l::Send, #^{Right}

; Cortana
!^f::Send, #s

; CLCL
#c::Send, !c

; Other basic settings
!Space::Send, {vkF3sc029} ; IME by A-Space
^Space::Send, {vkF3sc029} ; IME by C-Space
;{vkF3sc029}               ; 変換
;{vk1Dsc07B}               ; 無変換
!^a::Send, !{Space}n       ; Minimize window
!4::Send, !{F4}           ; Close window
^4::Send, !{F4}           ; Close window
!d::Send, {Del}           ; Always Delete with A-d
;^o::Send,!{Left}          ; Go to previous page
;^i::Send,!{Right}         ; Go to nexe page
^Space::!`                ; IME

^h::Send, {BS}            ; Always BS with C-h
;^h::
;  While GetKeyState("h","p"){
;    Send {BS}
;    TrayTip,Start:,%n%,10,,
;    Sleep 50
;  }
;  return

;^j::Send,{Enter}      ; C-j to Enter

; For HHKB
; ESC to ` like normal keyboard (ESC is placed on the left of 1 in HHKB)
!1::!`                ; IME
; }}} Basic Settings

; Cursor, Mouse, Window move/size {{{
; Cursor {{{
!^h::Send, {Left}
!^j::Send, {Down}
!^k::Send, {Up}
!^l::Send, {Right}
; }}} Cursor

; Mouse {{{
; Mouse Move
^+h::MouseMove, -10, 0, 0, R
^+j::MouseMove, 0, 10, 0, R
^+k::MouseMove, 0, -10, 0, R
^+l::MouseMove, 10, 0, 0, R

; Click
^+n::MouseClick, Left
^+p::MouseClick, Right
; Right click on current window

; Mouse wheel
!^m::MouseClick, WheelDown, , , 2
!^,::MouseClick, WheelUp, , , 2
; }}} Mouse

; Window move {{{

; Move a little
^+y::
  WinGetPos, X, Y, , , A ;A for Active Window
  WinMove, A, ,X-20, Y,
Return

^+u::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y+20
Return

^+i::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y-20
Return

^+o::
  WinGetPos, X, Y, , , A
  WinMove, A, , X+20, Y
Return

; Move to a different screen
!^+y:: Send, #+{Left}
!^+u:: Send, #+{Down}
!^+i:: Send, #+{Up}
!^+o:: Send, #+{Right}

; }}} Window move

; Window size {{{

; Almost full
^!Enter::
!+Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , MWABottom-MWATop-TMargin-BMargin
Return

; Minsize
^!+Enter::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*Minsize
    , (MWABottom-MWATop-TMargin-BMargin)*Minsize
Return

; Half size
!+h::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

!+j::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin
    , MWATop+(MWABottom-MWATop)*0.5
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+k::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+l::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+(MWARight-MWALeft)*0.5
    , MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

; Resize
!+y::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W-20, H
Return

!+u::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H+20
Return

!+i::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H-20
Return

!+o::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W+20, H
Return

; }}} Window size
; }}} Cursor, Mouse, Window move
; }}} Global Settings


Parse keymap strings instead of multiple SetKey()

Also add keymaps and stub menus for WASD/HJKL

; JKLmouse for AutoHotkey by Michael Geary
; http://www.jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement
; Version 0.1: 11/3/2011

#AllowSameLineComments
#SingleInstance force

; Use either the embedded icon in a compiled .exe,
; or a separate .ico file when running the .ahk script.
iconPath := RegExReplace( A_ScriptFullPath, "i).ahk$", ".ico" )

keyMap := ""

keyMaps :=
(join
{
	Arrows: "Up~Up Down~Down Left~Left Right~Right",
	NumPad: "7~UpLeft 8~Up 9~UpRight 4~Left 5~Down 6~Right 1~DownLeft 2~Down 3~DownRight",
	IJKL: "U~UpLeft I~Up O~UpRight J~Left K~Down L~Right M~DownLeft ,~Down .~DownRight",
	HJKL: "H~Left J~Down K~Up L~Right",
	ESDF: "W~UpLeft E~Up R~UpRight S~Left D~Down F~Right X~DownLeft C~Down V~DownRight",
	WASD: "Q~UpLeft W~Up E~UpRight A~Left S~Down D~Right Z~DownLeft X~Down C~DownRight"
}
)

; Set up the tray icon and menu
Menu, Tray, Icon, %iconPath%
Menu, Tray, Tip, JKLmouse
Menu, Tray, Add
Menu, Tray, Add, Left Hand: ESDF, MenuESDF
Menu, Tray, Add, Left Hand: WASD, MenuWASD
Menu, Tray, Add
Menu, Tray, Add, Right Hand: IJKL, MenuIJKL
Menu, Tray, Add, Right Hand: HJKL, MenuHJKL
Menu, Tray, Add
Menu, Tray, Add, About JKLmouse, MenuAbout

Menu, Tray, Check, Left Hand: ESDF
Menu, Tray, Check, Right Hand: IJKL

; Display tray balloon
; TODO: more useful content?
; TODO: display this only during an install
TrayTip JKLmouse, The Automatic Keyboard Mouse

; Remove forced delay between triggered mouse events.
; TODO: experiment with this when accelerated
SetMouseDelay, -1

; Hotkey repeat count for acceleration
repeat := 0

SetKeyMap( "Arrows", "NumPad", "IJKL", "ESDF" )
;SetKeyMap( "Arrows", "NumPad", "HJKL", "WASD" )

;MsgBox % keyMap

SetAllKeys( true )

return

SetKeyMap( keys* ) {
	global keyMap, keyMaps
    for index, value in keys
        keyMap .= keyMaps[value] . " "
    return SubStr( str, 1, -StrLen(sep) )
}

SetAllKeys( on ) {
	; Each of these modifier keys enables the same set of JKLmouse hotkeys
	SetKeys( on, "CapsLock" )
	SetKeys( on, "~LButton" )
	SetKeys( on, "~RButton" )
	SetKeys( on, "~MButton" )
	SetKeys( on, "~XButton1" )
	SetKeys( on, "~XButton2" )
}

; Set up or remove all the hotkeys for a specific modifier key
SetKeys( on, mod ) {
	global keyMap
	Loop, Parse, keyMap, %A_Space%
	{
		StringSplit map, A_LoopField, ~
		SetKey( on, mod, map1, "Mouse" . map2 )
	}
}

; Set up or remove one hotkey by combining the modifier and key names.
; Take the specified action on key down,
; and always stop acceleration on key up.
SetKey( on, mod, key, action ) {
	keydown = %mod% & %key%
	if( on ) {
		Hotkey %keydown%, %action%
		Hotkey %keydown% UP, StopAcceleration
	}
	else {
		Hotkey %keydown%, Off
		Hotkey %keydown% UP, Off
	}
}

; Move the mouse the specifed x and y distances, both scaled by the
; mouse acceleration factor calculated from the key repeat count.
Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

;ArrayJoin( sep, ary ) {
;    for index, value in ary
;		MsgBox % index
;        ;str .= value . sep
;	MsgBox % str
;    return SubStr( str, 1, -StrLen(sep) )
;}

; Handle the keydown for each of the mouse movement directions
; TODO: Maybe a way to simplify this?
MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseUpLeft:
	Move( -1, -1 )
	return
MouseUpRight:
	Move( 1, -1 )
	return
MouseDownLeft:
	Move( -1, 1 )
	return
MouseDownRight:
	Move( 1, 1 )
	return

; Handle the keyup for all hotkeys
StopAcceleration:
	repeat = 0
	return

; Handle the About menu item
MenuAbout:
	Run, http://www.jklmouse.com/
	return

MenuESDF:
	return

MenuWASD:
	return

MenuIJKL:
	return

MenuHJKL:
	return

; JKLmouse for AutoHotkey by Michael Geary
; http://www.jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement
; Version 0.1: 11/3/2011

#SingleInstance force

; Use either the embedded icon in a compiled .exe,
; or a separate .ico file when running the .ahk script.
iconPath := RegExReplace( A_ScriptFullPath, "i).ahk$", ".ico" )

; Set up the tray icon and menu
Menu, Tray, Icon, %iconPath%
Menu, Tray, Tip, JKLmouse
Menu, Tray, Add
Menu, Tray, Add, About JKLmouse, MenuAbout

; Display tray balloon
; TODO: more useful content?
; TODO: display this only during an install
TrayTip JKLmouse, The Automatic Keyboard Mouse

; Remove forced delay between triggered mouse events.
; TODO: experiment with this when accelerated
SetMouseDelay, -1

; Hotkey repeat count for acceleration
repeat := 0

; Each of these modifier keys enables the same set of JKLmouse hotkeys
SetKeys( "CapsLock" )
SetKeys( "~LButton" )
SetKeys( "~RButton" )
SetKeys( "~MButton" )
SetKeys( "~XButton1" )
SetKeys( "~XButton2" )

return

; Set up all the hotkeys for a specific modifier key
SetKeys( mod ) {

	; Left hand
	SetKey( mod, "W", "MouseLeftUp" )
	SetKey( mod, "E", "MouseUp" )
	SetKey( mod, "R", "MouseRightUp" )
	SetKey( mod, "S", "MouseLeft" )
	SetKey( mod, "D", "MouseDown" )
	SetKey( mod, "F", "MouseRight" )
	SetKey( mod, "X", "MouseLeftDown" )
	SetKey( mod, "C", "MouseDown" )
	SetKey( mod, "V", "MouseRightDown" )

	; Right hand
	SetKey( mod, "U", "MouseLeftUp" )
	SetKey( mod, "I", "MouseUp" )
	SetKey( mod, "O", "MouseRightUp" )
	SetKey( mod, "J", "MouseLeft" )
	SetKey( mod, "K", "MouseDown" )
	SetKey( mod, "L", "MouseRight" )
	SetKey( mod, "M", "MouseLeftDown" )
	SetKey( mod, "`,","MouseDown" )
	SetKey( mod, "`.","MouseRightDown" )

	; Numeric
	SetKey( mod, "7", "MouseLeftUp" )
	SetKey( mod, "8", "MouseUp" )
	SetKey( mod, "9", "MouseRightUp" )
	SetKey( mod, "4", "MouseLeft" )
	SetKey( mod, "5", "MouseDown" )
	SetKey( mod, "6", "MouseRight" )
	SetKey( mod, "1", "MouseLeftDown" )
	SetKey( mod, "2", "MouseDown" )
	SetKey( mod, "3", "MouseRightDown" )

	; Arrows
	SetKey( mod, "Up", "MouseUp" )
	SetKey( mod, "Down", "MouseDown" )
	SetKey( mod, "Left", "MouseLeft" )
	SetKey( mod, "Right", "MouseRight" )
}

; Set up one hotkey by combining the modifier and key names.
; Take the specified action on key down,
; and always stop acceleration on key up.
SetKey( mod, key, action ) {
	keydown = %mod% & %key%
	Hotkey %keydown%, %action%
	Hotkey %keydown% UP, StopAcceleration
}

; Move the mouse the specifed x and y distances, both scaled by the
; mouse acceleration factor calculated from the key repeat count.
Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

; Handle the keydown for each of the mouse movement directions
; TODO: Maybe a way to simplify this?
MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

; Handle the keyup for all hotkeys
StopAcceleration:
	repeat = 0
	return

; Handle the About menu item
MenuAbout:
	Run, http://www.jklmouse.com/
	return