-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoHotkey.ahk
146 lines (131 loc) · 3.67 KB
/
AutoHotkey.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
SetTitleMatchMode RegEx
^!n::
IfWinExist Untitled - Notepad
WinActivate
else
Run Notepad
return
#a:: Winset, AlwaysOnTop, Toggle, A
; Ctrl-Alt-R as a hotkey to restart the script.
^!r::Reload
; Ctrl-Alt-C to start console, use windows explorer's path when active
^!c::
If WinActive("ahk_class CabinetWClass")
{
path := Explorer_GetPath()
Run "C:\Program Files\ConEmu\ConEmu64.exe" /dir "%path%"
return
}
else
{
IfWinExist ahk_class VirtualConsoleClass
WinActivate
else
Run "C:\Program Files\ConEmu\ConEmu64.exe" /dir c:\gitdata
return
}
; visual studio
#IfWinActive, .* - Microsoft Visual Studio
; Ctrl-Alt-/ to remove and sort usings and format document
; note: you should manually assign ctrl-alt-/ as removeandsort shortcut
^!/::
Send ^!/ ; remove and sort usings
Send ^ed ; format document
return
; Ctrl-Click to go to definition
^LButton::Send {click}{f12}
#IfWinActive
/********************************************************************************************
LIBS
/********************************************************************************************/
; http://www.autohotkey.com/board/topic/60985-get-paths-of-selected-items-in-an-explorer-window/
/*
Library for getting info from a specific explorer window (if window handle not specified, the currently active
window will be used). Requires AHK_L or similar. Works with the desktop. Does not currently work with save
dialogs and such.
Explorer_GetSelected(hwnd="") - paths of target window's selected items
Explorer_GetAll(hwnd="") - paths of all items in the target window's folder
Explorer_GetPath(hwnd="") - path of target window's folder
example:
F1::
path := Explorer_GetPath()
all := Explorer_GetAll()
sel := Explorer_GetSelected()
MsgBox % path
MsgBox % all
MsgBox % sel
return
Joshua A. Kinnison
2011-04-27, 16:12
*/
Explorer_GetPath(hwnd="")
{
if !(window := Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
return A_Desktop
path := window.LocationURL
path := RegExReplace(path, "ftp://.*@","ftp://")
StringReplace, path, path, file:
StringReplace, path, path, ///
StringReplace, path, path, /, \, All
; thanks to polyethene
Loop
If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
Else Break
return path
}
Explorer_GetAll(hwnd="")
{
return Explorer_Get(hwnd)
}
Explorer_GetSelected(hwnd="")
{
return Explorer_Get(hwnd,true)
}
Explorer_GetWindow(hwnd="")
{
; thanks to jethrow for some pointers here
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process!="explorer.exe")
return
if (class ~= "(Cabinet|Explore)WClass")
{
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
return window
}
else if (class ~= "Progman|WorkerW")
return "desktop" ; desktop found
}
Explorer_Get(hwnd="",selection=false)
{
if !(window := Explorer_GetWindow(hwnd))
return ErrorLevel := "ERROR"
if (window="desktop")
{
ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
if !hwWindow ; #D mode
ControlGet, hwWindow, HWND,, SysListView321, A
ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
Loop, Parse, files, `n, `r
{
path := base "\" A_LoopField
IfExist %path% ; ignore special icons like Computer (at least for now)
ret .= path "`n"
}
}
else
{
if selection
collection := window.document.SelectedItems
else
collection := window.document.Folder.Items
for item in collection
ret .= item.path "`n"
}
return Trim(ret,"`n")
}