1

To increase and decrease the volume I use this code (c#):

[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);

keybd_event((byte)Keys.VolumeUp, 0, 0, 0); // increase volume
keybd_event((byte)Keys.VolumeDown, 0, 0, 0); // decrease volume

How can I raise and lower the volume by 10% and How I can mute or set to full volume? I use a loop to decrease and increase the volume But I do not think that's the right way.

Danny
  • 161
  • 1
  • 2
  • 7
  • Please [edit] your question to add a tag for the language you're using and the framework you're using. No-one will find your question otherwise with such a generic tag. – Mat Mar 09 '14 at 07:56
  • possible duplicate of [How can I control system sound volume with a TrackBar?](http://stackoverflow.com/questions/13232085/how-can-i-control-system-sound-volume-with-a-trackbar) – keenthinker Mar 09 '14 at 09:43

1 Answers1

-1

This example is from a speech recognition system I'm designing in C#. The first image is your Variable Declarations, this is a vital part to fulfill first. This goes just under the top of your project/code (Under Public Class Form) -Void the Timer Declarations- In the second image, you will see that I used a Switch/Case statement, which are similar to If & Else statements, both designed for executing one case at a time. You may very well be using something other than Case or If statements, and if that's the case, I would make your cases into a function, calling the function to satisfy certain conditions. I am essentially using an Iteration Statement as seen in the 2nd picture to produce 10 loops at once for my volume. I declared and initialize a local loop variable in that section.

First Step/Public Class Form

2nd Step

  • 1
    Hello and welcome to StackOverflow! Please refrain from posting images of your code and instead post them in code blocks. – Ad5001 Aug 01 '21 at 15:32