Mostrador de teclas pulsadas

Esta sección es para preguntas sobre programación/scripting usando AutoHotkey.
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Mostrador de teclas pulsadas

10 Oct 2018, 07:30

Hola Flipeador se podría algo parecido a Replay Hub en AutoHotkey.

cuando estés pulsando una tecla se muestre en pantalla la tecla que estás pulsando .

ejemplo pulso la A y en pantalla aparezca la A.

No se por dónde empezar hacer lo
No me burlo de los novatos,porque de ellos vengo
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Mostrador de teclas pulsadas

10 Oct 2018, 07:42

Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:03

Bertíni ---> Si algo así ahora tendré que hacer unos retoques para que sea más pequeño
No me burlo de los novatos,porque de ellos vengo
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:12

Ya hice unos cambios de tamaño de letra pero ahora no se como editar la banda negra o gris para que no tome todo la pantalla y solo tomo un tamaño pequeño.
Estoy mirando a ver si puedo reducirla y gracias Flipeador.

No se si puedo poner el código acá.
No me burlo de los novatos,porque de ellos vengo
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:19

Puedes poner el código que quieras, pero no puedo probar nada sino hasta el fin de semana.
Por cierto, por qué pones tu nombre de usuario y una flecha en cada párrafo, es completamente innecesario.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:26

Puedes poner el código que quieras, pero no puedo probar nada sino hasta el fin de semana.
Por cierto, por qué pones tu nombre de usuario y una flecha en cada párrafo, es completamente innecesario.
A vale ahora ya no lo pondré más

Code: Select all


; KeypressOSD v2.52 (2018-05-22)

#NoEnv
#SingleInstance force
#MaxHotkeysPerInterval 200
#KeyHistory 0
ListLines, Off
SetBatchLines, -1

global appVersion := "v2.52"
global AutoGuiW, BkColor, Bottom_OffsetX, Bottom_OffsetY, Bottom_Screen, Bottom_Win, DisplaySec, FixedX, FixedY
     , FontColor, FontName, FontSize, FontStyle, GuiHeight, GuiPosition, GuiWidth, SettingsGuiIsOpen
     , ShowModifierKeyCount, ShowMouseButton, ShowSingleKey, ShowSingleModifierKey, ShowStickyModKeyCount
     , Top_OffsetX, Top_OffsetY, Top_Screen, Top_Win, TransN
     , oLast := {}, hGui_OSD, hGUI_s

ReadSettings()
CreateTrayMenu()
CreateGUI()
CreateHotkey()
return

F7::ExitApp ; Deja de ejecutar el programa
F8::Reload ; Renicia el programa

#if !SettingsGuiIsOpen
	OnKeyPressed:
		try {
			key := GetKeyStr()
			ShowHotkey(key)
			SetTimer, HideGUI, % -1 * DisplaySec * 1000
		}
	return

	OnKeyUp:
	return

	_OnKeyUp:
		tickcount_start := A_TickCount
	return

; ===================================================================================
CreateGUI() {
	global

	Gui, +AlwaysOnTop -Caption +Owner +LastFound +E0x20 +HWNDhGui_OSD
	Gui, Margin, 0, 0
	Gui, Color, %BkColor%
	Gui, Font, c%FontColor% %FontStyle% s%FontSize%, %FontName%
	Gui, Add, Text, vHotkeyText Center y20

	WinSet, Transparent, %TransN%
}

CreateHotkey() {
	Loop, 95
	{
		k := Chr(A_Index + 31)
		k := (k = " ") ? "Space" : k

		Hotkey, % "~*" k, OnKeyPressed
		Hotkey, % "~*" k " Up", _OnKeyUp
	}

	Loop, 24 ; F1-F24
	{
		Hotkey, % "~*F" A_Index, OnKeyPressed
		Hotkey, % "~*F" A_Index " Up", _OnKeyUp
	}

	Loop, 10 ; Numpad0 - Numpad9
	{
		Hotkey, % "~*Numpad" A_Index - 1, OnKeyPressed
		Hotkey, % "~*Numpad" A_Index - 1 " Up", _OnKeyUp
	}

	Otherkeys := "WheelDown|WheelUp|WheelLeft|WheelRight|XButton1|XButton2|Browser_Forward|Browser_Back|Browser_Refresh|Browser_Stop|Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2|Help|Sleep|PrintScreen|CtrlBreak|Break|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|sc123"
	Loop, parse, Otherkeys, |
	{
		Hotkey, % "~*" A_LoopField, OnKeyPressed
		Hotkey, % "~*" A_LoopField " Up", _OnKeyUp
	}

	If ShowMouseButton {
		Loop, Parse, % "LButton|MButton|RButton", |
			Hotkey, % "~*" A_LoopField, OnKeyPressed
	}

	for i, mod in ["Ctrl", "Shift", "Alt"] {
		Hotkey, % "~*" mod, OnKeyPressed
		Hotkey, % "~*" mod " Up", OnKeyUp
	}
	for i, mod in ["LWin", "RWin"]
		Hotkey, % "~*" mod, OnKeyPressed
}

MouseHotkey_On() {
	Loop, Parse, % "LButton|MButton|RButton", |
		Hotkey, % "~*" A_LoopField, On, UseErrorLevel
}

MouseHotkey_Off() {
	Loop, Parse, % "LButton|MButton|RButton", |
		Hotkey, % "~*" A_LoopField, Off, UseErrorLevel
}

ShowHotkey(HotkeyStr) {
	if SettingsGuiIsOpen {
		ActWin_X := ActWin_Y := 0
		ActWin_W := A_ScreenWidth
		ActWin_H := A_ScreenHeight
	} else {
		WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
		if !ActWin_W
			throw
	}

	text_w := AutoGuiW ? ActWin_W : GuiWidth
	if (HotkeyStr != oLast.HotkeyStr) {
		GuiControl, 1:, HotkeyText, %HotkeyStr%
		oLast.HotkeyStr := HotkeyStr
		changed := true
	}

	ctrlSize = w%text_w% h%GuiHeight%
	; ToolTip, % obj_print(oLast) "`n`n" ctrlSize "`n" oLast.ctrlSize
	if (ctrlSize != oLast.ctrlSize) {
		GuiControl, 1:Move, HotkeyText, x0 y0 %ctrlSize%
		GuiControl, +0x201, HotkeyText
		oLast.ctrlSize := ctrlSize
		changed := true
	}

	if (GuiPosition = "Fixed Position")
	{
		gui_x := FixedX
		gui_y := FixedY
	}
	else
	{
		if (GuiPosition = "Top" && Top_Screen)
		|| (GuiPosition = "Bottom" && Bottom_Screen)
		{
			ActWin_X := ActWin_Y := 0
			ActWin_W := A_ScreenWidth
			ActWin_H := A_ScreenHeight
		}

		if (GuiPosition = "Top")
		{
			gui_x := ActWin_X + Top_OffsetX
			gui_y := ActWin_Y + Top_OffsetY
		}
		else if (GuiPosition = "Bottom")
		{
			gui_x := ActWin_X + Bottom_OffsetX
			gui_y := (ActWin_Y+ActWin_H) - GuiHeight - Bottom_OffsetY
		}
	}
	

	guiPos = x%gui_x% y%gui_y%
	if (guiPos != oLast.guiPos || changed) {
		Gui, 1:Show, NoActivate %guiPos% %ctrlSize%
		oLast.guiPos := guiPos
		; ToolTip, updated! %a_now%

		; static n := 0
		; n += 1
		; ToolTip, % HotkeyStr " " n "`n" guiPos
	} else {
		; ToolTip, % "why?`n" obj_print(oLast) "`n`n" ctrlSize "`n" oLast.ctrlSize
	}
}

GetKeyStr() {
	static modifiers := ["Ctrl", "Shift", "Alt", "LWin", "RWin"]
	static repeatCount := 1

	for i, mod in modifiers {
		if GetKeyState(mod)
			prefix .= mod " + "
	}

	if (!prefix && !ShowSingleKey)
		throw

	key := SubStr(A_ThisHotkey, 3)

	if (key ~= "i)^(Ctrl|Shift|Alt|LWin|RWin)$") {
		if !ShowSingleModifierKey {
			throw
		}
		key := ""
		prefix := RTrim(prefix, "+ ")

		if ShowModifierKeyCount {
			if !InStr(prefix, "+") && IsDoubleClickEx() {
				if (A_ThisHotKey != A_PriorHotKey) || ShowStickyModKeyCount {
					if (++repeatCount > 1) {
						prefix .= " ( * " repeatCount " )"
					}
				} else {
					repeatCount := 0
				}
			} else {
				repeatCount := 1
			}
		}
	} 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"
		}
		_key := (key = "Double-Click") ? "LButton" : key

		static pre_prefix, pre_key, keyCount := 1
		global tickcount_start
		if (prefix && pre_prefix) && (A_TickCount-tickcount_start < 300) {
			if (prefix != pre_prefix) {
				result := pre_prefix pre_key ", " prefix key
			} else {
				keyCount := (key=pre_key) ? (keyCount+1) : 1
				key := (keyCount>2) ? (key " (" keyCount ")") : (pre_key ", " key)
			}
		} else {
			keyCount := 1
		}

		pre_prefix := prefix
		pre_key := _key

		repeatCount := 1
	}
	return result ? result : prefix . key
}

SpecialSC(sc) {
	static k := {sc046: "ScrollLock", sc145: "NumLock", sc146: "Pause", sc123: "Genius LuxeMate Scroll"}
	return k[sc]
}

; by Lexikos -- 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")
}

IsDoubleClick(MSec = 300) {
	Return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey < MSec)
}

IsDoubleClickEx(MSec = 300) {
	preHotkey := RegExReplace(A_PriorHotkey, "i) Up$")
	Return (A_ThisHotKey = preHotkey) && (A_TimeSincePriorHotkey < MSec)
}

HideGUI() {
	if !SettingsGuiIsOpen {
		Gui, Hide
	}
	oLast := {}
}

; -------------------------------------------------------------------

ReadSettings() {
	IniFile := SubStr(A_ScriptFullPath, 1, -4) ".ini"

	IniRead, TransN               , %IniFile%, Settings, TransN               , 100
	IniRead, ShowSingleKey        , %IniFile%, Settings, ShowSingleKey        , 1
	IniRead, ShowMouseButton      , %IniFile%, Settings, ShowMouseButton      , 1
	IniRead, ShowSingleModifierKey, %IniFile%, Settings, ShowSingleModifierKey, 1
	IniRead, ShowModifierKeyCount , %IniFile%, Settings, ShowModifierKeyCount , 1
	IniRead, ShowStickyModKeyCount, %IniFile%, Settings, ShowStickyModKeyCount, 0
	IniRead, DisplaySec           , %IniFile%, Settings, DisplaySec           , 1
	IniRead, GuiPosition          , %IniFile%, Settings, GuiPosition          , Bottom
	IniRead, FontSize             , %IniFile%, Settings, FontSize             , 50
	IniRead, GuiWidth             , %IniFile%, Settings, GuiWidth             , %A_ScreenWidth%
	IniRead, GuiHeight            , %IniFile%, Settings, GuiHeight            , 115
	IniRead, BkColor              , %IniFile%, Settings, BkColor              , Black
	IniRead, FontColor            , %IniFile%, Settings, FontColor            , white
	IniRead, FontStyle            , %IniFile%, Settings, FontStyle            , w700
	IniRead, FontName             , %IniFile%, Settings, FontName             , Arial
	IniRead, AutoGuiW             , %IniFile%, Settings, AutoGuiW             , 1
	IniRead, Bottom_Win           , %IniFile%, Settings, Bottom_Win           , 1
	IniRead, Bottom_Screen        , %IniFile%, Settings, Bottom_Screen        , 0
	IniRead, Bottom_OffsetX       , %IniFile%, Settings, Bottom_OffsetX       , 0
	IniRead, Bottom_OffsetY       , %IniFile%, Settings, Bottom_OffsetY       , 50
	IniRead, Top_Win              , %IniFile%, Settings, Top_Win              , 1
	IniRead, Top_Screen           , %IniFile%, Settings, Top_Screen           , 0
	IniRead, Top_OffsetX          , %IniFile%, Settings, Top_OffsetX          , 0
	IniRead, Top_OffsetY          , %IniFile%, Settings, Top_OffsetY          , 0
	IniRead, FixedX               , %IniFile%, Settings, FixedX               , 100
	IniRead, FixedY               , %IniFile%, Settings, FixedY               , 200
}

SaveSettings() {
	IniFile := SubStr(A_ScriptFullPath, 1, -4) ".ini"

	IniWrite, %TransN%               , %IniFile%, Settings, TransN
	IniWrite, %ShowSingleKey%        , %IniFile%, Settings, ShowSingleKey
	IniWrite, %ShowMouseButton%      , %IniFile%, Settings, ShowMouseButton
	IniWrite, %ShowSingleModifierKey%, %IniFile%, Settings, ShowSingleModifierKey
	IniWrite, %ShowModifierKeyCount% , %IniFile%, Settings, ShowModifierKeyCount
	IniWrite, %ShowStickyModKeyCount%, %IniFile%, Settings, ShowStickyModKeyCount
	IniWrite, %DisplaySec%           , %IniFile%, Settings, DisplaySec
	IniWrite, %GuiPosition%          , %IniFile%, Settings, GuiPosition
	IniWrite, %FontSize%             , %IniFile%, Settings, FontSize
	IniWrite, %GuiWidth%             , %IniFile%, Settings, GuiWidth
	IniWrite, %GuiHeight%            , %IniFile%, Settings, GuiHeight
	IniWrite, %BkColor%              , %IniFile%, Settings, BkColor
	IniWrite, %FontColor%            , %IniFile%, Settings, FontColor
	IniWrite, %FontStyle%            , %IniFile%, Settings, FontStyle
	IniWrite, %FontName%             , %IniFile%, Settings, FontName
	IniWrite, %AutoGuiW%             , %IniFile%, Settings, AutoGuiW
	IniWrite, %Bottom_Win%           , %IniFile%, Settings, Bottom_Win
	IniWrite, %Bottom_Screen%        , %IniFile%, Settings, Bottom_Screen
	IniWrite, %Bottom_OffsetX%       , %IniFile%, Settings, Bottom_OffsetX
	IniWrite, %Bottom_OffsetY%       , %IniFile%, Settings, Bottom_OffsetY
	IniWrite, %Top_Win%              , %IniFile%, Settings, Top_Win
	IniWrite, %Top_Screen%           , %IniFile%, Settings, Top_Screen
	IniWrite, %Top_OffsetX%          , %IniFile%, Settings, Top_OffsetX
	IniWrite, %Top_OffsetY%          , %IniFile%, Settings, Top_OffsetY
	IniWrite, %FixedX%               , %IniFile%, Settings, FixedX
	IniWrite, %FixedY%               , %IniFile%, Settings, FixedY
}

CreateTrayMenu() {
	Menu, Tray, NoStandard
	Menu, Tray, Add, Settings, ShowSettingsGUI
	Menu, Tray, Add, Suspend, ToggleSuspend
	Menu, Tray, Add, About, ShowAboutGUI
	Menu, Tray, Add
	Menu, Tray, Add, Exit, _ExitApp
	Menu, Tray, Default, Settings
	Menu, Tray, Tip, KeypressOSD
}

ToggleSuspend() {
	Suspend, Toggle
	Menu, Tray, ToggleCheck, Suspend
	Menu, Tray, Tip, % "KeypressOSD" (A_IsSuspended ? " - Suspended" : "")
}

ShowAboutGUI() {
	Gui, a:Font, s12 bold
	Gui, a:Add, Text, , KeypressOSD %appVersion%
	Gui, a:Add, Link, gOpenUrl, <a>https://github.com/tmplinshi/KeypressOSD</a>
	Gui, a:Show,, About
	Return

	OpenUrl:
		Run, https://github.com/tmplinshi/KeypressOSD
	return
}

_ExitApp() {
	ExitApp
}

sGuiAddTitleText(text) {
	Gui, s:Font, s16
	Gui, s:Add, Text, xm y+20, %text%
	Gui, s:Font, s12
}

ShowSettingsGUI() {
	global

	SettingsGuiIsOpen := true

	Gui, s:Destroy
	Gui, s:+HWNDhGUI_s
	Gui, s:Font, s12

	Gui, s:Add, Text, xm, Transparency:
	Gui, s:Add, Text, x+10 w100 vTransNVal, %TransN%
	Gui, s:Add, Slider, xm+10 vTransN Range0-255 ToolTip gUpdateTransVal, %TransN%


	Gui, s:Add, Text, xm, Display
	Gui, s:Add, Edit, x+10 w80 Center vDisplaySec, %DisplaySec%
	Gui, s:Add, Text, x+10, Seconds

	Gui, s:Add, Checkbox, xm h24 vShowSingleKey Checked%ShowSingleKey%, Show Single Key
	Gui, s:Add, Checkbox, xm h24 vShowMouseButton Checked%ShowMouseButton%, Show Mouse Button
	Gui, s:Add, Checkbox, xm h24 vShowSingleModifierKey Checked%ShowSingleModifierKey%, Show Single Modifier Key
	Gui, s:Add, Checkbox, xm h24 vShowModifierKeyCount Checked%ShowModifierKeyCount%, Show Modifier Key Count
	Gui, s:Add, Checkbox, xm h24 vShowStickyModKeyCount Checked%ShowStickyModKeyCount%, Show Sticky Modifier Key Count

	sGuiAddTitleText("Window Position")
		Gui, s:Add, Tab3, xm y+10 Buttons vGuiPosition gUpdateGuiPosition, Bottom|Top|Fixed Position
		GuiControl, s:ChooseString, GuiPosition, |%GuiPosition%
		Gui, s:Tab, 1
			Gui, s:Add, Text, Section y+20, Relative To:
			Gui, s:Add, Radio, x+10 vBottom_Win Checked%Bottom_Win%, Active Window
			Gui, s:Add, Radio, x+20 vBottom_Screen Checked%Bottom_Screen%, Screen
			Gui, s:Add, Text, xs y+20, OffsetX
			Gui, s:Add, Edit, x+10 w80 vBottom_OffsetX Number gUpdateOSD, %Bottom_OffsetX%
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %Bottom_OffsetX%
			Gui, s:Add, Text, x+50, OffsetY
			Gui, s:Add, Edit, x+10 w80 vBottom_OffsetY Number gUpdateOSD, %Bottom_OffsetY%
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %Bottom_OffsetY%
		Gui, s:Tab, 2
			Gui, s:Add, Text, Section y+20, Relative To:
			Gui, s:Add, Radio, x+10 vTop_Win Checked%Top_Win%, Active Window
			Gui, s:Add, Radio, x+20 vTop_Screen Checked%Top_Screen%, Screen
			Gui, s:Add, Text, xs y+20, OffsetX
			Gui, s:Add, Edit, x+10 w80 vTop_OffsetX Number gUpdateOSD, 
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %Top_OffsetX%
			Gui, s:Add, Text, x+50, OffsetY
			Gui, s:Add, Edit, x+10 w80 vTop_OffsetY Number gUpdateOSD, 
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %Top_OffsetY%
		Gui, s:Tab, 3
			Gui, s:Add, Text, y+20, X
			Gui, s:Add, Edit, x+10 w80 vFixedX Number gUpdateOSD, %FixedX%
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %FixedX%
			Gui, s:Add, Text, x+50, Y
			Gui, s:Add, Edit, x+10 w80 vFixedY Number gUpdateOSD, %FixedY%
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %FixedY%
			Gui, s:Font, s10
			Gui, s:Add, Text, xs cGray, Input or drag the OSD window.
			Gui, s:Font, s12
		Gui, s:Tab

	sGuiAddTitleText("Window Size")
		Gui, s:Add, Text, xm, % " Width:"

		Gui, s:Add, Edit, x+10 w85 Center Number vGuiWidth gUpdateGuiWidth, %GuiWidth%
		Gui, s:Add, UpDown, Range10-4000 gUpdateGuiWidth 0x80 vGuiWUD, %GuiWidth%
		Gui, s:Add, Checkbox, x+30 vAutoGuiW Checked%AutoGuiW% g_AutoGuiW, Same As Active Window
		Gosub, _AutoGuiW

		Gui, s:Add, Text, xm, Height:
		Gui, s:Add, Edit, x+10 w85 Number Center vGuiHeight gUpdateGuiHeight, %GuiHeight%
		Gui, s:Add, UpDown, Range5-2000 gUpdateGuiHeight 0x80, %GuiHeight%

	Gui, s:Add, Button, xm y+20 gChangeBkColor, Change Background Color

	Gui, s:Add, Button, xm gChangeFont, Change Font
	Gui, s:Add, Button, x+50 gChangeFontColor, Change Font Color

	Gui, s:Add, Text, xm, Font Size:
	Gui, s:Add, Edit, x+10 w100 Number Center vFontSize gUpdateFontSize, %FontSize%
	Gui, s:Add, UpDown, Range1-1000 gUpdateFontSize 0x80, %fontSize%

	if (GuiPosition = "Fixed Position")
		OSD_EnableDrag()
	Gui, s:Show,, Settings - KeypressOSD

	ShowHotkey("KeypressOSD")
	SetTimer, HideGUI, Off
	return

	UpdateOSD:
		Gui, Submit, NoHide
		Gosub, _CheckValues
		ShowHotkey("KeypressOSD")
	return

	_CheckValues:
		Loop, Parse, % "Bottom_OffsetX,Bottom_OffsetY,Top_OffsetX,Top_OffsetY,FixedX,FixedY", `,
		{
			if (%A_LoopField% = "") {
				%A_LoopField% := 0
			}
		}
	return

	_AutoGuiW:
		; GuiControlGet, AutoGuiW, s:
		Gui, Submit, NoHide
		GuiControl, % "s:Enable" !AutoGuiW, GuiWidth
		GuiControl, % "s:Enable" !AutoGuiW, GuiWUD
		ShowHotkey("KeypressOSD")
		GuiControl, 1:+Redraw, HotkeyText
	return

	UpdateGuiPosition:
		oLast := {}
		Gui, Submit, NoHide
		ShowHotkey("KeypressOSD")

		if (GuiPosition = "Fixed Position")
			OSD_EnableDrag()
		else
			OSD_DisableDrag()
	return

	UpdateGuiWidth:
		GuiControlGet, newW,, GuiWidth
		if newW {
			GuiWidth := newW
			ShowHotkey("KeypressOSD")
		}
	return

	UpdateGuiHeight:
		GuiControlGet, newH,, GuiHeight
		if newH {
			GuiHeight := newH
			ShowHotkey("KeypressOSD")
		}
	return

	UpdateTransVal:
		GuiControlGet, TransN
		GuiControl,, TransNVal, % TransN

		Gui, 1:+LastFound
		WinSet, Transparent, %TransN%
	return

	UpdateFontSize:
		GuiControlGet, FontSize
		Gui, 1:Font, s%FontSize%
		GuiControl, 1:Font, HotkeyText
	return

	sGuiClose:
	sGuiEscape:
		FontSize_pre := FontSize

		Gui, s:Submit
		Gosub, _CheckValues

		ShowMouseButton ? MouseHotkey_On() : MouseHotkey_Off()

		if (FontSize_pre != FontSize) {
			Gui, 1:Font, s%FontSize%
			GuiControl, 1:Font, HotkeyText
		}

		if !GuiHeight
			GuiHeight := 115

		SaveSettings()
		Gui, s:Destroy
		Gui, 1:Hide
		OSD_DisableDrag()
		SettingsGuiIsOpen := ""
	return

	ChangeBkColor:
		newColor := BkColor
		if Select_Color(hGUI_s, newColor) {
			Gui, 1:Color, %newColor%
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
			BkColor := newColor
		}
	return

	ChangeFontColor:
		newColor := FontColor
		if Select_Color(hGUI_s, newColor) {
			Gui, 1:Font, c%newColor%
			GuiControl, 1:Font, HotkeyText
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
			FontColor := newColor
		}
	return

	ChangeFont:
		fStyle := FontStyle " s" FontSize
		fName  := FontName
		fColor := FontColor

		if Select_Font(hGUI_s, fStyle, fName, fColor) {
			FontStyle := fStyle
			FontName := fName
			FontColor := fColor
			if RegExMatch(FontStyle, "\bs\K\d+", FontSize) {
				FontStyle := RegExReplace(FontStyle, "\bs\d+")
				GuiControl,, FontSize, %FontSize%
			}

			Gui, 1:Font
			Gui, 1:Font, %fStyle% c%FontColor%, %fName%
			GuiControl, 1:Font, HotkeyText
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
		}
	return
}


WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	static hCursor := DllCall("LoadCursor", "Uint", 0, "Int", 32646, "Ptr") ; SizeAll = 32646

	if (hwnd = hGui_OSD) {
		PostMessage, 0xA1, 2
		DllCall("SetCursor", "ptr", hCursor)
	}
}

WM_MOVE(wParam, lParam, msg, hwnd) {
	if (hwnd = hGui_OSD) && GetKeyState("LButton", "P")
	{
		GuiControl, s:, FixedX, % lParam << 48 >> 48
		GuiControl, s:, FixedY, % lParam << 32 >> 48
	}
}

OSD_EnableDrag() {
	OnMessage(0x0201, "WM_LBUTTONDOWN")
	OnMessage(0x0003, "WM_MOVE")
	Gui, 1:-E0x20
}

OSD_DisableDrag() {
	OnMessage(0x0201, "")
	OnMessage(0x0003, "")
	Gui, 1:+E0x20
}


; https://autohotkey.com/boards/viewtopic.php?p=112730#p112730
;-------------------------------------------------------------------------------
Select_Font(hGui, ByRef Style, ByRef Name, ByRef Color) { ; using comdlg32.dll
;-------------------------------------------------------------------------------
    static SubKey := "SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI"


    ;-----------------------------------
    ; LOGFONT structure
    ;-----------------------------------
    VarSetCapacity(LOGFONT, 128, 0)

    If RegExMatch(Style, "s\K\d+", s) {
        RegRead, LogPixels, HKLM, %SubKey%, LogPixels
        NumPut(s * LogPixels // 72, LOGFONT, 0, "Int")
    }

    If RegExMatch(Style, "w\K\d+", w)
        NumPut(w, LOGFONT, 16, "Int")

    If InStr(Style, "italic")
        NumPut(255, LOGFONT, 20, "Int")

    If InStr(Style, "underline")
        NumPut(1, LOGFONT, 21, "Int")

    If InStr(Style, "strikeout")
        NumPut(1, LOGFONT, 22, "Int")

    StrPut(Name, &LOGFONT + 28, StrLen(Name) + 1)


    ;-----------------------------------
    ; CHOOSEFONT structure
    ;-----------------------------------

    ; CHOOSEFONT structure expects text color in BGR format
    BGR := convert_Color(Color)

    If (A_PtrSize = 8) { ; 64 bit
        VarSetCapacity(CHOOSEFONT, 104, 0)
        NumPut(     104, CHOOSEFONT,  0, "UInt") ; StructSize
        NumPut(    hGui, CHOOSEFONT,  8, "UInt") ; hwndOwner
        NumPut(&LOGFONT, CHOOSEFONT, 24, "UInt") ; lpLogFont
        NumPut(   0x141, CHOOSEFONT, 36, "UInt") ; Flags
        NumPut(     BGR, CHOOSEFONT, 40, "UInt") ; bgrColor
    }

    Else { ; 32 bit
        VarSetCapacity(CHOOSEFONT, 60, 0)
        NumPut(      60, CHOOSEFONT,  0, "UInt") ; StructSize
        NumPut(    hGui, CHOOSEFONT,  4, "UInt") ; hwndOwner
        NumPut(&LOGFONT, CHOOSEFONT, 12, "UInt") ; lpLogFont
        NumPut(   0x141, CHOOSEFONT, 20, "UInt") ; Flags
        NumPut(     BGR, CHOOSEFONT, 24, "UInt") ; bgrColor
    }


    ;-----------------------------------
    ; call ChooseFont function
    ;-----------------------------------
    FuncName := "comdlg32\ChooseFont" (A_IsUnicode ? "W" : "A")
    If Not DllCall(FuncName, "UInt", &CHOOSEFONT)
        Return, False


    ;-----------------------------------
    ; results to return
    ;-----------------------------------

    ; style
    Style := "s" NumGet(CHOOSEFONT, A_PtrSize = 8 ? 32 : 16, "Int") // 10
    Style .= " w" NumGet(LOGFONT, 16)
    If NumGet(LOGFONT, 20, "UChar")
        Style .= " italic"
    If NumGet(LOGFONT, 21, "UChar")
        Style .= " underline"
    If NumGet(LOGFONT, 22, "UChar")
        Style .= " strikeout"

    ; name
    Name := StrGet(&LOGFONT + 28)

    ; chosen color
    RGB := convert_Color(NumGet(CHOOSEFONT, A_PtrSize = 8 ? 40 : 24, "UInt"))
    Color := SubStr("0x00000", 1, 10 - StrLen(RGB)) SubStr(RGB, 3)
    Return, True
}



;-------------------------------------------------------------------------------
Select_Color(hGui, ByRef Color) { ; using comdlg32.dll
;-------------------------------------------------------------------------------

    ; CHOOSECOLOR structure expects text color in BGR format
    BGR := convert_Color(Color)

    ; unused, but a valid pointer to the structure
    VarSetCapacity(CUSTOM, 64, 0)


    ;-----------------------------------
    ; CHOOSECOLOR structure
    ;-----------------------------------

    If (A_PtrSize = 8) { ; 64 bit
        VarSetCapacity(CHOOSECOLOR, 72, 0)
        NumPut(     72, CHOOSECOLOR,  0) ; StructSize
        NumPut(   hGui, CHOOSECOLOR,  8) ; hwndOwner
        NumPut(    BGR, CHOOSECOLOR, 24) ; bgrColor
        NumPut(&CUSTOM, CHOOSECOLOR, 32) ; lpCustColors
        NumPut(  0x103, CHOOSECOLOR, 40) ; Flags
    }

    Else { ; 32 bit
        VarSetCapacity(CHOOSECOLOR, 36, 0)
        NumPut(     36, CHOOSECOLOR,  0) ; StructSize
        NumPut(   hGui, CHOOSECOLOR,  4) ; hwndOwner
        NumPut(    BGR, CHOOSECOLOR, 12) ; bgrColor
        NumPut(&CUSTOM, CHOOSECOLOR, 16) ; lpCustColors
        NumPut(  0x103, CHOOSECOLOR, 20) ; Flags
    }


    ;-----------------------------------
    ; call ChooseColorA function
    ;-----------------------------------

    If Not DllCall("comdlg32\ChooseColorA", "UInt", &CHOOSECOLOR)
        Return, False


    ;-----------------------------------
    ; result to return
    ;-----------------------------------

    ; chosen color
    RGB := convert_Color(NumGet(CHOOSECOLOR, A_PtrSize = 8 ? 24 : 12, "UInt"))
    Color := SubStr("0x00000", 1, 10 - StrLen(RGB)) SubStr(RGB, 3)
    Return, True
}



;-------------------------------------------------------------------------------
convert_Color(Color) { ; convert RGB <--> BGR
;-------------------------------------------------------------------------------
    $_FormatInteger := A_FormatInteger
    SetFormat, Integer, Hex
    Result := (Color & 0xFF) << 16 | Color & 0xFF00 | (Color >> 16) & 0xFF
    SetFormat, Integer, % $_FormatInteger
    Return, Result
}

No me burlo de los novatos,porque de ellos vengo
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:36

En está línea del script:

Code: Select all

	IniRead, BkColor              , %IniFile%, Settings, BkColor              , white
	IniRead, FontColor            , %IniFile%, Settings, FontColor            , Black
Se puede cambiar las palabras white o black por código Hex #000000.
Vale de mi manera de lo como tenia pensado no cambia nada.
Ahora sería intentar que el margen de fondo no tome toda la ventana.
No me burlo de los novatos,porque de ellos vengo
User avatar
Flipeador
Posts: 1018
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:43

Cuando ejecutas el script, si te fijas en el menu contextual del icono en el area de notificación, debe estar la opción para configurar ciertos aspectos de la ventana y el comportamiento.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2 My GDI+ Library
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

10 Oct 2018, 08:49

Cuando ejecutas el script, si te fijas en el menu contextual del icono en el area de notificación, debe estar la opción para configurar ciertos aspectos de la ventana y el comportamiento.
Me quiero morir :lol:

Gracias Flipeador
Yo pensaba que no tenia configuración y que la tenia que editar cada línea de comando pero no se puede editar casi todo.
No me burlo de los novatos,porque de ellos vengo
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

10 Oct 2018, 19:06

Flipeador tengo un problema no me deja editar las palabras de las teclas que están en inglés.
Ejemplo space, backsapce etc.
No me burlo de los novatos,porque de ellos vengo
eqv
Posts: 52
Joined: 18 Sep 2018, 22:17

Re: Mostrador de teclas pulsadas

11 Oct 2018, 03:04

Bertini, las palabras están en inglés; porque son los comandos aceptados por autohotkey (osea salen en el keylist: https://autohotkey.com/docs/KeyList.htm)
·
Para cambiarlo solo debes reemplazar el nombre justo antes de ser mostrado.
No se como será tu script, así que te explico en base al código original (el de GitHub: https://raw.githubusercontent.com/tmpli ... essOSD.ahk)
·
Ve a la línea 118, y verás esto:

Code: Select all

If (HotkeyStr != oLast.HotkeyStr) {
GuiControl, 1:, HotkeyText, %HotkeyStr%	;; <<<<< DEBES MODIFICAR "HotkeyStr"
oLast.HotkeyStr := HotkeyStr
changed := true
}
Así que modificas "HotkeyStr" con simples "StrReplace", y te quedará algo así:

Code: Select all

If (HotkeyStr != oLast.HotkeyStr) {
GuiControl, 1:, HotkeyText, % StrReplace(StrReplace(HotkeyStr,"BackSpace","Retroceso"),"Space","Espacio")
oLast.HotkeyStr := HotkeyStr
changed := true
}
Así vas modificando todo los nombres que necesites.
Espero te haya servido.

Saludos,
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

12 Oct 2018, 16:54

[b]@eqv[/b] Vale ya puse eso ahora no se modificar el resto para que tomen la palabra en español.

Dejo el script hasta dónde tengo modificado:

Code: Select all


; KeypressOSD v2.52 (2018-05-22)

#NoEnv
#SingleInstance force
#MaxHotkeysPerInterval 200
#KeyHistory 0
ListLines, Off
SetBatchLines, -1

global appVersion := "v2.52"
global AutoGuiW, BkColor, Bottom_OffsetX, Bottom_OffsetY, Bottom_Screen, Bottom_Win, DisplaySec, FixedX, FixedY
     , FontColor, FontName, FontSize, FontStyle, GuiHeight, GuiPosition, GuiWidth, SettingsGuiIsOpen
     , ShowModifierKeyCount, ShowMouseButton, ShowSingleKey, ShowSingleModifierKey, ShowStickyModKeyCount
     , Top_OffsetX, Top_OffsetY, Top_Screen, Top_Win, TransN
     , oLast := {}, hGui_OSD, hGUI_s

ReadSettings()
CreateTrayMenu()
CreateGUI()
CreateHotkey()
return

F7::ExitApp ; Deja de ejecutar el programa
F8::Reload ; Renicia el programa

#if !SettingsGuiIsOpen
	OnKeyPressed:
		try {
			key := GetKeyStr()
			ShowHotkey(key)
			SetTimer, HideGUI, % -1 * DisplaySec * 1000
		}
	return

	OnKeyUp:
	return

	_OnKeyUp:
		tickcount_start := A_TickCount
	return

; ===================================================================================
CreateGUI() {
	global

	Gui, +AlwaysOnTop -Caption +Owner +LastFound +E0x20 +HWNDhGui_OSD
	Gui, Margin, 0, 0
	Gui, Color, %BkColor%
	Gui, Font, c%FontColor% %FontStyle% s%FontSize%, %FontName%
	Gui, Add, Text, vHotkeyText Center y20

	WinSet, Transparent, %TransN%
}

CreateHotkey() {
	Loop, 95
	{
		k := Chr(A_Index + 31)
		k := (k = " ") ? "Space" : k

		Hotkey, % "~*" k, OnKeyPressed
		Hotkey, % "~*" k " Up", _OnKeyUp
	}

	Loop, 24 ; F1-F24
	{
		Hotkey, % "~*F" A_Index, OnKeyPressed
		Hotkey, % "~*F" A_Index " Up", _OnKeyUp
	}

	Loop, 10 ; Numpad0 - Numpad9
	{
		Hotkey, % "~*Numpad" A_Index - 1, OnKeyPressed
		Hotkey, % "~*Numpad" A_Index - 1 " Up", _OnKeyUp
	}

	Otherkeys := "WheelDown|WheelUp|WheelLeft|WheelRight|XButton1|XButton2|Browser_Forward|Browser_Back|Browser_Refresh|Browser_Stop|Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2|Help|Sleep|PrintScreen|CtrlBreak|Break|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|sc123"
	Loop, parse, Otherkeys, |
	{
		Hotkey, % "~*" A_LoopField, OnKeyPressed
		Hotkey, % "~*" A_LoopField " Up", _OnKeyUp
	}

	If ShowMouseButton {
		Loop, Parse, % "LButton|MButton|RButton", |
			Hotkey, % "~*" A_LoopField, OnKeyPressed
	}

	for i, mod in ["Ctrl", "Shift", "Alt"] {
		Hotkey, % "~*" mod, OnKeyPressed
		Hotkey, % "~*" mod " Up", OnKeyUp
	}
	for i, mod in ["LWin", "RWin"]
		Hotkey, % "~*" mod, OnKeyPressed
}

MouseHotkey_On() {
	Loop, Parse, % "LButton|MButton|RButton", |
		Hotkey, % "~*" A_LoopField, On, UseErrorLevel
}

MouseHotkey_Off() {
	Loop, Parse, % "LButton|MButton|RButton", |
		Hotkey, % "~*" A_LoopField, Off, UseErrorLevel
}

ShowHotkey(HotkeyStr) {
	if SettingsGuiIsOpen {
		ActWin_X := ActWin_Y := 0
		ActWin_W := A_ScreenWidth
		ActWin_H := A_ScreenHeight
	} else {
		WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
		if !ActWin_W
			throw
	}

	text_w := AutoGuiW ? ActWin_W : GuiWidth
	if (HotkeyStr != oLast.HotkeyStr) {
		GuiControl, 1:, HotkeyText, % StrReplace(StrReplace(HotkeyStr,"BackSpace","Retroceso"),"Space","Espacio")
		oLast.HotkeyStr := HotkeyStr
		changed := true
	}

	ctrlSize = w%text_w% h%GuiHeight%
	; ToolTip, % obj_print(oLast) "`n`n" ctrlSize "`n" oLast.ctrlSize
	if (ctrlSize != oLast.ctrlSize) {
		GuiControl, 1:Move, HotkeyText, x0 y0 %ctrlSize%
		GuiControl, +0x201, HotkeyText
		oLast.ctrlSize := ctrlSize
		changed := true
	}

	if (GuiPosition = "Fixed Position")
	{
		gui_x := FixedX
		gui_y := FixedY
	}
	else
	{
		if (GuiPosition = "Top" && Top_Screen)
		|| (GuiPosition = "Bottom" && Bottom_Screen)
		{
			ActWin_X := ActWin_Y := 0
			ActWin_W := A_ScreenWidth
			ActWin_H := A_ScreenHeight
		}

		if (GuiPosition = "Top")
		{
			gui_x := ActWin_X + Top_OffsetX
			gui_y := ActWin_Y + Top_OffsetY
		}
		else if (GuiPosition = "Bottom")
		{
			gui_x := ActWin_X + Bottom_OffsetX
			gui_y := (ActWin_Y+ActWin_H) - GuiHeight - Bottom_OffsetY
		}
	}
	

	guiPos = x%gui_x% y%gui_y%
	if (guiPos != oLast.guiPos || changed) {
		Gui, 1:Show, NoActivate %guiPos% %ctrlSize%
		oLast.guiPos := guiPos
		; ToolTip, updated! %a_now%

		; static n := 0
		; n += 1
		; ToolTip, % HotkeyStr " " n "`n" guiPos
	} else {
		; ToolTip, % "why?`n" obj_print(oLast) "`n`n" ctrlSize "`n" oLast.ctrlSize
	}
}

GetKeyStr() {
	static modifiers := ["Ctrl", "Shift", "Alt", "LWin", "RWin"]
	static repeatCount := 1

	for i, mod in modifiers {
		if GetKeyState(mod)
			prefix .= mod " + "
	}

	if (!prefix && !ShowSingleKey)
		throw

	key := SubStr(A_ThisHotkey, 3)

	if (key ~= "i)^(Ctrl|Shift|Alt|LWin|RWin)$") {
		if !ShowSingleModifierKey {
			throw
		}
		key := ""
		prefix := RTrim(prefix, "+ ")

		if ShowModifierKeyCount {
			if !InStr(prefix, "+") && IsDoubleClickEx() {
				if (A_ThisHotKey != A_PriorHotKey) || ShowStickyModKeyCount {
					if (++repeatCount > 1) {
						prefix .= " ( * " repeatCount " )"
					}
				} else {
					repeatCount := 0
				}
			} else {
				repeatCount := 1
			}
		}
	} 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"
		}
		_key := (key = "Double-Click") ? "LButton" : key

		static pre_prefix, pre_key, keyCount := 1
		global tickcount_start
		if (prefix && pre_prefix) && (A_TickCount-tickcount_start < 300) {
			if (prefix != pre_prefix) {
				result := pre_prefix pre_key ", " prefix key
			} else {
				keyCount := (key=pre_key) ? (keyCount+1) : 1
				key := (keyCount>2) ? (key " (" keyCount ")") : (pre_key ", " key)
			}
		} else {
			keyCount := 1
		}

		pre_prefix := prefix
		pre_key := _key

		repeatCount := 1
	}
	return result ? result : prefix . key
}

SpecialSC(sc) {
	static k := {sc046: "ScrollLock", sc145: "NumLock", sc146: "Pause", sc123: "Genius LuxeMate Scroll"}
	return k[sc]
}

; by Lexikos -- 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")
}

IsDoubleClick(MSec = 300) {
	Return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey < MSec)
}

IsDoubleClickEx(MSec = 300) {
	preHotkey := RegExReplace(A_PriorHotkey, "i) Up$")
	Return (A_ThisHotKey = preHotkey) && (A_TimeSincePriorHotkey < MSec)
}

HideGUI() {
	if !SettingsGuiIsOpen {
		Gui, Hide
	}
	oLast := {}
}

; -------------------------------------------------------------------

ReadSettings() {
	IniFile := SubStr(A_ScriptFullPath, 1, -4) ".ini"

	IniRead, TransN               , %IniFile%, Settings, TransN               , 100
	IniRead, ShowSingleKey        , %IniFile%, Settings, ShowSingleKey        , 1
	IniRead, ShowMouseButton      , %IniFile%, Settings, ShowMouseButton      , 1
	IniRead, ShowSingleModifierKey, %IniFile%, Settings, ShowSingleModifierKey, 1
	IniRead, ShowModifierKeyCount , %IniFile%, Settings, ShowModifierKeyCount , 1
	IniRead, ShowStickyModKeyCount, %IniFile%, Settings, ShowStickyModKeyCount, 0
	IniRead, DisplaySec           , %IniFile%, Settings, DisplaySec           , 1
	IniRead, GuiPosition          , %IniFile%, Settings, GuiPosition          , Bottom
	IniRead, FontSize             , %IniFile%, Settings, FontSize             , 25
	IniRead, GuiWidth             , %IniFile%, Settings, GuiWidth             , %A_ScreenWidth%
	IniRead, GuiHeight            , %IniFile%, Settings, GuiHeight            , 50
	IniRead, BkColor              , %IniFile%, Settings, BkColor              , black
	IniRead, FontColor            , %IniFile%, Settings, FontColor            , white
	IniRead, FontStyle            , %IniFile%, Settings, FontStyle            , w50
	IniRead, FontName             , %IniFile%, Settings, FontName             , Arial
	IniRead, AutoGuiW             , %IniFile%, Settings, AutoGuiW             , 1
	IniRead, Bottom_Win           , %IniFile%, Settings, Bottom_Win           , 1
	IniRead, Bottom_Screen        , %IniFile%, Settings, Bottom_Screen        , 0
	IniRead, Bottom_OffsetX       , %IniFile%, Settings, Bottom_OffsetX       , 0
	IniRead, Bottom_OffsetY       , %IniFile%, Settings, Bottom_OffsetY       , 50
	IniRead, Top_Win              , %IniFile%, Settings, Top_Win              , 1
	IniRead, Top_Screen           , %IniFile%, Settings, Top_Screen           , 0
	IniRead, Top_OffsetX          , %IniFile%, Settings, Top_OffsetX          , 0
	IniRead, Top_OffsetY          , %IniFile%, Settings, Top_OffsetY          , 0
	IniRead, FixedX               , %IniFile%, Settings, FixedX               , 100
	IniRead, FixedY               , %IniFile%, Settings, FixedY               , 200
}

SaveSettings() {
	IniFile := SubStr(A_ScriptFullPath, 1, -4) ".ini"

	IniWrite, %TransN%               , %IniFile%, Settings, TransN
	IniWrite, %ShowSingleKey%        , %IniFile%, Settings, ShowSingleKey
	IniWrite, %ShowMouseButton%      , %IniFile%, Settings, ShowMouseButton
	IniWrite, %ShowSingleModifierKey%, %IniFile%, Settings, ShowSingleModifierKey
	IniWrite, %ShowModifierKeyCount% , %IniFile%, Settings, ShowModifierKeyCount
	IniWrite, %ShowStickyModKeyCount%, %IniFile%, Settings, ShowStickyModKeyCount
	IniWrite, %DisplaySec%           , %IniFile%, Settings, DisplaySec
	IniWrite, %GuiPosition%          , %IniFile%, Settings, GuiPosition
	IniWrite, %FontSize%             , %IniFile%, Settings, FontSize
	IniWrite, %GuiWidth%             , %IniFile%, Settings, GuiWidth
	IniWrite, %GuiHeight%            , %IniFile%, Settings, GuiHeight
	IniWrite, %BkColor%              , %IniFile%, Settings, BkColor
	IniWrite, %FontColor%            , %IniFile%, Settings, FontColor
	IniWrite, %FontStyle%            , %IniFile%, Settings, FontStyle
	IniWrite, %FontName%             , %IniFile%, Settings, FontName
	IniWrite, %AutoGuiW%             , %IniFile%, Settings, AutoGuiW
	IniWrite, %Bottom_Win%           , %IniFile%, Settings, Bottom_Win
	IniWrite, %Bottom_Screen%        , %IniFile%, Settings, Bottom_Screen
	IniWrite, %Bottom_OffsetX%       , %IniFile%, Settings, Bottom_OffsetX
	IniWrite, %Bottom_OffsetY%       , %IniFile%, Settings, Bottom_OffsetY
	IniWrite, %Top_Win%              , %IniFile%, Settings, Top_Win
	IniWrite, %Top_Screen%           , %IniFile%, Settings, Top_Screen
	IniWrite, %Top_OffsetX%          , %IniFile%, Settings, Top_OffsetX
	IniWrite, %Top_OffsetY%          , %IniFile%, Settings, Top_OffsetY
	IniWrite, %FixedX%               , %IniFile%, Settings, FixedX
	IniWrite, %FixedY%               , %IniFile%, Settings, FixedY
}

CreateTrayMenu() {
	Menu, Tray, NoStandard
	Menu, Tray, Add, Settings, ShowSettingsGUI
	Menu, Tray, Add, Suspend, ToggleSuspend
	Menu, Tray, Add, About, ShowAboutGUI
	Menu, Tray, Add
	Menu, Tray, Add, Exit, _ExitApp
	Menu, Tray, Default, Settings
	Menu, Tray, Tip, KeypressOSD
}

ToggleSuspend() {
	Suspend, Toggle
	Menu, Tray, ToggleCheck, Suspend
	Menu, Tray, Tip, % "KeypressOSD" (A_IsSuspended ? " - Suspended" : "")
}

ShowAboutGUI() {
	Gui, a:Font, s12 bold
	Gui, a:Add, Text, , KeypressOSD %appVersion%
	Gui, a:Add, Link, gOpenUrl, <a>https://github.com/tmplinshi/KeypressOSD</a>
	Gui, a:Show,, About
	Return

	OpenUrl:
		Run, https://github.com/tmplinshi/KeypressOSD
	return
}

_ExitApp() {
	ExitApp
}

sGuiAddTitleText(text) {
	Gui, s:Font, s16
	Gui, s:Add, Text, xm y+20, %text%
	Gui, s:Font, s12
}

ShowSettingsGUI() {
	global

	SettingsGuiIsOpen := true

	Gui, s:Destroy
	Gui, s:+HWNDhGUI_s
	Gui, s:Font, s12

	Gui, s:Add, Text, xm, Transparency:
	Gui, s:Add, Text, x+10 w100 vTransNVal, %TransN%
	Gui, s:Add, Slider, xm+10 vTransN Range0-255 ToolTip gUpdateTransVal, %TransN%


	Gui, s:Add, Text, xm, Display
	Gui, s:Add, Edit, x+10 w80 Center vDisplaySec, %DisplaySec%
	Gui, s:Add, Text, x+10, Seconds

	Gui, s:Add, Checkbox, xm h24 vShowSingleKey Checked%ShowSingleKey%, Show Single Key
	Gui, s:Add, Checkbox, xm h24 vShowMouseButton Checked%ShowMouseButton%, Show Mouse Button
	Gui, s:Add, Checkbox, xm h24 vShowSingleModifierKey Checked%ShowSingleModifierKey%, Show Single Modifier Key
	Gui, s:Add, Checkbox, xm h24 vShowModifierKeyCount Checked%ShowModifierKeyCount%, Show Modifier Key Count
	Gui, s:Add, Checkbox, xm h24 vShowStickyModKeyCount Checked%ShowStickyModKeyCount%, Show Sticky Modifier Key Count

	sGuiAddTitleText("Window Position")
		Gui, s:Add, Tab3, xm y+10 Buttons vGuiPosition gUpdateGuiPosition, Bottom|Top|Fixed Position
		GuiControl, s:ChooseString, GuiPosition, |%GuiPosition%
		Gui, s:Tab, 1
			Gui, s:Add, Text, Section y+20, Relative To:
			Gui, s:Add, Radio, x+10 vBottom_Win Checked%Bottom_Win%, Active Window
			Gui, s:Add, Radio, x+20 vBottom_Screen Checked%Bottom_Screen%, Screen
			Gui, s:Add, Text, xs y+20, OffsetX
			Gui, s:Add, Edit, x+10 w80 vBottom_OffsetX Number gUpdateOSD, %Bottom_OffsetX%
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %Bottom_OffsetX%
			Gui, s:Add, Text, x+50, OffsetY
			Gui, s:Add, Edit, x+10 w80 vBottom_OffsetY Number gUpdateOSD, %Bottom_OffsetY%
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %Bottom_OffsetY%
		Gui, s:Tab, 2
			Gui, s:Add, Text, Section y+20, Relative To:
			Gui, s:Add, Radio, x+10 vTop_Win Checked%Top_Win%, Active Window
			Gui, s:Add, Radio, x+20 vTop_Screen Checked%Top_Screen%, Screen
			Gui, s:Add, Text, xs y+20, OffsetX
			Gui, s:Add, Edit, x+10 w80 vTop_OffsetX Number gUpdateOSD, 
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %Top_OffsetX%
			Gui, s:Add, Text, x+50, OffsetY
			Gui, s:Add, Edit, x+10 w80 vTop_OffsetY Number gUpdateOSD, 
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %Top_OffsetY%
		Gui, s:Tab, 3
			Gui, s:Add, Text, y+20, X
			Gui, s:Add, Edit, x+10 w80 vFixedX Number gUpdateOSD, %FixedX%
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %FixedX%
			Gui, s:Add, Text, x+50, Y
			Gui, s:Add, Edit, x+10 w80 vFixedY Number gUpdateOSD, %FixedY%
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %FixedY%
			Gui, s:Font, s10
			Gui, s:Add, Text, xs cGray, Input or drag the OSD window.
			Gui, s:Font, s12
		Gui, s:Tab

	sGuiAddTitleText("Window Size")
		Gui, s:Add, Text, xm, % " Width:"

		Gui, s:Add, Edit, x+10 w85 Center Number vGuiWidth gUpdateGuiWidth, %GuiWidth%
		Gui, s:Add, UpDown, Range10-4000 gUpdateGuiWidth 0x80 vGuiWUD, %GuiWidth%
		Gui, s:Add, Checkbox, x+30 vAutoGuiW Checked%AutoGuiW% g_AutoGuiW, Same As Active Window
		Gosub, _AutoGuiW

		Gui, s:Add, Text, xm, Height:
		Gui, s:Add, Edit, x+10 w85 Number Center vGuiHeight gUpdateGuiHeight, %GuiHeight%
		Gui, s:Add, UpDown, Range5-2000 gUpdateGuiHeight 0x80, %GuiHeight%

	Gui, s:Add, Button, xm y+20 gChangeBkColor, Change Background Color

	Gui, s:Add, Button, xm gChangeFont, Change Font
	Gui, s:Add, Button, x+50 gChangeFontColor, Change Font Color

	Gui, s:Add, Text, xm, Font Size:
	Gui, s:Add, Edit, x+10 w100 Number Center vFontSize gUpdateFontSize, %FontSize%
	Gui, s:Add, UpDown, Range1-1000 gUpdateFontSize 0x80, %fontSize%

	if (GuiPosition = "Fixed Position")
		OSD_EnableDrag()
	Gui, s:Show,, Settings - KeypressOSD

	ShowHotkey("KeypressOSD")
	SetTimer, HideGUI, Off
	return

	UpdateOSD:
		Gui, Submit, NoHide
		Gosub, _CheckValues
		ShowHotkey("KeypressOSD")
	return

	_CheckValues:
		Loop, Parse, % "Bottom_OffsetX,Bottom_OffsetY,Top_OffsetX,Top_OffsetY,FixedX,FixedY", `,
		{
			if (%A_LoopField% = "") {
				%A_LoopField% := 0
			}
		}
	return

	_AutoGuiW:
		; GuiControlGet, AutoGuiW, s:
		Gui, Submit, NoHide
		GuiControl, % "s:Enable" !AutoGuiW, GuiWidth
		GuiControl, % "s:Enable" !AutoGuiW, GuiWUD
		ShowHotkey("KeypressOSD")
		GuiControl, 1:+Redraw, HotkeyText
	return

	UpdateGuiPosition:
		oLast := {}
		Gui, Submit, NoHide
		ShowHotkey("KeypressOSD")

		if (GuiPosition = "Fixed Position")
			OSD_EnableDrag()
		else
			OSD_DisableDrag()
	return

	UpdateGuiWidth:
		GuiControlGet, newW,, GuiWidth
		if newW {
			GuiWidth := newW
			ShowHotkey("KeypressOSD")
		}
	return

	UpdateGuiHeight:
		GuiControlGet, newH,, GuiHeight
		if newH {
			GuiHeight := newH
			ShowHotkey("KeypressOSD")
		}
	return

	UpdateTransVal:
		GuiControlGet, TransN
		GuiControl,, TransNVal, % TransN

		Gui, 1:+LastFound
		WinSet, Transparent, %TransN%
	return

	UpdateFontSize:
		GuiControlGet, FontSize
		Gui, 1:Font, s%FontSize%
		GuiControl, 1:Font, HotkeyText
	return

	sGuiClose:
	sGuiEscape:
		FontSize_pre := FontSize

		Gui, s:Submit
		Gosub, _CheckValues

		ShowMouseButton ? MouseHotkey_On() : MouseHotkey_Off()

		if (FontSize_pre != FontSize) {
			Gui, 1:Font, s%FontSize%
			GuiControl, 1:Font, HotkeyText
		}

		if !GuiHeight
			GuiHeight := 115

		SaveSettings()
		Gui, s:Destroy
		Gui, 1:Hide
		OSD_DisableDrag()
		SettingsGuiIsOpen := ""
	return

	ChangeBkColor:
		newColor := BkColor
		if Select_Color(hGUI_s, newColor) {
			Gui, 1:Color, %newColor%
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
			BkColor := newColor
		}
	return

	ChangeFontColor:
		newColor := FontColor
		if Select_Color(hGUI_s, newColor) {
			Gui, 1:Font, c%newColor%
			GuiControl, 1:Font, HotkeyText
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
			FontColor := newColor
		}
	return

	ChangeFont:
		fStyle := FontStyle " s" FontSize
		fName  := FontName
		fColor := FontColor

		if Select_Font(hGUI_s, fStyle, fName, fColor) {
			FontStyle := fStyle
			FontName := fName
			FontColor := fColor
			if RegExMatch(FontStyle, "\bs\K\d+", FontSize) {
				FontStyle := RegExReplace(FontStyle, "\bs\d+")
				GuiControl,, FontSize, %FontSize%
			}

			Gui, 1:Font
			Gui, 1:Font, %fStyle% c%FontColor%, %fName%
			GuiControl, 1:Font, HotkeyText
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
		}
	return
}


WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	static hCursor := DllCall("LoadCursor", "Uint", 0, "Int", 32646, "Ptr") ; SizeAll = 32646

	if (hwnd = hGui_OSD) {
		PostMessage, 0xA1, 2
		DllCall("SetCursor", "ptr", hCursor)
	}
}

WM_MOVE(wParam, lParam, msg, hwnd) {
	if (hwnd = hGui_OSD) && GetKeyState("LButton", "P")
	{
		GuiControl, s:, FixedX, % lParam << 48 >> 48
		GuiControl, s:, FixedY, % lParam << 32 >> 48
	}
}

OSD_EnableDrag() {
	OnMessage(0x0201, "WM_LBUTTONDOWN")
	OnMessage(0x0003, "WM_MOVE")
	Gui, 1:-E0x20
}

OSD_DisableDrag() {
	OnMessage(0x0201, "")
	OnMessage(0x0003, "")
	Gui, 1:+E0x20
}


; https://autohotkey.com/boards/viewtopic.php?p=112730#p112730
;-------------------------------------------------------------------------------
Select_Font(hGui, ByRef Style, ByRef Name, ByRef Color) { ; using comdlg32.dll
;-------------------------------------------------------------------------------
    static SubKey := "SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI"


    ;-----------------------------------
    ; LOGFONT structure
    ;-----------------------------------
    VarSetCapacity(LOGFONT, 128, 0)

    If RegExMatch(Style, "s\K\d+", s) {
        RegRead, LogPixels, HKLM, %SubKey%, LogPixels
        NumPut(s * LogPixels // 72, LOGFONT, 0, "Int")
    }

    If RegExMatch(Style, "w\K\d+", w)
        NumPut(w, LOGFONT, 16, "Int")

    If InStr(Style, "italic")
        NumPut(255, LOGFONT, 20, "Int")

    If InStr(Style, "underline")
        NumPut(1, LOGFONT, 21, "Int")

    If InStr(Style, "strikeout")
        NumPut(1, LOGFONT, 22, "Int")

    StrPut(Name, &LOGFONT + 28, StrLen(Name) + 1)


    ;-----------------------------------
    ; CHOOSEFONT structure
    ;-----------------------------------

    ; CHOOSEFONT structure expects text color in BGR format
    BGR := convert_Color(Color)

    If (A_PtrSize = 8) { ; 64 bit
        VarSetCapacity(CHOOSEFONT, 104, 0)
        NumPut(     104, CHOOSEFONT,  0, "UInt") ; StructSize
        NumPut(    hGui, CHOOSEFONT,  8, "UInt") ; hwndOwner
        NumPut(&LOGFONT, CHOOSEFONT, 24, "UInt") ; lpLogFont
        NumPut(   0x141, CHOOSEFONT, 36, "UInt") ; Flags
        NumPut(     BGR, CHOOSEFONT, 40, "UInt") ; bgrColor
    }

    Else { ; 32 bit
        VarSetCapacity(CHOOSEFONT, 60, 0)
        NumPut(      60, CHOOSEFONT,  0, "UInt") ; StructSize
        NumPut(    hGui, CHOOSEFONT,  4, "UInt") ; hwndOwner
        NumPut(&LOGFONT, CHOOSEFONT, 12, "UInt") ; lpLogFont
        NumPut(   0x141, CHOOSEFONT, 20, "UInt") ; Flags
        NumPut(     BGR, CHOOSEFONT, 24, "UInt") ; bgrColor
    }


    ;-----------------------------------
    ; call ChooseFont function
    ;-----------------------------------
    FuncName := "comdlg32\ChooseFont" (A_IsUnicode ? "W" : "A")
    If Not DllCall(FuncName, "UInt", &CHOOSEFONT)
        Return, False


    ;-----------------------------------
    ; results to return
    ;-----------------------------------

    ; style
    Style := "s" NumGet(CHOOSEFONT, A_PtrSize = 8 ? 32 : 16, "Int") // 10
    Style .= " w" NumGet(LOGFONT, 16)
    If NumGet(LOGFONT, 20, "UChar")
        Style .= " italic"
    If NumGet(LOGFONT, 21, "UChar")
        Style .= " underline"
    If NumGet(LOGFONT, 22, "UChar")
        Style .= " strikeout"

    ; name
    Name := StrGet(&LOGFONT + 28)

    ; chosen color
    RGB := convert_Color(NumGet(CHOOSEFONT, A_PtrSize = 8 ? 40 : 24, "UInt"))
    Color := SubStr("0x00000", 1, 10 - StrLen(RGB)) SubStr(RGB, 3)
    Return, True
}



;-------------------------------------------------------------------------------
Select_Color(hGui, ByRef Color) { ; using comdlg32.dll
;-------------------------------------------------------------------------------

    ; CHOOSECOLOR structure expects text color in BGR format
    BGR := convert_Color(Color)

    ; unused, but a valid pointer to the structure
    VarSetCapacity(CUSTOM, 64, 0)


    ;-----------------------------------
    ; CHOOSECOLOR structure
    ;-----------------------------------

    If (A_PtrSize = 8) { ; 64 bit
        VarSetCapacity(CHOOSECOLOR, 72, 0)
        NumPut(     72, CHOOSECOLOR,  0) ; StructSize
        NumPut(   hGui, CHOOSECOLOR,  8) ; hwndOwner
        NumPut(    BGR, CHOOSECOLOR, 24) ; bgrColor
        NumPut(&CUSTOM, CHOOSECOLOR, 32) ; lpCustColors
        NumPut(  0x103, CHOOSECOLOR, 40) ; Flags
    }

    Else { ; 32 bit
        VarSetCapacity(CHOOSECOLOR, 36, 0)
        NumPut(     36, CHOOSECOLOR,  0) ; StructSize
        NumPut(   hGui, CHOOSECOLOR,  4) ; hwndOwner
        NumPut(    BGR, CHOOSECOLOR, 12) ; bgrColor
        NumPut(&CUSTOM, CHOOSECOLOR, 16) ; lpCustColors
        NumPut(  0x103, CHOOSECOLOR, 20) ; Flags
    }


    ;-----------------------------------
    ; call ChooseColorA function
    ;-----------------------------------

    If Not DllCall("comdlg32\ChooseColorA", "UInt", &CHOOSECOLOR)
        Return, False


    ;-----------------------------------
    ; result to return
    ;-----------------------------------

    ; chosen color
    RGB := convert_Color(NumGet(CHOOSECOLOR, A_PtrSize = 8 ? 24 : 12, "UInt"))
    Color := SubStr("0x00000", 1, 10 - StrLen(RGB)) SubStr(RGB, 3)
    Return, True
}



;-------------------------------------------------------------------------------
convert_Color(Color) { ; convert RGB <--> BGR
;-------------------------------------------------------------------------------
    $_FormatInteger := A_FormatInteger
    SetFormat, Integer, Hex
    Result := (Color & 0xFF) << 16 | Color & 0xFF00 | (Color >> 16) & 0xFF
    SetFormat, Integer, % $_FormatInteger
    Return, Result
}
No me burlo de los novatos,porque de ellos vengo
eqv
Posts: 52
Joined: 18 Sep 2018, 22:17

Re: Mostrador de teclas pulsadas

13 Oct 2018, 01:40

no se modificar el resto para que tomen la palabra en español
Con "tomar la palabra en español" te refieres a mostrártelo en español?
(por ejemplo, «presionar espacio» → «muestra la palabra "Espacio"», en lugar de "Space").

Para facilitarlo, cree la función "ES()", la cuál cambia todas las palabras del inglés al español (ir al final del script, línea 790). Cada reemplazo está separado por una línea. Si no te gusta una traducción, cámbiale a lo que tu prefirieras a la derecha:

Code: Select all

ES(a) {		;; Ejemplo:	(línea 790)
a:=StrReplace(a,"LButton","Click Izquierdo")	;; <<< no te gusta "Click Izquierdo"

Code: Select all

ES(a) {		;; Ejemplo:	(línea 790)
a:=StrReplace(a,"LButton","Click Izq")		;; <<< pásalo por ejemplo a "Click Izq"
Aquí abajo, dejo tu script junto la traducción:

Code: Select all


; KeypressOSD v2.52 (2018-05-22)

#NoEnv
#SingleInstance force
#MaxHotkeysPerInterval 200
#KeyHistory 0
ListLines, Off
SetBatchLines, -1

global appVersion := "v2.52"
global AutoGuiW, BkColor, Bottom_OffsetX, Bottom_OffsetY, Bottom_Screen, Bottom_Win, DisplaySec, FixedX, FixedY
     , FontColor, FontName, FontSize, FontStyle, GuiHeight, GuiPosition, GuiWidth, SettingsGuiIsOpen
     , ShowModifierKeyCount, ShowMouseButton, ShowSingleKey, ShowSingleModifierKey, ShowStickyModKeyCount
     , Top_OffsetX, Top_OffsetY, Top_Screen, Top_Win, TransN
     , oLast := {}, hGui_OSD, hGUI_s

ReadSettings()
CreateTrayMenu()
CreateGUI()
CreateHotkey()
return

F7::ExitApp ; Deja de ejecutar el programa
F8::Reload ; Renicia el programa

#if !SettingsGuiIsOpen
	OnKeyPressed:
		try {
			key := GetKeyStr()
			ShowHotkey(key)
			SetTimer, HideGUI, % -1 * DisplaySec * 1000
		}
	return

	OnKeyUp:
	return

	_OnKeyUp:
		tickcount_start := A_TickCount
	return

; ===================================================================================
CreateGUI() {
	global

	Gui, +AlwaysOnTop -Caption +Owner +LastFound +E0x20 +HWNDhGui_OSD
	Gui, Margin, 0, 0
	Gui, Color, %BkColor%
	Gui, Font, c%FontColor% %FontStyle% s%FontSize%, %FontName%
	Gui, Add, Text, vHotkeyText Center y20

	WinSet, Transparent, %TransN%
}

CreateHotkey() {
	Loop, 95
	{
		k := Chr(A_Index + 31)
		k := (k = " ") ? "Space" : k

		Hotkey, % "~*" k, OnKeyPressed
		Hotkey, % "~*" k " Up", _OnKeyUp
	}

	Loop, 24 ; F1-F24
	{
		Hotkey, % "~*F" A_Index, OnKeyPressed
		Hotkey, % "~*F" A_Index " Up", _OnKeyUp
	}

	Loop, 10 ; Numpad0 - Numpad9
	{
		Hotkey, % "~*Numpad" A_Index - 1, OnKeyPressed
		Hotkey, % "~*Numpad" A_Index - 1 " Up", _OnKeyUp
	}

	Otherkeys := "WheelDown|WheelUp|WheelLeft|WheelRight|XButton1|XButton2|Browser_Forward|Browser_Back|Browser_Refresh|Browser_Stop|Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2|Help|Sleep|PrintScreen|CtrlBreak|Break|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|sc123"
	Loop, parse, Otherkeys, |
	{
		Hotkey, % "~*" A_LoopField, OnKeyPressed
		Hotkey, % "~*" A_LoopField " Up", _OnKeyUp
	}

	If ShowMouseButton {
		Loop, Parse, % "LButton|MButton|RButton", |
			Hotkey, % "~*" A_LoopField, OnKeyPressed
	}

	for i, mod in ["Ctrl", "Shift", "Alt"] {
		Hotkey, % "~*" mod, OnKeyPressed
		Hotkey, % "~*" mod " Up", OnKeyUp
	}
	for i, mod in ["LWin", "RWin"]
		Hotkey, % "~*" mod, OnKeyPressed
}

MouseHotkey_On() {
	Loop, Parse, % "LButton|MButton|RButton", |
		Hotkey, % "~*" A_LoopField, On, UseErrorLevel
}

MouseHotkey_Off() {
	Loop, Parse, % "LButton|MButton|RButton", |
		Hotkey, % "~*" A_LoopField, Off, UseErrorLevel
}

ShowHotkey(HotkeyStr) {
	if SettingsGuiIsOpen {
		ActWin_X := ActWin_Y := 0
		ActWin_W := A_ScreenWidth
		ActWin_H := A_ScreenHeight
	} else {
		WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
		if !ActWin_W
			throw
	}

	text_w := AutoGuiW ? ActWin_W : GuiWidth
	if (HotkeyStr != oLast.HotkeyStr) {
		GuiControl, 1:, HotkeyText, % ES(HotkeyStr)
		oLast.HotkeyStr := HotkeyStr
		changed := true
	}

	ctrlSize = w%text_w% h%GuiHeight%
	; ToolTip, % obj_print(oLast) "`n`n" ctrlSize "`n" oLast.ctrlSize
	if (ctrlSize != oLast.ctrlSize) {
		GuiControl, 1:Move, HotkeyText, x0 y0 %ctrlSize%
		GuiControl, +0x201, HotkeyText
		oLast.ctrlSize := ctrlSize
		changed := true
	}

	if (GuiPosition = "Fixed Position")
	{
		gui_x := FixedX
		gui_y := FixedY
	}
	else
	{
		if (GuiPosition = "Top" && Top_Screen)
		|| (GuiPosition = "Bottom" && Bottom_Screen)
		{
			ActWin_X := ActWin_Y := 0
			ActWin_W := A_ScreenWidth
			ActWin_H := A_ScreenHeight
		}

		if (GuiPosition = "Top")
		{
			gui_x := ActWin_X + Top_OffsetX
			gui_y := ActWin_Y + Top_OffsetY
		}
		else if (GuiPosition = "Bottom")
		{
			gui_x := ActWin_X + Bottom_OffsetX
			gui_y := (ActWin_Y+ActWin_H) - GuiHeight - Bottom_OffsetY
		}
	}
	

	guiPos = x%gui_x% y%gui_y%
	if (guiPos != oLast.guiPos || changed) {
		Gui, 1:Show, NoActivate %guiPos% %ctrlSize%
		oLast.guiPos := guiPos
		; ToolTip, updated! %a_now%

		; static n := 0
		; n += 1
		; ToolTip, % HotkeyStr " " n "`n" guiPos
	} else {
		; ToolTip, % "why?`n" obj_print(oLast) "`n`n" ctrlSize "`n" oLast.ctrlSize
	}
}

GetKeyStr() {
	static modifiers := ["Ctrl", "Shift", "Alt", "LWin", "RWin"]
	static repeatCount := 1

	for i, mod in modifiers {
		if GetKeyState(mod)
			prefix .= mod " + "
	}

	if (!prefix && !ShowSingleKey)
		throw

	key := SubStr(A_ThisHotkey, 3)

	if (key ~= "i)^(Ctrl|Shift|Alt|LWin|RWin)$") {
		if !ShowSingleModifierKey {
			throw
		}
		key := ""
		prefix := RTrim(prefix, "+ ")

		if ShowModifierKeyCount {
			if !InStr(prefix, "+") && IsDoubleClickEx() {
				if (A_ThisHotKey != A_PriorHotKey) || ShowStickyModKeyCount {
					if (++repeatCount > 1) {
						prefix .= " ( * " repeatCount " )"
					}
				} else {
					repeatCount := 0
				}
			} else {
				repeatCount := 1
			}
		}
	} 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"
		}
		_key := (key = "Double-Click") ? "LButton" : key

		static pre_prefix, pre_key, keyCount := 1
		global tickcount_start
		if (prefix && pre_prefix) && (A_TickCount-tickcount_start < 300) {
			if (prefix != pre_prefix) {
				result := pre_prefix pre_key ", " prefix key
			} else {
				keyCount := (key=pre_key) ? (keyCount+1) : 1
				key := (keyCount>2) ? (key " (" keyCount ")") : (pre_key ", " key)
			}
		} else {
			keyCount := 1
		}

		pre_prefix := prefix
		pre_key := _key

		repeatCount := 1
	}
	return result ? result : prefix . key
}

SpecialSC(sc) {
	static k := {sc046: "ScrollLock", sc145: "NumLock", sc146: "Pause", sc123: "Genius LuxeMate Scroll"}
	return k[sc]
}

; by Lexikos -- 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")
}

IsDoubleClick(MSec = 300) {
	Return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey < MSec)
}

IsDoubleClickEx(MSec = 300) {
	preHotkey := RegExReplace(A_PriorHotkey, "i) Up$")
	Return (A_ThisHotKey = preHotkey) && (A_TimeSincePriorHotkey < MSec)
}

HideGUI() {
	if !SettingsGuiIsOpen {
		Gui, Hide
	}
	oLast := {}
}

; -------------------------------------------------------------------

ReadSettings() {
	IniFile := SubStr(A_ScriptFullPath, 1, -4) ".ini"

	IniRead, TransN               , %IniFile%, Settings, TransN               , 100
	IniRead, ShowSingleKey        , %IniFile%, Settings, ShowSingleKey        , 1
	IniRead, ShowMouseButton      , %IniFile%, Settings, ShowMouseButton      , 1
	IniRead, ShowSingleModifierKey, %IniFile%, Settings, ShowSingleModifierKey, 1
	IniRead, ShowModifierKeyCount , %IniFile%, Settings, ShowModifierKeyCount , 1
	IniRead, ShowStickyModKeyCount, %IniFile%, Settings, ShowStickyModKeyCount, 0
	IniRead, DisplaySec           , %IniFile%, Settings, DisplaySec           , 1
	IniRead, GuiPosition          , %IniFile%, Settings, GuiPosition          , Bottom
	IniRead, FontSize             , %IniFile%, Settings, FontSize             , 25
	IniRead, GuiWidth             , %IniFile%, Settings, GuiWidth             , %A_ScreenWidth%
	IniRead, GuiHeight            , %IniFile%, Settings, GuiHeight            , 50
	IniRead, BkColor              , %IniFile%, Settings, BkColor              , black
	IniRead, FontColor            , %IniFile%, Settings, FontColor            , white
	IniRead, FontStyle            , %IniFile%, Settings, FontStyle            , w50
	IniRead, FontName             , %IniFile%, Settings, FontName             , Arial
	IniRead, AutoGuiW             , %IniFile%, Settings, AutoGuiW             , 1
	IniRead, Bottom_Win           , %IniFile%, Settings, Bottom_Win           , 1
	IniRead, Bottom_Screen        , %IniFile%, Settings, Bottom_Screen        , 0
	IniRead, Bottom_OffsetX       , %IniFile%, Settings, Bottom_OffsetX       , 0
	IniRead, Bottom_OffsetY       , %IniFile%, Settings, Bottom_OffsetY       , 50
	IniRead, Top_Win              , %IniFile%, Settings, Top_Win              , 1
	IniRead, Top_Screen           , %IniFile%, Settings, Top_Screen           , 0
	IniRead, Top_OffsetX          , %IniFile%, Settings, Top_OffsetX          , 0
	IniRead, Top_OffsetY          , %IniFile%, Settings, Top_OffsetY          , 0
	IniRead, FixedX               , %IniFile%, Settings, FixedX               , 100
	IniRead, FixedY               , %IniFile%, Settings, FixedY               , 200
}

SaveSettings() {
	IniFile := SubStr(A_ScriptFullPath, 1, -4) ".ini"

	IniWrite, %TransN%               , %IniFile%, Settings, TransN
	IniWrite, %ShowSingleKey%        , %IniFile%, Settings, ShowSingleKey
	IniWrite, %ShowMouseButton%      , %IniFile%, Settings, ShowMouseButton
	IniWrite, %ShowSingleModifierKey%, %IniFile%, Settings, ShowSingleModifierKey
	IniWrite, %ShowModifierKeyCount% , %IniFile%, Settings, ShowModifierKeyCount
	IniWrite, %ShowStickyModKeyCount%, %IniFile%, Settings, ShowStickyModKeyCount
	IniWrite, %DisplaySec%           , %IniFile%, Settings, DisplaySec
	IniWrite, %GuiPosition%          , %IniFile%, Settings, GuiPosition
	IniWrite, %FontSize%             , %IniFile%, Settings, FontSize
	IniWrite, %GuiWidth%             , %IniFile%, Settings, GuiWidth
	IniWrite, %GuiHeight%            , %IniFile%, Settings, GuiHeight
	IniWrite, %BkColor%              , %IniFile%, Settings, BkColor
	IniWrite, %FontColor%            , %IniFile%, Settings, FontColor
	IniWrite, %FontStyle%            , %IniFile%, Settings, FontStyle
	IniWrite, %FontName%             , %IniFile%, Settings, FontName
	IniWrite, %AutoGuiW%             , %IniFile%, Settings, AutoGuiW
	IniWrite, %Bottom_Win%           , %IniFile%, Settings, Bottom_Win
	IniWrite, %Bottom_Screen%        , %IniFile%, Settings, Bottom_Screen
	IniWrite, %Bottom_OffsetX%       , %IniFile%, Settings, Bottom_OffsetX
	IniWrite, %Bottom_OffsetY%       , %IniFile%, Settings, Bottom_OffsetY
	IniWrite, %Top_Win%              , %IniFile%, Settings, Top_Win
	IniWrite, %Top_Screen%           , %IniFile%, Settings, Top_Screen
	IniWrite, %Top_OffsetX%          , %IniFile%, Settings, Top_OffsetX
	IniWrite, %Top_OffsetY%          , %IniFile%, Settings, Top_OffsetY
	IniWrite, %FixedX%               , %IniFile%, Settings, FixedX
	IniWrite, %FixedY%               , %IniFile%, Settings, FixedY
}

CreateTrayMenu() {
	Menu, Tray, NoStandard
	Menu, Tray, Add, Settings, ShowSettingsGUI
	Menu, Tray, Add, Suspend, ToggleSuspend
	Menu, Tray, Add, About, ShowAboutGUI
	Menu, Tray, Add
	Menu, Tray, Add, Exit, _ExitApp
	Menu, Tray, Default, Settings
	Menu, Tray, Tip, KeypressOSD
}

ToggleSuspend() {
	Suspend, Toggle
	Menu, Tray, ToggleCheck, Suspend
	Menu, Tray, Tip, % "KeypressOSD" (A_IsSuspended ? " - Suspended" : "")
}

ShowAboutGUI() {
	Gui, a:Font, s12 bold
	Gui, a:Add, Text, , KeypressOSD %appVersion%
	Gui, a:Add, Link, gOpenUrl, <a>https://github.com/tmplinshi/KeypressOSD</a>
	Gui, a:Show,, About
	Return

	OpenUrl:
		Run, https://github.com/tmplinshi/KeypressOSD
	return
}

_ExitApp() {
	ExitApp
}

sGuiAddTitleText(text) {
	Gui, s:Font, s16
	Gui, s:Add, Text, xm y+20, %text%
	Gui, s:Font, s12
}

ShowSettingsGUI() {
	global

	SettingsGuiIsOpen := true

	Gui, s:Destroy
	Gui, s:+HWNDhGUI_s
	Gui, s:Font, s12

	Gui, s:Add, Text, xm, Transparency:
	Gui, s:Add, Text, x+10 w100 vTransNVal, %TransN%
	Gui, s:Add, Slider, xm+10 vTransN Range0-255 ToolTip gUpdateTransVal, %TransN%


	Gui, s:Add, Text, xm, Display
	Gui, s:Add, Edit, x+10 w80 Center vDisplaySec, %DisplaySec%
	Gui, s:Add, Text, x+10, Seconds

	Gui, s:Add, Checkbox, xm h24 vShowSingleKey Checked%ShowSingleKey%, Show Single Key
	Gui, s:Add, Checkbox, xm h24 vShowMouseButton Checked%ShowMouseButton%, Show Mouse Button
	Gui, s:Add, Checkbox, xm h24 vShowSingleModifierKey Checked%ShowSingleModifierKey%, Show Single Modifier Key
	Gui, s:Add, Checkbox, xm h24 vShowModifierKeyCount Checked%ShowModifierKeyCount%, Show Modifier Key Count
	Gui, s:Add, Checkbox, xm h24 vShowStickyModKeyCount Checked%ShowStickyModKeyCount%, Show Sticky Modifier Key Count

	sGuiAddTitleText("Window Position")
		Gui, s:Add, Tab3, xm y+10 Buttons vGuiPosition gUpdateGuiPosition, Bottom|Top|Fixed Position
		GuiControl, s:ChooseString, GuiPosition, |%GuiPosition%
		Gui, s:Tab, 1
			Gui, s:Add, Text, Section y+20, Relative To:
			Gui, s:Add, Radio, x+10 vBottom_Win Checked%Bottom_Win%, Active Window
			Gui, s:Add, Radio, x+20 vBottom_Screen Checked%Bottom_Screen%, Screen
			Gui, s:Add, Text, xs y+20, OffsetX
			Gui, s:Add, Edit, x+10 w80 vBottom_OffsetX Number gUpdateOSD, %Bottom_OffsetX%
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %Bottom_OffsetX%
			Gui, s:Add, Text, x+50, OffsetY
			Gui, s:Add, Edit, x+10 w80 vBottom_OffsetY Number gUpdateOSD, %Bottom_OffsetY%
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %Bottom_OffsetY%
		Gui, s:Tab, 2
			Gui, s:Add, Text, Section y+20, Relative To:
			Gui, s:Add, Radio, x+10 vTop_Win Checked%Top_Win%, Active Window
			Gui, s:Add, Radio, x+20 vTop_Screen Checked%Top_Screen%, Screen
			Gui, s:Add, Text, xs y+20, OffsetX
			Gui, s:Add, Edit, x+10 w80 vTop_OffsetX Number gUpdateOSD, 
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %Top_OffsetX%
			Gui, s:Add, Text, x+50, OffsetY
			Gui, s:Add, Edit, x+10 w80 vTop_OffsetY Number gUpdateOSD, 
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %Top_OffsetY%
		Gui, s:Tab, 3
			Gui, s:Add, Text, y+20, X
			Gui, s:Add, Edit, x+10 w80 vFixedX Number gUpdateOSD, %FixedX%
			Gui, s:Add, UpDown, Range0-%A_ScreenWidth% 0x80 gUpdateOSD, %FixedX%
			Gui, s:Add, Text, x+50, Y
			Gui, s:Add, Edit, x+10 w80 vFixedY Number gUpdateOSD, %FixedY%
			Gui, s:Add, UpDown, Range0-%A_ScreenHeight% 0x80 gUpdateOSD, %FixedY%
			Gui, s:Font, s10
			Gui, s:Add, Text, xs cGray, Input or drag the OSD window.
			Gui, s:Font, s12
		Gui, s:Tab

	sGuiAddTitleText("Window Size")
		Gui, s:Add, Text, xm, % " Width:"

		Gui, s:Add, Edit, x+10 w85 Center Number vGuiWidth gUpdateGuiWidth, %GuiWidth%
		Gui, s:Add, UpDown, Range10-4000 gUpdateGuiWidth 0x80 vGuiWUD, %GuiWidth%
		Gui, s:Add, Checkbox, x+30 vAutoGuiW Checked%AutoGuiW% g_AutoGuiW, Same As Active Window
		Gosub, _AutoGuiW

		Gui, s:Add, Text, xm, Height:
		Gui, s:Add, Edit, x+10 w85 Number Center vGuiHeight gUpdateGuiHeight, %GuiHeight%
		Gui, s:Add, UpDown, Range5-2000 gUpdateGuiHeight 0x80, %GuiHeight%

	Gui, s:Add, Button, xm y+20 gChangeBkColor, Change Background Color

	Gui, s:Add, Button, xm gChangeFont, Change Font
	Gui, s:Add, Button, x+50 gChangeFontColor, Change Font Color

	Gui, s:Add, Text, xm, Font Size:
	Gui, s:Add, Edit, x+10 w100 Number Center vFontSize gUpdateFontSize, %FontSize%
	Gui, s:Add, UpDown, Range1-1000 gUpdateFontSize 0x80, %fontSize%

	if (GuiPosition = "Fixed Position")
		OSD_EnableDrag()
	Gui, s:Show,, Settings - KeypressOSD

	ShowHotkey("KeypressOSD")
	SetTimer, HideGUI, Off
	return

	UpdateOSD:
		Gui, Submit, NoHide
		Gosub, _CheckValues
		ShowHotkey("KeypressOSD")
	return

	_CheckValues:
		Loop, Parse, % "Bottom_OffsetX,Bottom_OffsetY,Top_OffsetX,Top_OffsetY,FixedX,FixedY", `,
		{
			if (%A_LoopField% = "") {
				%A_LoopField% := 0
			}
		}
	return

	_AutoGuiW:
		; GuiControlGet, AutoGuiW, s:
		Gui, Submit, NoHide
		GuiControl, % "s:Enable" !AutoGuiW, GuiWidth
		GuiControl, % "s:Enable" !AutoGuiW, GuiWUD
		ShowHotkey("KeypressOSD")
		GuiControl, 1:+Redraw, HotkeyText
	return

	UpdateGuiPosition:
		oLast := {}
		Gui, Submit, NoHide
		ShowHotkey("KeypressOSD")

		if (GuiPosition = "Fixed Position")
			OSD_EnableDrag()
		else
			OSD_DisableDrag()
	return

	UpdateGuiWidth:
		GuiControlGet, newW,, GuiWidth
		if newW {
			GuiWidth := newW
			ShowHotkey("KeypressOSD")
		}
	return

	UpdateGuiHeight:
		GuiControlGet, newH,, GuiHeight
		if newH {
			GuiHeight := newH
			ShowHotkey("KeypressOSD")
		}
	return

	UpdateTransVal:
		GuiControlGet, TransN
		GuiControl,, TransNVal, % TransN

		Gui, 1:+LastFound
		WinSet, Transparent, %TransN%
	return

	UpdateFontSize:
		GuiControlGet, FontSize
		Gui, 1:Font, s%FontSize%
		GuiControl, 1:Font, HotkeyText
	return

	sGuiClose:
	sGuiEscape:
		FontSize_pre := FontSize

		Gui, s:Submit
		Gosub, _CheckValues

		ShowMouseButton ? MouseHotkey_On() : MouseHotkey_Off()

		if (FontSize_pre != FontSize) {
			Gui, 1:Font, s%FontSize%
			GuiControl, 1:Font, HotkeyText
		}

		if !GuiHeight
			GuiHeight := 115

		SaveSettings()
		Gui, s:Destroy
		Gui, 1:Hide
		OSD_DisableDrag()
		SettingsGuiIsOpen := ""
	return

	ChangeBkColor:
		newColor := BkColor
		if Select_Color(hGUI_s, newColor) {
			Gui, 1:Color, %newColor%
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
			BkColor := newColor
		}
	return

	ChangeFontColor:
		newColor := FontColor
		if Select_Color(hGUI_s, newColor) {
			Gui, 1:Font, c%newColor%
			GuiControl, 1:Font, HotkeyText
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
			FontColor := newColor
		}
	return

	ChangeFont:
		fStyle := FontStyle " s" FontSize
		fName  := FontName
		fColor := FontColor

		if Select_Font(hGUI_s, fStyle, fName, fColor) {
			FontStyle := fStyle
			FontName := fName
			FontColor := fColor
			if RegExMatch(FontStyle, "\bs\K\d+", FontSize) {
				FontStyle := RegExReplace(FontStyle, "\bs\d+")
				GuiControl,, FontSize, %FontSize%
			}

			Gui, 1:Font
			Gui, 1:Font, %fStyle% c%FontColor%, %fName%
			GuiControl, 1:Font, HotkeyText
			ShowHotkey("KeypressOSD")
			SetTimer, HideGUI, Off
		}
	return
}


WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
	static hCursor := DllCall("LoadCursor", "Uint", 0, "Int", 32646, "Ptr") ; SizeAll = 32646

	if (hwnd = hGui_OSD) {
		PostMessage, 0xA1, 2
		DllCall("SetCursor", "ptr", hCursor)
	}
}

WM_MOVE(wParam, lParam, msg, hwnd) {
	if (hwnd = hGui_OSD) && GetKeyState("LButton", "P")
	{
		GuiControl, s:, FixedX, % lParam << 48 >> 48
		GuiControl, s:, FixedY, % lParam << 32 >> 48
	}
}

OSD_EnableDrag() {
	OnMessage(0x0201, "WM_LBUTTONDOWN")
	OnMessage(0x0003, "WM_MOVE")
	Gui, 1:-E0x20
}

OSD_DisableDrag() {
	OnMessage(0x0201, "")
	OnMessage(0x0003, "")
	Gui, 1:+E0x20
}


; https://autohotkey.com/boards/viewtopic.php?p=112730#p112730
;-------------------------------------------------------------------------------
Select_Font(hGui, ByRef Style, ByRef Name, ByRef Color) { ; using comdlg32.dll
;-------------------------------------------------------------------------------
    static SubKey := "SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI"


    ;-----------------------------------
    ; LOGFONT structure
    ;-----------------------------------
    VarSetCapacity(LOGFONT, 128, 0)

    If RegExMatch(Style, "s\K\d+", s) {
        RegRead, LogPixels, HKLM, %SubKey%, LogPixels
        NumPut(s * LogPixels // 72, LOGFONT, 0, "Int")
    }

    If RegExMatch(Style, "w\K\d+", w)
        NumPut(w, LOGFONT, 16, "Int")

    If InStr(Style, "italic")
        NumPut(255, LOGFONT, 20, "Int")

    If InStr(Style, "underline")
        NumPut(1, LOGFONT, 21, "Int")

    If InStr(Style, "strikeout")
        NumPut(1, LOGFONT, 22, "Int")

    StrPut(Name, &LOGFONT + 28, StrLen(Name) + 1)


    ;-----------------------------------
    ; CHOOSEFONT structure
    ;-----------------------------------

    ; CHOOSEFONT structure expects text color in BGR format
    BGR := convert_Color(Color)

    If (A_PtrSize = 8) { ; 64 bit
        VarSetCapacity(CHOOSEFONT, 104, 0)
        NumPut(     104, CHOOSEFONT,  0, "UInt") ; StructSize
        NumPut(    hGui, CHOOSEFONT,  8, "UInt") ; hwndOwner
        NumPut(&LOGFONT, CHOOSEFONT, 24, "UInt") ; lpLogFont
        NumPut(   0x141, CHOOSEFONT, 36, "UInt") ; Flags
        NumPut(     BGR, CHOOSEFONT, 40, "UInt") ; bgrColor
    }

    Else { ; 32 bit
        VarSetCapacity(CHOOSEFONT, 60, 0)
        NumPut(      60, CHOOSEFONT,  0, "UInt") ; StructSize
        NumPut(    hGui, CHOOSEFONT,  4, "UInt") ; hwndOwner
        NumPut(&LOGFONT, CHOOSEFONT, 12, "UInt") ; lpLogFont
        NumPut(   0x141, CHOOSEFONT, 20, "UInt") ; Flags
        NumPut(     BGR, CHOOSEFONT, 24, "UInt") ; bgrColor
    }


    ;-----------------------------------
    ; call ChooseFont function
    ;-----------------------------------
    FuncName := "comdlg32\ChooseFont" (A_IsUnicode ? "W" : "A")
    If Not DllCall(FuncName, "UInt", &CHOOSEFONT)
        Return, False


    ;-----------------------------------
    ; results to return
    ;-----------------------------------

    ; style
    Style := "s" NumGet(CHOOSEFONT, A_PtrSize = 8 ? 32 : 16, "Int") // 10
    Style .= " w" NumGet(LOGFONT, 16)
    If NumGet(LOGFONT, 20, "UChar")
        Style .= " italic"
    If NumGet(LOGFONT, 21, "UChar")
        Style .= " underline"
    If NumGet(LOGFONT, 22, "UChar")
        Style .= " strikeout"

    ; name
    Name := StrGet(&LOGFONT + 28)

    ; chosen color
    RGB := convert_Color(NumGet(CHOOSEFONT, A_PtrSize = 8 ? 40 : 24, "UInt"))
    Color := SubStr("0x00000", 1, 10 - StrLen(RGB)) SubStr(RGB, 3)
    Return, True
}



;-------------------------------------------------------------------------------
Select_Color(hGui, ByRef Color) { ; using comdlg32.dll
;-------------------------------------------------------------------------------

    ; CHOOSECOLOR structure expects text color in BGR format
    BGR := convert_Color(Color)

    ; unused, but a valid pointer to the structure
    VarSetCapacity(CUSTOM, 64, 0)


    ;-----------------------------------
    ; CHOOSECOLOR structure
    ;-----------------------------------

    If (A_PtrSize = 8) { ; 64 bit
        VarSetCapacity(CHOOSECOLOR, 72, 0)
        NumPut(     72, CHOOSECOLOR,  0) ; StructSize
        NumPut(   hGui, CHOOSECOLOR,  8) ; hwndOwner
        NumPut(    BGR, CHOOSECOLOR, 24) ; bgrColor
        NumPut(&CUSTOM, CHOOSECOLOR, 32) ; lpCustColors
        NumPut(  0x103, CHOOSECOLOR, 40) ; Flags
    }

    Else { ; 32 bit
        VarSetCapacity(CHOOSECOLOR, 36, 0)
        NumPut(     36, CHOOSECOLOR,  0) ; StructSize
        NumPut(   hGui, CHOOSECOLOR,  4) ; hwndOwner
        NumPut(    BGR, CHOOSECOLOR, 12) ; bgrColor
        NumPut(&CUSTOM, CHOOSECOLOR, 16) ; lpCustColors
        NumPut(  0x103, CHOOSECOLOR, 20) ; Flags
    }


    ;-----------------------------------
    ; call ChooseColorA function
    ;-----------------------------------

    If Not DllCall("comdlg32\ChooseColorA", "UInt", &CHOOSECOLOR)
        Return, False


    ;-----------------------------------
    ; result to return
    ;-----------------------------------

    ; chosen color
    RGB := convert_Color(NumGet(CHOOSECOLOR, A_PtrSize = 8 ? 24 : 12, "UInt"))
    Color := SubStr("0x00000", 1, 10 - StrLen(RGB)) SubStr(RGB, 3)
    Return, True
}



;-------------------------------------------------------------------------------
convert_Color(Color) { ; convert RGB <--> BGR
;-------------------------------------------------------------------------------
    $_FormatInteger := A_FormatInteger
    SetFormat, Integer, Hex
    Result := (Color & 0xFF) << 16 | Color & 0xFF00 | (Color >> 16) & 0xFF
    SetFormat, Integer, % $_FormatInteger
    Return, Result
}

;; ========================================================
;;			ESPAÑOL
;; ========================================================
ES(a) {
a:=StrReplace(a,"LButton","Click Izquierdo")
a:=StrReplace(a,"RButton","Click Derecho")
a:=StrReplace(a,"MButton","Click Medio")

a:=StrReplace(a,"LWin","Izq.Win")
a:=StrReplace(a,"LAlt","Izq.Alt")
a:=StrReplace(a,"LShift","Izq.Shift")
a:=StrReplace(a,"RWin","Der.Win")
a:=StrReplace(a,"RAlt","Der.Alt")
a:=StrReplace(a,"RShift","Der.Shift")

a:=StrReplace(a,"Browser_Back","Navegador_Retroceder")
a:=StrReplace(a,"Browser_Forward","Navegador_Adelantar")
a:=StrReplace(a,"Browser_Refresh","Navegador_Actualizar")
a:=StrReplace(a,"Browser_Stop","Navegador_Parar")
a:=StrReplace(a,"Browser_Search","Navegador_Buscar")
a:=StrReplace(a,"Browser_Favorites","Navegador_Favoritos")
a:=StrReplace(a,"Browser_Home","Navegador_Inicio")

a:=StrReplace(a,"Volume_Mute","Volumen_Silencio")
a:=StrReplace(a,"Volume_Up","Volumen_+")
a:=StrReplace(a,"Volume_Down","Volumen_-")

a:=StrReplace(a,"Media_Play_Pause","Multimedia_Tocar\Pausar")
a:=StrReplace(a,"Media_Next","Multimedia_Siguiente")
a:=StrReplace(a,"Media_Prev","Multimedia_Anterior")
a:=StrReplace(a,"Media_Stop","Multimedia_Parar")

a:=StrReplace(a,"AppsKey","Menú Contextual")
a:=StrReplace(a,"PrintScreen","Capturar Pantalla")
a:=StrReplace(a,"Pause","Pausa")
a:=StrReplace(a,"Help","Ayuda")
a:=StrReplace(a,"Sleep","Descansar")

a:=StrReplace(a,"BackSpace","Retroceso")
a:=StrReplace(a,"Space","Espacio")
a:=StrReplace(a,"BackSpace","Retroceso")
a:=StrReplace(a,"WheelDown","Rueda Abajo")
a:=StrReplace(a,"WheelUp","Rueda Arriba")
a:=StrReplace(a,"WheelLeft","Rueda Izquierda")
a:=StrReplace(a,"WheelRight","Rueda Derecha")
a:=StrReplace(a,"CapsLock","Bloq Mayús")
a:=StrReplace(a,"Tab","Tabulación")
a:=StrReplace(a,"Esc","Escape")
a:=StrReplace(a,"ScrollLock","Cerrar Desplazamiento")
a:=StrReplace(a,"Insert","Insertar")
a:=StrReplace(a,"Del","Eliminar")
a:=StrReplace(a,"Home","Inicio")
a:=StrReplace(a,"End","Final")
a:=StrReplace(a,"PgUp","Página Arriba")
a:=StrReplace(a,"PgDn","Página Abajo")
a:=StrReplace(a,"Up","Arriba")
a:=StrReplace(a,"Down","Abajo")
a:=StrReplace(a,"Left","Izquierda")
a:=StrReplace(a,"Right","Derecha")

a:=StrReplace(a,"Numpad0","Panel Numérico # 0")
a:=StrReplace(a,"Numpad1","Panel Numérico # 1")
a:=StrReplace(a,"Numpad2","Panel Numérico # 2")
a:=StrReplace(a,"Numpad3","Panel Numérico # 3")
a:=StrReplace(a,"Numpad4","Panel Numérico # 4")
a:=StrReplace(a,"Numpad5","Panel Numérico # 5")
a:=StrReplace(a,"Numpad6","Panel Numérico # 6")
a:=StrReplace(a,"Numpad7","Panel Numérico # 7")
a:=StrReplace(a,"Numpad8","Panel Numérico # 8")
a:=StrReplace(a,"Numpad9","Panel Numérico # 9")
a:=StrReplace(a,"NumLock","Cerrar Panel Numérico")
a:=StrReplace(a,"NumpadDiv","Panel Numérico # División")
a:=StrReplace(a,"NumpadMult","Panel Numérico # Multiplicación")
a:=StrReplace(a,"NumpadAdd","Panel Numérico # Suma")
a:=StrReplace(a,"NumpadSub","Panel Numérico # Resta")

Return, a
}
Nota: en la línea 122, verás mi función para traducir "HotkeyStr";
«GuiControl, 1:, HotkeyText, % ES(HotkeyStr)»


Saludos,
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

13 Oct 2018, 07:07

Vale gracias ahora modificare script.
Ahora ha salido otro problema: los acentos.

Ejemplo: áéíóúñ etc..

No salen como el resto y la ñ no la muestra.
No me burlo de los novatos,porque de ellos vengo
eqv
Posts: 52
Joined: 18 Sep 2018, 22:17

Re: Mostrador de teclas pulsadas

13 Oct 2018, 07:51


ahora salido otro problema son los acentos

Ejemplo: áéíóúñ etc..

No salen como el resto y la ñ no la muestra
Siento escuchar eso, pero no puedo ayudarte. En mi computadora funciona bien; intente replicar el problema y no pude. Parece estar relacionado con la codificación de los caracteres (UNICODE, ANSI, UTF-8), pero fuera de una idea general; no se. También podrías quitar las vocales con tílde y las ñ.

Suerte.
Saludos,
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

13 Oct 2018, 08:40


ahora salido otro problema son los acentos

Ejemplo: áéíóúñ etc..

No salen como el resto y la ñ no la muestra
Siento escuchar eso, pero no puedo ayudarte. En mi computadora funciona bien; intente replicar el problema y no pude. Parece estar relacionado con la codificación de los caracteres (UNICODE, ANSI, UTF-8), pero fuera de una idea general; no se. También podrías quitar las vocales con tílde y las ñ.

Suerte.
Saludos,
Voy aprobar si UNICODE me muestra las tildes
No me burlo de los novatos,porque de ellos vengo
User avatar
Bertini
Posts: 86
Joined: 23 May 2018, 10:11

Re: Mostrador de teclas pulsadas

13 Oct 2018, 08:55


ahora salido otro problema son los acentos

Ejemplo: áéíóúñ etc..

No salen como el resto y la ñ no la muestra
Siento escuchar eso, pero no puedo ayudarte. En mi computadora funciona bien; intente replicar el problema y no pude. Parece estar relacionado con la codificación de los caracteres (UNICODE, ANSI, UTF-8), pero fuera de una idea general; no se. También podrías quitar las vocales con tílde y las ñ.

Suerte.
Saludos,
Voy aprobar si UNICODE me muestra las tildes
Vale UNICODE sigue sin mostrar la ñ
No me burlo de los novatos,porque de ellos vengo

Return to “Pedir Ayuda”

Who is online

Users browsing this forum: No registered users and 5 guests