Code style

Code style

; Version 1.0.3

#Persistent, ON
#SingleInstance, Force

SetWorkingDir, %A_ScriptDir%
SetControlDelay, -1
Detecthiddenwindows, on
Coordmode, Menu, Window

OnMessage(0x4a, "Receive_WM_COPYDATA")

Init()

; Tray Menu {{{1
Menu, Tray, NoStandard
Menu, Tray, Add, 显示热键(&Q), GUI_ListHotkey
Menu, Tray, Default, 显示热键(&Q)
Menu, Tray, Add
Menu, Tray, Add, 主页(&M), GUI_GotoWeb
Menu, Tray, Add, 提交问题(&I), GUI_GotoIssue
Menu, Tray, Add
Menu, Tray, Add, 重启(&R), <reload>
Menu, Tray, Add, 退出(&X), GUI_Exit
Menu, Tray, Icon, viatc.ico
;====================================================================
; Read Config {{{1

FileEncoding, utf-8

Global ConfigPath := A_ScriptDir  "\vimd.ini"

If Not FileExist(ConfigPath)
    FileAppend, , %ConfigPath%
If Not FileExist(A_ScriptDir "\plugins\plugins.ahk")
    Run %A_ScriptDir%\check.ahk

config := GetINIObj(ConfigPath)
plog   := GetINIObj(A_ScriptDir "\plugins\plugins.ahk")

Global InvalidMode := config.GetValue("config", "InvalidMode")

;是否显示快捷键注释
Global ToShowComment := true
IniRead ToShowComment, %ConfigPath%, Config, ToShowComment, true

sub := plog.GetKeys("ExtensionsTime")
Loop, Parse, Sub, `n
{
    If IsLabel(A_LoopField) And Strlen(A_LoopField){
        Enabled := strlen(config.GetValue("plugins", A_LoopField)) ? config.GetValue("plugins", A_LoopField) : 1
        if Enabled{
            GoSub, %A_LoopField%
        }
    }
}
keylist := config.GetKeys("Global")
Loop, Parse, keylist, `n
{
    If not strlen(A_LoopField)
        continue
    value := config.GetValue("Global", Trim(A_LoopField))
    If RegExMatch(value, "\[=[^\[\]]*\]", mode)Plugins
        vim.mode(Substr(mode, 3, strlen(mode)-3))
    If RegExMatch(Trim(A_LoopField), "^\*")
        vim.smap(SubStr(Trim(A_LoopField), 2), RegExReplace(value, "\[=[^\[\]]*\]"))
    Else
        vim.map(Trim(A_LoopField), RegExReplace(value, "\[=[^\[\]]*\]"))
}

keylist := config.GetKeys("Global_Exclude")
Loop, Parse, keylist, `n
{
    If Strlen(A_LoopField)
        vim.Exclude(A_LoopField)
    Else
        continue
}

for class , k in vim.vimWindows
{
    If strlen(config.GetKeyValue(class))
    {
        keylist := config.GetKeys(class)
        Loop, Parse, keylist, `n
        {
            If not strlen(A_LoopField)
                continue
            value := config.GetValue(class, Trim(A_LoopField))
            If RegExMatch(value, "\[=[^\[\]]*\]", mode)
                vim.mode(Substr(mode, 3, strlen(mode)-3))
            If RegExMatch(Trim(A_LoopField), "^\*")
                vim.smap(SubStr(Trim(A_LoopField), 2), RegExReplace(value, "\[=[^\[\]]*\]"), class)
            Else
                vim.map(Trim(A_LoopField), RegExReplace(value, "\[=[^\[\]]*\]"), class)
        }
    }
}

;检查是否触发了重启操作
IniRead, trigger, %ConfigPath%, Config, Reload.Trigger, null
if trigger <> null
{
    ;感觉这个提示没有用，调试时很麻烦，先去掉
    ;MsgBox, , 提示 -- 两秒后自动关闭.., %trigger%, 2

    IniDelete, %ConfigPath%, Config, Reload.Trigger
}

WatchDirectory(A_ScriptDir , 1)
autoload := strlen(config.GetValue("config", "autoload")) ? config.GetValue("config", "autoload") : 1
If autoload
    SetTimer, WatchPlugins, 1000
EmptyMem()
return

;====================================================================
WatchPlugins:
    WatchDirectory("PluginsChange")
return
PluginsChange(a, f, i){
    IniWrite, 插件或配置的变更已被成功应用！, %ConfigPath%, Config, Reload.Trigger
    Run %A_ScriptDir%\check.ahk
    ;SetTimer, WatchPlugins, off
    ExitApp
}
; GUI {{{1
; GUI_Config() {{{2
<Config>:
    GUI_Config()
return
GUI_Config() {
    GUI, Config:Destroy
    GUI, Config:Font, s9 , Microsoft YaHei
    Gui, Config:+Delimiter`n +hwndconfig +LastFound +Resize
    GUI, Config:Add, ListBox, w200 h200
    GUI, Config:Show
    WinMove, ahk_id %config%, , , , 626, 500
}

; GUI_ListHotkey() {{{2
GUI_ListHotkey() {
    win := "全局" "`n"
    For i , k in vim.vimWindows
        win .= i "`n"
    ;GUI, ListHotkey:Add, Edit
    GUI, ListHotkey:Destroy
    GUI, ListHotkey:Font, s9 , Microsoft YaHei
    Gui, ListHotkey:+Delimiter`n +hwndlhk +LastFound +Resize
    GUI, ListHotkey:Add, Text, x7 y8, 窗口:
    GUI, ListHotkey:Add, DropDownList, x45 y5 w560 choose1 gGUI_ListHotKey_Win, %win%
    GUI, ListHotkey:Add, Text, x7 y38, 模式:
    GUI, ListHotKey:Add, DropDownList, x45 y35 w560 choose1 gGUI_ListHotKey_Mode
    GUI, ListHotKey:Add, ListView, x5 w600 h400 , 热键`n动作`n说明
    GUI, ListHotkey:Default
    LV_ModifyCol(1, "100")
    LV_ModifyCol(2, "200")
    LV_ModifyCol(3, "300")
    GUI, ListHOtkey:Show
    WinMove, ahk_id %lhk%, , , , 626
    GoSub, GUI_ListHotkey_Win
}

GUI_ListHotkey_Win:
    GUI_ListHotkey_Win()
return
; GUI_ListHotkey_Win() {{{2
GUI_ListHotkey_Win() {
    GUI, ListHotkey:Default
    GUIControlGet, win, , ComboBox1
    win := win = 全局 ? "" : win
    m := vim.ListKey(win)
    mode := "`n"
    Loop, Parse, m, `n
    {
        If IsMode
            mode .= A_LoopField "`n"
        If A_LoopField = ====
            IsMode := True
        ELse
            IsMode := False
    }
    GUIControl, , ComboBox2, %mode%
    GUIControl, Choose, ComboBox2, 1
    GoSub, GUI_ListHotkey_Mode
}
GUI_ListHotkey_Mode:
    GUI_ListHotkey_Mode()
return
; GUI_ListHotkey_Mode() {{{2
GUI_ListHotkey_Mode() {
    GUI, ListHOtkey:Default
    GUIControlGet, win, , ComboBox1
    GUIControlGet, Mode, , ComboBox2
    m := vim.ListKey(win, Mode)
    m0 := 1
    LV_Delete()
    Loop, Parse, m, `n
    {
        If Strlen(A_LoopField) = 0
            Continue
        m1 := ""
        m2 := ""
        Loop, Parse, A_LoopField, %A_Space%
        {
            If Strlen(m1)
                m2 := A_LoopField
            Else
                m1 := A_LoopField
        }
        m3 := vim.CommentList[m2]
        If LV_Add("", m1, m2, m3)
            m0 := m0 + 1
    }
}
; GUISize(w, p){{{2
GUISize(w, p){
    GUI, ListHotkey:+hwndlhk
    IfWinActive ahk_id %lhk%
    {
        Anchor("combobox1", "w")
        Anchor("combobox2", "w")
        Anchor("SysListView321", "wh")
        GUI, ListHotkey:Default
        GUI, ListView, SysListView321
        ControlGetPos , , , w, , SysListView321, ahk_id %lhk%
        LV_ModifyCol(3, w-221)
    }
}

GUI_ListHotkey:
    GUI_ListHotkey()
return

GUI_Listline:
    Listlines
return

<reload>:
    IniWrite, VimDesktop 重启完成！, %ConfigPath%, Config, Reload.Trigger
    Reload
return

GUI_Exit:
    ExitApp
return

GUI_GotoWeb:
    run "https://github.com/victorwoo/vimdesktop"
return

GUI_GotoIssue:
    run "https://github.com/victorwoo/vimdesktop/issues"
return

GUI_VIMINFO:
    GUI_VIMINFO()
return
GUI_VIMINFO()
{
    GUI, Query:Default
    GUIControlGet, Key, , Edit1
    GUIControlGet, Win, , Static1
    w := vim.Vaild(win)
    mode := w.GetMode()
    If Strlen(Key)
    {
        Msgbox % win Key
    }
    Else
        GUI, Query:Destroy
}
; Receive_WM_COPYDATA(wParam, lParam) {{{2
Receive_WM_COPYDATA(wParam, lParam){
    StringAddress := NumGet(lParam + 2*A_PtrSize)  ; 获取 CopyDataStruct 的 lpData 成员.
    AHKReturn := StrGet(StringAddress)  ; 从结构中复制字符串.
    If RegExMatch(AHKReturn, "i)exitapp")
        ExitApp
    return true
}

#Include %A_ScriptDir%\lib\vimcore.ahk
#Include %A_ScriptDir%\lib\anchor.ahk
#Include %A_ScriptDir%\lib\ini.ahk
#Include %A_ScriptDir%\lib\watchdir.ahk
#Include *i %A_ScriptDir%\lib\InputColor.ahk
#Include *i %A_ScriptDir%\plugins\plugins.ahk

;Version 1.0.3
#Persistent,ON
#SingleInstance,Force
SetWorkingDir, %A_ScriptDir%
SetControlDelay,-1
Detecthiddenwindows,on
Coordmode,Menu,Window
OnMessage(0x4a, "Receive_WM_COPYDATA")
Init()
; Tray Menu {{{1
Menu,Tray,NoStandard
Menu,Tray,Add,显示热键(&Q),GUI_ListHotkey
Menu,Tray,Default,显示热键(&Q)
Menu,Tray,Add
Menu,Tray,Add,主页(&M),GUI_GotoWeb
Menu,Tray,Add,提交问题(&I),GUI_GotoIssue
Menu,Tray,Add
Menu,Tray,Add,重启(&R),<reload>
Menu,Tray,Add,退出(&X),GUI_Exit
Menu,Tray,Icon,viatc.ico
;====================================================================
; Read Config {{{1

FileEncoding,utf-8

Global ConfigPath := A_ScriptDir  "\vimd.ini"

If Not FileExist(ConfigPath)
	FileAppend,,%ConfigPath%
If Not FileExist(A_ScriptDir "\plugins\plugins.ahk")
	Run %A_ScriptDir%\check.ahk

config := GetINIObj(ConfigPath)
plog   := GetINIObj(A_ScriptDir "\plugins\plugins.ahk")

Global InvalidMode := config.GetValue("config","InvalidMode")

;是否显示快捷键注释
Global ToShowComment := true
IniRead ToShowComment, %ConfigPath%, Config, ToShowComment, true

sub := plog.GetKeys("ExtensionsTime")
Loop,Parse,Sub,`n
{
	If IsLabel(A_LoopField) And Strlen(A_LoopField){
		Enabled := strlen(config.GetValue("plugins",A_LoopField)) ? config.GetValue("plugins",A_LoopField) : 1
		if Enabled{
			GoSub,%A_LoopField%
		}
	}
}
keylist := config.GetKeys("Global")
Loop,Parse,keylist,`n
{
	If not strlen(A_LoopField)
		continue
	value := config.GetValue("Global",Trim(A_LoopField))
	If RegExMatch(value,"\[=[^\[\]]*\]",mode)Plugins
		vim.mode(Substr(mode,3,strlen(mode)-3))
	If RegExMatch(Trim(A_LoopField),"^\*")
		vim.smap(SubStr(Trim(A_LoopField),2),RegExReplace(value,"\[=[^\[\]]*\]"))
	Else
		vim.map(Trim(A_LoopField),RegExReplace(value,"\[=[^\[\]]*\]"))
}

keylist := config.GetKeys("Global_Exclude")
Loop,Parse,keylist,`n
{
	If Strlen(A_LoopField)
		vim.Exclude(A_LoopField)
	Else
		continue
}

for class ,k in vim.vimWindows
{
	If strlen(config.GetKeyValue(class))
	{
		keylist := config.GetKeys(class)
		Loop,Parse,keylist,`n
		{
			If not strlen(A_LoopField)
				continue
			value := config.GetValue(class,Trim(A_LoopField))
			If RegExMatch(value,"\[=[^\[\]]*\]",mode)
				vim.mode(Substr(mode,3,strlen(mode)-3))
			If RegExMatch(Trim(A_LoopField),"^\*")
				vim.smap(SubStr(Trim(A_LoopField),2),RegExReplace(value,"\[=[^\[\]]*\]"),class)
			Else
				vim.map(Trim(A_LoopField),RegExReplace(value,"\[=[^\[\]]*\]"),class)
		}
	}
}

;检查是否触发了重启操作
IniRead, trigger, %ConfigPath%, Config, Reload.Trigger, null
if trigger <> null
{
	;感觉这个提示没有用，调试时很麻烦，先去掉
	;MsgBox, , 提示 -- 两秒后自动关闭.., %trigger%, 2

	IniDelete, %ConfigPath%, Config, Reload.Trigger
}

WatchDirectory(A_ScriptDir ,1)
autoload := strlen(config.GetValue("config","autoload")) ? config.GetValue("config","autoload") : 1
If autoload
	SetTimer,WatchPlugins,1000
EmptyMem()
return

;====================================================================
WatchPlugins:
	WatchDirectory("PluginsChange")
return
PluginsChange(a,f,i){
	IniWrite, 插件或配置的变更已被成功应用！, %ConfigPath%, Config, Reload.Trigger
	Run %A_ScriptDir%\check.ahk
	;SetTimer,WatchPlugins,off
	ExitApp
}
; GUI {{{1
; GUI_Config() {{{2
<Config>:
	GUI_Config()
return
GUI_Config() {
	GUI,Config:Destroy
	GUI,Config:Font,s9 ,Microsoft YaHei
	Gui,Config:+Delimiter`n +hwndconfig +LastFound +Resize
	GUI,Config:Add,ListBox,w200 h200
	GUI,Config:Show
	WinMove,ahk_id %config%,,,,626,500
}

; GUI_ListHotkey() {{{2
GUI_ListHotkey() {
	win := "全局" "`n"
	For i , k in vim.vimWindows
		win .= i "`n"
	;GUI,ListHotkey:Add,Edit
	GUI,ListHotkey:Destroy
	GUI,ListHotkey:Font,s9 ,Microsoft YaHei
	Gui,ListHotkey:+Delimiter`n +hwndlhk +LastFound +Resize
	GUI,ListHotkey:Add,Text,x7 y8,窗口:
	GUI,ListHotkey:Add,DropDownList,x45 y5 w560 choose1 gGUI_ListHotKey_Win,%win%
	GUI,ListHotkey:Add,Text,x7 y38 ,模式:
	GUI,ListHotKey:Add,DropDownList,x45 y35 w560 choose1 gGUI_ListHotKey_Mode
	GUI,ListHotKey:Add,ListView, x5   w600 h400 ,热键`n动作`n说明
	GUI,ListHotkey:Default
	LV_ModifyCol(1,"100 ")
	LV_ModifyCol(2,"200 ")
	LV_ModifyCol(3,"300 ")
	GUI,ListHOtkey:Show
	WinMove,ahk_id %lhk%,,,,626
	GoSub,GUI_ListHotkey_Win
}

GUI_ListHotkey_Win:
	GUI_ListHotkey_Win()
return
; GUI_ListHotkey_Win() {{{2
GUI_ListHotkey_Win() {
	GUI,ListHotkey:Default
	GUIControlGet,win,,ComboBox1
    win := win = 全局 ? "" : win
	m := vim.ListKey(win)
	mode := "`n"
	Loop,Parse,m,`n
	{
		If IsMode
			mode .= A_LoopField "`n"
		If A_LoopField = ====
			IsMode := True
		ELse
			IsMode := False
	}
	GUIControl,,ComboBox2,%mode%
	GUIControl,Choose,ComboBox2,1
	GoSub,GUI_ListHotkey_Mode
}
GUI_ListHotkey_Mode:
	GUI_ListHotkey_Mode()
return
; GUI_ListHotkey_Mode() {{{2
GUI_ListHotkey_Mode() {
	GUI,ListHOtkey:Default
	GUIControlGet,win,,ComboBox1
	GUIControlGet,Mode,,ComboBox2
	m := vim.ListKey(win,Mode)
	m0 := 1
	LV_Delete()
	Loop,Parse,m,`n
	{
		If Strlen(A_LoopField) = 0
			Continue
		m1 := ""
		m2 := ""
		Loop,Parse,A_LoopField,%A_Space%
		{
			If Strlen(m1)
				m2 := A_LoopField
			Else
				m1 := A_LoopField
		}
		m3 := vim.CommentList[m2]
		If LV_Add("",m1,m2,m3)
			m0 := m0 + 1
	}
}
; GUISize(w,p){{{2
GUISize(w,p){
	GUI,ListHotkey:+hwndlhk
	IfWinActive ahk_id %lhk%
	{
		Anchor("combobox1","w")
		Anchor("combobox2","w")
		Anchor("SysListView321","wh")
		GUI,ListHotkey:Default
		GUI,ListView,SysListView321
		ControlGetPos , , , w, ,SysListView321,ahk_id %lhk%
		LV_ModifyCol(3,w-221)
	}
}

GUI_ListHotkey:
	GUI_ListHotkey()
return

GUI_Listline:
	Listlines
return

<reload>:
	IniWrite, VimDesktop 重启完成！, %ConfigPath%, Config, Reload.Trigger
	Reload
return

GUI_Exit:
	ExitApp
return

GUI_GotoWeb:
	run "https://github.com/victorwoo/vimdesktop"
return

GUI_GotoIssue:
	run "https://github.com/victorwoo/vimdesktop/issues"
return

GUI_VIMINFO:
    GUI_VIMINFO()
return
GUI_VIMINFO()
{
    GUI,Query:Default
    GUIControlGet,Key,,Edit1
    GUIControlGet,Win,,Static1
    w := vim.Vaild(win)
    mode := w.GetMode()
    If Strlen(Key)
    {
        Msgbox % win Key
    }
    Else
        GUI,Query:Destroy
}
; Receive_WM_COPYDATA(wParam, lParam) {{{2
Receive_WM_COPYDATA(wParam, lParam){
    StringAddress := NumGet(lParam + 2*A_PtrSize)  ; 获取 CopyDataStruct 的 lpData 成员.
    AHKReturn := StrGet(StringAddress)  ; 从结构中复制字符串.
	If RegExMatch(AHKReturn,"i)exitapp")
		ExitApp
    return true
}

#Include %A_ScriptDir%\lib\vimcore.ahk
#Include %A_ScriptDir%\lib\anchor.ahk
#Include %A_ScriptDir%\lib\ini.ahk
#Include %A_ScriptDir%\lib\watchdir.ahk
#Include *i %A_ScriptDir%\lib\InputColor.ahk
#Include *i %A_ScriptDir%\plugins\plugins.ahk


Added Pidgin support to AutoHotkey

Added Pidgin support to AutoHotkey

;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%

;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
	+^![::
	{
		X := MonitorWorkAreaRight - 920
		Y := 45
		Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%X%`,%Y%" --class "mintty_thetty" --exec /bin/zsh -l, %CygPath%
		return
	}
	^![::
	{
		if (!WinExist("ahk_class mintty_thetty"))
		{
			X := MonitorWorkAreaRight - 920
			Y := 45
			Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%X%`,%Y%" --class "mintty_thetty" --exec /bin/zsh -l -c 'while /bin/true`; do /bin/zsh`; 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
	+^!]::
	{
		X := 45
		Y := 45
		Run, %CygPath%\bin\mintty.exe --title "Remote terminal" --size "190`,65" --position "%X%`,%Y%" --class mintty_ssh --exec /bin/ssh -p 65000 rr-@sakuya.pl, %CygPath%/bin
		return
	}
	^!]::
	{
		X := 45
		Y := 45
		if (!WinExist("ahk_class mintty_ssh"))
		{
			Run, %CygPath%\bin\mintty.exe --title "Remote terminal" --size "190`,65" --position "%X%`,%Y%" --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 -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("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
	{
		ActiveHwnd := WinExist("A")
		PostMessage 0x112, 0xF020 ;WM_SYSCOMMAND, SC_MINIMIZE
	}
	return

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

;transparency
#1::WinSet, Transparent, 0, A
#2::WinSet, Transparent, 64, A
#3::WinSet, Transparent, 255, A
#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

;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 WTWPath
WTWPath = C:\Program Files\WTW\WTW.exe
IfNotExist %WTWPath%
	WTWPath = C:\Program Files\K2T\WTW\WTW.exe

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

;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
	+^![::
	{
		X := MonitorWorkAreaRight - 920
		Y := 45
		Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%X%`,%Y%" --class "mintty_thetty" --exec /bin/zsh -l, %CygPath%
		return
	}
	^![::
	{
		if (!WinExist("ahk_class mintty_thetty"))
		{
			X := MonitorWorkAreaRight - 920
			Y := 45
			Run, %CygPath%\bin\mintty.exe --title "Terminal" --size "110`,35" --position "%X%`,%Y%" --class "mintty_thetty" --exec /bin/zsh -l -c 'while /bin/true`; do /bin/zsh`; 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
	+^!]::
	{
		X := 45
		Y := 45
		Run, %CygPath%\bin\mintty.exe --title "Remote terminal" --size "190`,65" --position "%X%`,%Y%" --class mintty_ssh --exec /bin/ssh -p 65000 rr-@sakuya.pl, %CygPath%/bin
		return
	}
	^!]::
	{
		X := 45
		Y := 45
		if (!WinExist("ahk_class mintty_ssh"))
		{
			Run, %CygPath%\bin\mintty.exe --title "Remote terminal" --size "190`,65" --position "%X%`,%Y%" --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 -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}

;wtw
#If FileExist(WTWPath)
	;wtw - activate/run
	+^!M::
		if (!WinExist("ahk_class {B993D471-D465-43f2-BBA5-DEEA18A1789E}"))
		{
			Run, %WTWPath% -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("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
	{
		ActiveHwnd := WinExist("A")
		PostMessage 0x112, 0xF020 ;WM_SYSCOMMAND, SC_MINIMIZE
	}
	return

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

;transparency
#1::WinSet, Transparent, 0, A
#2::WinSet, Transparent, 64, A
#3::WinSet, Transparent, 255, A
#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


turn debug off

turn debug off

; Autohotkey configuration file
; AHK Version v.1.1.32.00
; Franklin Chou (franklin.chou@nelsonmullins.com)
; 22 Mar. 2020
; Tested to work on Lenovo X1 Yoga, Gen. 4

#SingleInstance Force
#Persistent

GLOBAL_DEBUG_MODE := 0
Return

CapsLock::Ctrl
LCtrl::Return
;LCtrl::CapsLock

; DEBUG TOOLS -----------------------------------------------------------------

#c::
  If(GLOBAL_DEBUG_MODE > 0) {
    ; WinGetTitle, title, A
    WinGetClass, title, A
    MsgBox %title%
  }
Return

f12::
  If(GLOBAL_DEBUG_MODE > 0) {
    Reload
  }
Return

#'::
  If(GLOBAL_DEBUG_MODE > 0) {
    WinGet windows, List
    Loop %windows% {
      id := windows%A_Index%
      WinGetTitle wt, ahk_id %id%
      r .= wt . "`n"
    }
    MsgBox %r%
  }
Return

; TIMEKEEPER ------------------------------------------------------------------

; Shift focus to the timekeeper app
#!e::
  timekeeper_app := WinExist("ahk_class WindowsForms10.Window.8.app.0.262fb3d")
  ;MsgBox %timekeeper_app%
  If(timekeeper_app > 0) {
    WinActivate, ahk_id %timekeeper_app%
  } Else {
    Run, DTE.exe, C:\Program Files (x86)\DTEAxiom
  }
Return

; Start the timer on the selected item in the daily view
#IfWinActive ahk_class WindowsForms10.Window.8.app.0.262fb3d
  >+s::
    WinGetActiveTitle, active_title
    match_result := RegExMatch(active_title, "^Entries for")
    ; each item in the dropdown is approximately 25 pixels
    ; so item 4 (Start Timer) is 100 pixels down from the context menu
    drop_down := 100
    If(match_result > 0) {
      WinMove, 100, 100
      MouseMove, 100, 280
      Send {RButton}
      Sleep, 10 ; need to sleep to allow submenu time to come up
      MouseMove, 170, 300 + drop_down
      Send {LButton}
    }
Return

; WORD/OUTLOOK ----------------------------------------------------------------
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class rctrl_renwnd32")
  PrintScreen::AppsKey
Return

; Autohotkey configuration file
; AHK Version v.1.1.32.00
; Franklin Chou (franklin.chou@nelsonmullins.com)
; 22 Mar. 2020
; Tested to work on Lenovo X1 Yoga, Gen. 4

#SingleInstance Force
#Persistent

GLOBAL_DEBUG_MODE := 1
Return

CapsLock::Ctrl
LCtrl::Return
;LCtrl::CapsLock

; DEBUG TOOLS -----------------------------------------------------------------

#c::
  If(GLOBAL_DEBUG_MODE > 0) {
    ; WinGetTitle, title, A
    WinGetClass, title, A
    MsgBox %title%
  }
Return

f12::
  If(GLOBAL_DEBUG_MODE > 0) {
    Reload
  }
Return

#'::
  If(GLOBAL_DEBUG_MODE > 0) {
    WinGet windows, List
    Loop %windows% {
      id := windows%A_Index%
      WinGetTitle wt, ahk_id %id%
      r .= wt . "`n"
    }
    MsgBox %r%
  }
Return

; TIMEKEEPER ------------------------------------------------------------------

; Shift focus to the timekeeper app
#!e::
  timekeeper_app := WinExist("ahk_class WindowsForms10.Window.8.app.0.262fb3d")
  ;MsgBox %timekeeper_app%
  If(timekeeper_app > 0) {
    WinActivate, ahk_id %timekeeper_app%
  } Else {
    Run, DTE.exe, C:\Program Files (x86)\DTEAxiom
  }
Return

; Start the timer on the selected item in the daily view
#IfWinActive ahk_class WindowsForms10.Window.8.app.0.262fb3d
  >+s::
    WinGetActiveTitle, active_title
    match_result := RegExMatch(active_title, "^Entries for")
    ; each item in the dropdown is approximately 25 pixels
    ; so item 4 (Start Timer) is 100 pixels down from the context menu
    drop_down := 100
    If(match_result > 0) {
      WinMove, 100, 100
      MouseMove, 100, 280
      Send {RButton}
      Sleep, 10 ; need to sleep to allow submenu time to come up
      MouseMove, 170, 300 + drop_down
      Send {LButton}
    }
Return

; WORD/OUTLOOK ----------------------------------------------------------------
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class rctrl_renwnd32")
  PrintScreen::AppsKey
Return


update script

update script

DetectHiddenWindows, On
SetDefaultMouseSpeed, 0
CoordMode, Mouse, Client
target=ahk_class Diablo II
executeCmd = "Diablo II.exe" -w
executeDir=C:\Diablo II
SetWorkingDir, %executeDir%

WinGet, hwnd, ID, %target%
if (!hwnd) {
    Run, %executeCmd%
    Sleep, 5000
    WinGet, hwnd, ID, %target%
    if (hwnd) {
        WinSet, AlwaysOnTop, on, ahk_id %hwnd%
        WinActivate, ahk_id %hwnd%
        IfWinActive, ahk_id %hwnd%
        {
            BlockInput On
            MouseMove, 400, 308, 0
            MouseClick, left
            Sleep, 100
            MouseClick, left
            Sleep, 5000
            MouseMove, 175, 125, 0
            MouseClick, left
            MouseClick, left
            Sleep, 5000
            BlockInput Off
        }
    }
}

DetectHiddenWindows, On
SetDefaultMouseSpeed, 0
CoordMode, Mouse, Client
target=ahk_class Diablo II
executeCmd = "Diablo II.exe" -w
executeDir = "C:\Diablo II"

WinGet, hwnd, ID, %target%
if (!hwnd) {
    Run, %executeCmd%, %executeDir%
    Sleep, 5000
    WinGet, hwnd, ID, %target%
    if (hwnd) {
        WinSet, AlwaysOnTop, on, ahk_id %hwnd%
        WinMove, ahk_id %hwnd%, , 0, 0
        WinActivate, ahk_id %hwnd%
        IfWinActive, ahk_id %hwnd%
        {
            BlockInput On
            MouseMove, 400, 308, 0
            MouseClick, left
            Sleep, 100
            MouseClick, left
            Sleep, 5000
            MouseMove, 175, 125, 0
            MouseClick, left
            MouseClick, left
            Sleep, 5000
            BlockInput Off
        }
    }
}