-1

I'm relatively new to programming and I want to make a script that controls the volume of my pc, linkt to hotkeys. What I want it to do specifically is whenever I press a key on my keyboard (i.e. ctrl + Alt + arrow up), it turns the volume to 75% and when I press another key (i.e. ctrl + Alt + arrow down), it turns it to 15%.

What type of script would I need to make, where shoult it be saved and how do I setup a hotkey to trigger it? (Also, I want this to work as soon as my pc boots up, or right thereafter). You don't need to prewrite a script for me, just point me in the right direction and I'll find my way.

This is what I've got so far:

; Volume control (turn master volume to 75% or 15%)
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^!F12::Soundset, 75
^!F11::Soundset, 15

This works fine, but I use it on a laptop, which also has a function (fn) key to in-/decrease volume and mute it. Now, whenever I mute using the function key, I cannot set de volume to 75% with the hotkey. So I was wondering if I could override the function key (or whenever I press ctrl + fn + volume up/down it sets it to 75%, or 15%, respectivily). Also the script doesn't give any visual feedback, apart from the volume icon showing more or less volume bars (or however it's called). How would I go about doing this?

ALso, do I need those first few lines (e.g. #NoEnv, #Warn,...) or are they just for failsafe?

Any help would be much appreciated.

Morteza Asadi
  • 1,819
  • 2
  • 22
  • 39
Nico V
  • 107
  • 1
  • 9
  • You should start here: https://autohotkey.com/docs/AutoHotkey.htm – 2501 Apr 11 '16 at 19:14
  • Note: I am aware there is this thing called AutoHotkey and I've seens scripts that allow you to incramentally in-/decrease the volume, but I'm interested in writing my own script that sets the volume the desired percentage. – Nico V Apr 11 '16 at 19:34
  • @Nico V, After you look at the link posted by `2501` take a look at the link below. Then TRY IT YOURSELF (it is really not hard) and post your results, or attempts and failures and then ask specific questions about what works and doesn't work. That's how you learn. That's how we can help you. Good luck! – PGilm Apr 11 '16 at 20:07

1 Answers1

0

Look at the link in 2501's comment first. Try some things for yourself.

Then look here: https://autohotkey.com/docs/commands/SoundSet.htm which will tell you about SoundSet. Then try some more things yourself.

SoundSet

Changes various settings of a sound device (master mute, master volume, etc.)

SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]

NewSetting: Percentage number between -100 and 100 inclusive (it can be a floating point number or expression). If the number begins with a plus or minus sign, the current setting will be adjusted up or down by the indicated amount. Otherwise, the setting will be set explicitly to the level indicated by NewSetting.

PGilm
  • 2,262
  • 1
  • 14
  • 26
  • I would have left this as a comment, but I can't figure out how to get the formatting to work in comments. – PGilm Apr 11 '16 at 20:04
  • Jeez looks like OP used my answer to edit his post and mostly solve his issue, yet I get a DV? – PGilm Apr 12 '16 at 03:03
  • Finding out the mute state of an audio device and then setting it to unmute is easy in AHK -- just take a look at `VA.AHK` (search for it). Also, getting visual feed back is easy, too. Maybe use a `MsgBox` (which can self-dismiss after a few seconds) or a "progress bar" (lots of AHK implementations). In fact, getting the key scan code for the Fn key on your laptop is also something that can usually be accomplished. @2501's link can point you to that, too. Have fun, and remove the DV (or UV) as my answer clearly helped you (even if you don't accept it as a 'complete' answer)! – PGilm Apr 12 '16 at 14:42