topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 8:35 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Scroll Lock as system volume mute toggle  (Read 5249 times)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Scroll Lock as system volume mute toggle
« on: March 21, 2016, 08:16 AM »
Using AutoHotkey and nircmd makes it easy to use Scroll Lock key to toggle the master volume muting.

NirCmd download site

AutoHotkey download site

There is a built in functionality in AHK to send the volume mute key.  But it may not work on all systems.  More likely to be universal is the nircmd method.  If you run the script with Scroll Lock off then the Scroll Lock indicator LED on the keyboard should serve as the mute indicator.  This gives another visual cue to go with the system tray speaker icon with the line through it.

Here is the script

Edit:  The GetKeyState addition should sync the state of ScrollLock and the volume muting on script startup.

Code: Autohotkey [Select]
  1. ;
  2. ; any other settings here
  3. ;
  4. ; sync ScrollLock LED and volume muting on script start
  5. ;
  6. If (GetKeyState("ScrollLock","T"))
  7.   Run, nircmd mutesysvolume 1
  8. else
  9.   Run, nircmd mutesysvolume 0
  10.  
  11. ; Global Hotkey
  12. ;
  13. ~ScrollLock::
  14.    Run, nircmd mutesysvolume 2
  15. return

The tilde('~') character stops AHK from "eating" the keystroke.  This way the Scroll Lock LED should toggle as you press the key and mute/unmute the volume.  To avoid lighting the LED just delete the tilde.

To access nircmd from anywhere on your system it is recommended to copy it to the Windows directory.  If that is undesirable then copy the executable to a directory in your Path.
« Last Edit: March 21, 2016, 03:58 PM by MilesAhead »

eleman

  • Spam Killer
  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 413
    • View Profile
    • Donate to Member
Re: Scroll Lock as system volume mute toggle
« Reply #1 on: March 21, 2016, 08:22 AM »
You don't need an external utility to mute volume.

Try
Send {Volume_Mute}
in autohotkey. You can make it more functional and robust by adding a variable to keep the state of mute, and an if statement to check it.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Scroll Lock as system volume mute toggle
« Reply #2 on: March 21, 2016, 02:25 PM »
You don't need an external utility to mute volume.

Try
Send {Volume_Mute}
in autohotkey. You can make it more functional and robust by adding a variable to keep the state of mute, and an if statement to check it.

I tried that approach first.  It does not work on my Laptop. Probably because I have reversed the FN key so that the special keys are F1 to F12 by default.  I have to hold down the FN key to get the special key actions.  Anyway, if someone wants to change their script they are free to do so.  I find nircmd.exe can do dozens of handy things.  So I see no reason not to use it.


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Scroll Lock as system volume mute toggle
« Reply #3 on: March 21, 2016, 04:00 PM »
You can make it more functional and robust by adding a variable to keep the state of mute, and an if statement to check it.

Instead I added a GetKeyState() on script startup to put them in sync.  The code in my first post has the new lines.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Scroll Lock as system volume mute toggle
« Reply #4 on: March 23, 2016, 11:29 AM »
Added Shift Scroll Lock to resync the muting to the scroll lock Led indicator without having to rerun the script.  It just calls Reload.  This is useful if you should actually press the dedicated Mute Button throwing the scoll lock Led out of sync. I could poll but how often is muting really used?  I hardly ever mute since unmute would tend to blast the hardware if the volume was up high.  But anyway...   :)

Code: Autohotkey [Select]
  1. ;
  2. ; any other settings here
  3. ;
  4. ; sync ScrollLock LED and volume muting on script start
  5. ;
  6. If (GetKeyState("ScrollLock","T"))
  7.   Run, nircmd mutesysvolume 1
  8. else
  9.   Run, nircmd mutesysvolume 0
  10.  
  11. ; Global Hotkey
  12.  
  13. +ScrollLock::
  14.     Reload
  15. return
  16.  
  17. ~ScrollLock::
  18.    Run, nircmd mutesysvolume 2
  19. return