-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetLastPressedKey.ahk
124 lines (95 loc) · 2.7 KB
/
GetLastPressedKey.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
; KeypressOSD.ahk
;----------------------------------------------------------
; KeypressOSD v1.00
; Author : tmplinshi
; Date : 2013-10-11
; Tested on : Windows XP SP3 / AutoHotkey v1.1.13.00
; Thanks : HotShow.ahk by RaptorX (http://www.autohotkey.com/board/topic/51641-hotshow-10-osd-hotkeys-for-video-tutorials/)
;----------------------------------------------------------
#SingleInstance force
#NoEnv
SetBatchLines, -1
ListLines, Off
; #################################
; Settings
; #################################
;
transN := 200
ShowSingleKey := True
DisplayTime := 2000
; #################################
; Create GUI
; #################################
;
Gui, +AlwaysOnTop -Caption +Owner +LastFound +E0x20
Gui, Margin, 0, 0
Gui, Color, Black
Gui, Font, cWhite s50 bold, Arial
Gui, Add, Text, vHotkeyText Center y20
WinSet, Transparent, %transN%
; #################################
; Create hotkey
; #################################
;
Loop, 95
Hotkey, % "~*" Chr(A_Index + 31), Display
Loop, 24 ; F1-F24
Hotkey, % "~*F" A_Index, Display
Loop, 10 ; Numpad0 - Numpad9
Hotkey, % "~*Numpad" A_Index - 1, Display
Otherkeys := "NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|Tab|Enter|Esc|BackSpace|Del|Insert|Home|End|PgUp|PgDn|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|Pause"
Loop, parse, Otherkeys, |
Hotkey, % "~*" A_LoopField, Display
return
^!MButton::ShowSingleKey := !ShowSingleKey ; Toggle ShowSingleKey
; #################################
; Display
; #################################
;
Display:
If (A_ThisHotkey = "")
Return
mods := "Ctrl|Shift|Alt|LWin|RWin"
prefix := ""
Loop, Parse, mods, |
if GetKeyState(A_LoopField)
prefix .= A_LoopField " + "
if (!prefix && !ShowSingleKey)
return
key := SubStr(A_ThisHotkey, 3)
if (key = " ")
key := "Space"
if ( ShowHotkey(prefix key) = "Error" )
Return
NewHotkeyPressed := True
SetTimer, FadeOut, -1
Return
FadeOut:
Gui, +LastFound
Loop
{
NewHotkeyPressed := False
WinSet, Transparent, % transN
Sleep, %DisplayTime%
Loop, % transN
{
if NewHotkeyPressed
Break
WinSet, Transparent, % (A_Index - transN) * -1
}
if !NewHotkeyPressed
Break
}
Gui, Hide
Return
; ===================================================================================
ShowHotkey(Hotkey)
{
GuiControl,, HotkeyText, %Hotkey%
WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
if !ActWin_W
Return "Error"
text_w := ActWin_W, gui_y := (ActWin_Y+ActWin_H) - 115 - 50
GuiControl, Move, HotkeyText, w%text_w% Center
Gui, Show, NoActivate x%ActWin_X% y%gui_y% h115 w%text_w%
}