Jump to content

Windows Volume adjustment

Go to solution Solved by Pinguinsan,

In WinForms, the KeyEventArgs.KeyValue (raw value) for the keys (at least on my machine) are:

VolumeMute: 0xAD (173)
VolumeDown: 0xAE (174)
VolumeUp  : 0xAF (175)

You can confirm this on your machine if you have Visual Studio, just compile a simple C# WinForms application, put a button onto it (it will default to being named button1, then attach the KeyDown event to this block of code:

private void button1_KeyDown(Object sender, KeyEventArgs e) {
    System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
    messageBoxCS.AppendFormat("{0} = {1}", "Alt", e.Alt);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Control", e.Control);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Handled", e.Handled);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "KeyCode", e.KeyCode);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "KeyValue", e.KeyValue);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "KeyData", e.KeyData);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Modifiers", e.Modifiers);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Shift", e.Shift);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "SuppressKeyPress", e.SuppressKeyPress);
    messageBoxCS.AppendLine();
    MessageBox.Show(messageBoxCS.ToString(), "KeyDown Event");
}

Then run the application, place the mouse cursor over the button, and hit whatever button combination you want to know the code of.

So Im planning to build my own desk and part of it will include multiple buttons where I will sit to turn on my pc, one to restart it and the other 3 to adjust volume and mute the pc. I know to do the first 2 but my question is does anyone know the serial code for changing volume up, down and muting.

Main PC | AMD R7 3700X | Noctua D14 | MSI RTX 2080 Super XS OC | Corsair Vengence LPX 32GB DDR4 3200MHz | MSI B550A Pro | 1TB PNY XLR8 NVMe SSD | Kingston A400 960GB SSD | 2TB Western Digital Green HDD | Fractal Design Define R6TG |

Laptop (Asus TUF FX505DY) | AMD R5 3550H | RX560X | Crucial DDR4 16GB 2400MHz | Western Digital SN550 256GB SSD | PNY CS900 960GB SSD |

Phone | Samsung S10 Lite (128GB + 128GB SD card) |

Other Cool Stuff | Steam Link | Sontronics Podcast Pro | NZXT Hue+ | Corsair K70 MK 2 (MX Brown) | Logitech G402 | HiSense A7300 43 Inch 4K TV | Logitech C920 | Ender 3 Pro with Bulleye Fan duct and BLTouch |Sony PS4 | Nintendo Switch 

Link to comment
https://linustechtips.com/topic/891182-windows-volume-adjustment/
Share on other sites

Link to post
Share on other sites

Just now, wasab said:

I believe you can do this using some APIs from Microsoft.

 

do you have a link to the apI?

Main PC | AMD R7 3700X | Noctua D14 | MSI RTX 2080 Super XS OC | Corsair Vengence LPX 32GB DDR4 3200MHz | MSI B550A Pro | 1TB PNY XLR8 NVMe SSD | Kingston A400 960GB SSD | 2TB Western Digital Green HDD | Fractal Design Define R6TG |

Laptop (Asus TUF FX505DY) | AMD R5 3550H | RX560X | Crucial DDR4 16GB 2400MHz | Western Digital SN550 256GB SSD | PNY CS900 960GB SSD |

Phone | Samsung S10 Lite (128GB + 128GB SD card) |

Other Cool Stuff | Steam Link | Sontronics Podcast Pro | NZXT Hue+ | Corsair K70 MK 2 (MX Brown) | Logitech G402 | HiSense A7300 43 Inch 4K TV | Logitech C920 | Ender 3 Pro with Bulleye Fan duct and BLTouch |Sony PS4 | Nintendo Switch 

Link to post
Share on other sites

9 minutes ago, AdamBGames said:

do you have a link to the apI?

You could also use autohotkey but you'd need to make the buttons on the table send actual keystrokes or commands to the PC in order for autohotkey to recognise them. You could do this easily with any macro board, no matter how cheap it is, as long as it offers a way to send keystrokes. Even an external numpad can do this

Don't forget to quote when replying to me

Link to post
Share on other sites

In WinForms, the KeyEventArgs.KeyValue (raw value) for the keys (at least on my machine) are:

VolumeMute: 0xAD (173)
VolumeDown: 0xAE (174)
VolumeUp  : 0xAF (175)

You can confirm this on your machine if you have Visual Studio, just compile a simple C# WinForms application, put a button onto it (it will default to being named button1, then attach the KeyDown event to this block of code:

private void button1_KeyDown(Object sender, KeyEventArgs e) {
    System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
    messageBoxCS.AppendFormat("{0} = {1}", "Alt", e.Alt);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Control", e.Control);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Handled", e.Handled);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "KeyCode", e.KeyCode);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "KeyValue", e.KeyValue);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "KeyData", e.KeyData);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Modifiers", e.Modifiers);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "Shift", e.Shift);
    messageBoxCS.AppendLine();
    messageBoxCS.AppendFormat("{0} = {1}", "SuppressKeyPress", e.SuppressKeyPress);
    messageBoxCS.AppendLine();
    MessageBox.Show(messageBoxCS.ToString(), "KeyDown Event");
}

Then run the application, place the mouse cursor over the button, and hit whatever button combination you want to know the code of.

Link to post
Share on other sites

Just posting for future searchers, as this is a couple days old.

 

Ther is a nice API for audio streaming and rendering for the .NET stack called:

 AudioSwitcher.AudioApi.CoreAudio

If you are using Visual Studio, right click on the dependencies/reference menu item and select "Manage NuGet Packages" and search for the above snippet then install. Add the namespace to the top of your class file with (in C#, use 'imports' instead of 'using' for VB.net):

 

using AudioSwitcher.AudioApi.CoreAudio;

Then in the method where you want to control the audio, you can use it like this to adjust the volume.

CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;
defaultPlaybackDevice.Volume = 80;
The MSDN documentation for the whole, very useful, API is here : https://msdn.microsoft.com/en-us/library/windows/desktop/dd370802(v=vs.85).aspx
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×