Skip to content

Instantly share code, notes, and snippets.

@i5ar
Forked from tmplinshi/KeypressOSD.ahk
Last active October 27, 2016 02:14
Show Gist options
  • Save i5ar/f8db473f22942d81b8fb3fe5d15f8201 to your computer and use it in GitHub Desktop.
Save i5ar/f8db473f22942d81b8fb3fe5d15f8201 to your computer and use it in GitHub Desktop.
Keypress On Screen Display
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
height="256"
width="256"
id="svg2"
xml:space="preserve"
enable-background="new 0 0 1000 1000"
viewBox="0 0 256 256"
y="0px"
x="0px"
version="1.1"><defs
id="defs12" /><metadata
id="metadata4"> Svg Vector Icons : http://www.onlinewebfonts.com/icon <rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><g
style="fill:#ffffff;fill-opacity:1;stroke-width:1.0158385;stroke-miterlimit:4;stroke-dasharray:none"
transform="matrix(4.0000002,0,0,4.0000002,-1.525879e-5,-31.992375)"
id="g4608"><g
style="fill:#ffffff;fill-opacity:1;stroke-width:1.0158385;stroke-miterlimit:4;stroke-dasharray:none"
id="g4595"><rect
y="32"
x="16"
height="15.996185"
width="15.999998"
id="rect4464"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="32"
x="31.999998"
height="15.996185"
width="15.999998"
id="rect4464-4"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="16.003815"
x="1.9073486e-006"
height="15.996185"
width="15.999998"
id="rect4464-4-4"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="16.003815"
x="16"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="32"
x="3.8146973e-006"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0-7"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="16.003815"
x="32"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0-7-5"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="16.003815"
x="48"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0-7-5-0"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="32"
x="48"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0-7-5-0-1"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
ry="0"
y="47.996185"
x="16"
height="15.996185"
width="32"
id="rect4464-8"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="47.996185"
x="3.8146973e-006"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0-7-0"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /><rect
y="47.996185"
x="48"
height="15.996185"
width="15.999998"
id="rect4464-4-4-0-7-5-0-1-6"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1.0158385;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /></g></g></svg>
; KeypressOSD.ahk
;----------------------------------------------------------
; ChangeLog : v2.05 (2016-10-01) - Fixed not detecting "Ctrl + ScrollLock/NumLock/Pause"
; v2.04 (2016-10-01) - Added NumpadDot and AppsKey
; v2.03 (2016-09-17) - Added displaying "Double-Click" of the left mouse button.
; v2.02 (2016-09-16) - Added displaying mouse button, and 3 settings (ShowMouseButton, FontSize, GuiHeight)
; v2.01 (2016-09-11) - Display non english keyboard layout characters when combine with modifer keys.
; v2.00 (2016-09-01) - Removed the "Fade out" effect because of its buggy.
; - Added support for non english keyboard layout.
; - Added GuiPosition setting.
; v1.00 (2013-10-11) - First release.
;----------------------------------------------------------
#SingleInstance force
#NoEnv
SetBatchLines, -1
ListLines, Off
; Settings
global TransN := 200 ; 0~255
global ShowSingleKey := True ; True or False
global ShowMouseButton := True ; True or False
global DisplayTime := 2000 ; In milliseconds
global GuiPosition := "Bottom" ; Top or Bottom
global FontSize := 24
global GuiHeight := 80
CreateGUI()
CreateHotkey()
return
OnKeyPressed:
try {
key := GetKeyStr()
ShowHotkey(key)
SetTimer, HideGUI, % -1 * DisplayTime
}
return
; ===================================================================================
CreateGUI() {
global
Gui, +AlwaysOnTop -Caption +Owner +LastFound +E0x20
Gui, Margin, 0, 0
Gui, Color, FFFFFF
Gui, Font, c000000 s%FontSize% bold, Arial
Gui, Add, Text, vHotkeyText Center y20
WinSet, Transparent, %TransN%
}
CreateHotkey() {
Loop, 64
Hotkey, % "~*" Chr(A_Index + 31), OnKeyPressed
Loop, 24 ; F1-F24
Hotkey, % "~*F" A_Index, OnKeyPressed
Loop, 10 ; Numpad0 - Numpad9
Hotkey, % "~*Numpad" A_Index - 1, OnKeyPressed
Otherkeys := "AppsKey|NumpadDot|NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|Tab|Enter|Esc|BackSpace"
. "|Del|Insert|Home|End|PgUp|PgDn|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|Pause|sc145|sc146|sc046"
Loop, parse, Otherkeys, |
Hotkey, % "~*" A_LoopField, OnKeyPressed
If ShowMouseButton {
Loop, Parse, % "LButton|MButton|RButton", |
Hotkey, % "~*" A_LoopField, OnKeyPressed
}
}
ShowHotkey(HotkeyStr) {
WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
if !ActWin_W
throw
text_w := ActWin_W
GuiControl, , HotkeyText, %HotkeyStr%
GuiControl, Move, HotkeyText, w%text_w% Center
if (GuiPosition = "Top")
gui_y := ActWin_Y
else
gui_y := (ActWin_Y+ActWin_H) - 115 - 50
Gui, Show, NoActivate x%ActWin_X% y%gui_y% h%GuiHeight% w%text_w%
}
GetKeyStr() {
static modifiers := ["Ctrl", "Shift", "Alt", "LWin", "RWin"]
for i, mod in modifiers {
if GetKeyState(mod)
prefix .= mod " + "
}
if (!prefix && !ShowSingleKey)
throw
key := SubStr(A_ThisHotkey, 3)
if (key = " ") {
key := "Space"
} else if ( StrLen(key) = 1 ) {
key := GetKeyChar(key, "A")
} else if ( SubStr(key, 1, 2) = "sc" ) {
key := SpecialSC(key)
} else if (key = "LButton") && IsDoubleClick() {
key := "Double-Click"
}
return prefix . key
}
SpecialSC(sc) {
static k := {sc046: "ScrollLock", sc145: "NumLock", sc146: "Pause"}
return k[sc]
}
; https://autohotkey.com/board/topic/110808-getkeyname-for-other-languages/#entry682236
GetKeyChar(Key, WinTitle:=0) {
thread := WinTitle=0 ? 0
: DllCall("GetWindowThreadProcessId", "ptr", WinExist(WinTitle), "ptr", 0)
hkl := DllCall("GetKeyboardLayout", "uint", thread, "ptr")
vk := GetKeyVK(Key), sc := GetKeySC(Key)
VarSetCapacity(state, 256, 0)
VarSetCapacity(char, 4, 0)
n := DllCall("ToUnicodeEx", "uint", vk, "uint", sc
, "ptr", &state, "ptr", &char, "int", 2, "uint", 0, "ptr", hkl)
return StrGet(&char, n, "utf-16")
}
; http://msdn.microsoft.com/en-us/library/dd318693%28v=vs.85%29.aspx
; it := DllCall("LoadKeyboardLayout", "Str", "00000410", "Int", 1)
IsDoubleClick(MSec = 300) {
Return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey < MSec)
}
HideGUI() {
Gui, Hide
}
; Startup.ahk
;------------------------------------------------------------------------------
; Startup directory: "C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
;------------------------------------------------------------------------------
; Open Keypress On Screen Display "Ctrl-Shift-k"
^+k::Run "D:\Program Files\AutoHotkey\iSar\KeypressOSD\KeypressOSD.exe"
@i5ar
Copy link
Author

i5ar commented Oct 18, 2016

Executable:

Ahk2Exe.exe /in KeypressOSD.ahk /icon Keyboard.ico

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment