aboutsummaryrefslogtreecommitdiff
path: root/tiny/cfg.ahk
blob: 12be889ee5402e0b75efa5226e6af9dbf9203c2d (plain)
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
#SingleInstance Force
#Persistent

;; Initialization.
ShellApp := ComObjCreate("Shell.Application")
us := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)
jp := DllCall("LoadKeyboardLayout", "Str", "00000411", "Int", 1)
;; ru := DllCall("LoadKeyboardLayout", "Str", "00000419", "Int", 1)
;; sv := DllCall("LoadKeyboardLayout", "Str", "0000041D", "Int", 1)

Menu, Tray, Tip, Cfg
Menu, Tray, Icon, shell32.dll, 105

GroupAdd, Explorer, ahk_class CabinetWClass
GroupAdd, Explorer, ahk_class ExploreWClass
GroupAdd, Desktop, ahk_class Progman
GroupAdd, Desktop, ahk_class WorkerW

Gui +LastFound
DllCall("RegisterShellHookWindow", UInt, WinExist())
msg := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
OnMessage(msg, "FixZ")
return

;; Fix z-order after minimization.
FixZ(wParam, lParam){
	static HSHELL_GETMINRECT := 5
	static HWND_BOTTOM := 1
	static SWP_NOSIZE := 0x0001
	static SWP_NOMOVE := 0x0002
	static SWP_ASYNCWINDOWPOS := 0x4000
	if(wParam = HSHELL_GETMINRECT and WinActive("A") = 0){
		hwnd := NumGet(lParam + 0)
		WinWaitNotActive, ahk_id 0 ; Wait until end of minimization.
		Sleep, 20
		DllCall("SetWindowPos", "UInt", hwnd, "UInt", HWND_BOTTOM
			, "Int", 0, "Int", 0, "Int", 0, "Int", 0
			, "UInt", SWP_NOSIZE | SWP_NOMOVE | SWP_ASYNCWINDOWPOS)
	}
}

;; Window management hotkeys.
#o::WinSet, AlwaysOnTop, Toggle, A
#z::WinMinimize, A

;; Command prompt hotkeys.
#IfWinActive ahk_group Explorer
^p::
WinGet, hwnd, id, A
for window in ShellApp.Windows
	if (window.hwnd = hwnd)
		window.Document.Application.ShellExecute("cmd"
			, "/k cd /d """ window.Document.Folder.Self.path """")

return
#IfWinActive ahk_class ConsoleWindowClass
!F4::WinClose, A
#IfWinActive

;; Volume hotkeys.
RAlt & F6::SetVolume(GetKeyState("Shift") ? 2 : 1)
RAlt & F5::SetVolume(GetKeyState("Shift") ? -2 : -1)
SetVolume(n){
	SoundGet, s
	s := round(s) + n
	if (s > 100)
		s := 100
	if (s < 0)
		s := 0
	SoundSet, %s%
	ToolTip, %s%
	SetTimer, RemoveToolTip, -100
}
RemoveToolTip:
ToolTip
return

;; Toggle keyboard layout.
^\::
<^>!^SC00C::
if(Layout() == us)
	new := jp
else
	new := us
DllCall("SendMessage", "UInt", WinActive("A"), "UInt", 80, "UInt", 1, "UInt", new)
return
Layout(){
	f := A_FormatInteger
	SetFormat, Integer, H
	if (hwnd = "")
		WinGet, hwnd, id, A
	thread := DllCall("GetWindowThreadProcessId", "UInt",hwnd, "UInt",0)
	layout := DllCall("user32.dll\GetKeyboardLayout", "UInt",thread, "UInt")
	SetFormat, Integer, %f%
	return layout
}

;; Extra keys.
#If Layout() == us && !WinActive("ahk_exe VirtualBoxVM.exe")
:z*?:aa::
:z*?:ae::
:z*?:oe::
:z*?:AA::
:z*?:AE::
:z*?:OE::
:z*?:a``::
:z*?:e``::
:z*?:A``::
:z*?:E``::
>!a::SendInput, a
>!e::SendInput, e
>!+a::SendInput, A
>!+e::SendInput, E
#If