How to play sound on every keypress regardless of key and without affecting its function

Get help with using AutoHotkey and its commands and hotkeys
robhayes
Posts: 19
Joined: 28 Dec 2015, 15:35

How to play sound on every keypress regardless of key and without affecting its function

04 Jul 2017, 11:19

Hello,

I have a quiet keyboard, so for fun I would sometimes like to enable a satisfying mechanical switch sound whenever a key is pressed, such as https://freesound.org/people/Jagadamba/sounds/254286/

I have figured out how to make the sound play using SoundPlay, C:\mechanical-switch.wav, but making it work for every key is over my head.
BoBo
Posts: 4366
Joined: 13 May 2014, 17:15

Re: How to play sound on every keypress regardless of key and without affecting its function

04 Jul 2017, 11:57

Code: Select all

~a::c()
~b::c()
~c::c()

c(){
   Soundplay, C:\mechanical-switch.wav
   Return
   }
Tested, and working fine. Your (annoying) click sound isn't my favourite one, but it works the best because its duration fits (old typewriter sounds are lasting to long).

BTW, the sounds "preview"-file is listed within the source code: http://freesound.org/data/previews/254/ ... 622-lq.mp3
Last edited by BoBo on 05 Jul 2017, 07:37, edited 3 times in total.
robertcollier4
Posts: 33
Joined: 09 Apr 2016, 22:14

Re: How to play sound on every keypress regardless of key and without affecting its function

04 Jul 2017, 12:05

Look at KeyPressOSD for some sample code - https://autohotkey.com/boards/viewtopic.php?t=225

Code: Select all

	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
	}

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, boiler, Google [Bot], roysubs and 56 guests