Link to home
Start Free TrialLog in
Avatar of Max Destiny
Max Destiny

asked on

Hey Audio!

Hey I'm trying to change the value of my Audio volume but I can find Audio in System.Windows.Input;
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

You can simulate the user using the keyboard keys:

[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

Open in new window

Avatar of Max Destiny
Max Destiny

ASKER

ok thank you!
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hmm I have this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication143
{
    public partial class Form1 : Form
    {
        public const int VolumeHandler = 0x319;
        public const int VolumeUp = 0xA0000;
        public const int VolumeDown = 0x90000;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        [DllImport("newuser36.dll")]
        public static extern IntPtr RealtekHighDefinitionAudio(IntPtr WPARAM, IntPtr NMAPAR, int Msg,IntPtr VolumeHandler);

        private void VolumeUpMain()
        {
            RealtekHighDefinitionAudio(this.Handle, this.Handle, VolumeUp, (IntPtr)VolumeHandler);
        }
        private void VolumeDownMain()
        {
            RealtekHighDefinitionAudio(this.Handle, this.Handle, VolumeDown, (IntPtr)VolumeHandler);
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.A)
            {
                VolumeUpMain();
            }
            if (e.KeyCode == Keys.B)
            {
                VolumeDownMain();
            }
        }
    }
}
and it says that it cannot find the device(HResult:0x8007007E)
Is this a new Audio Device you installed? If yes did it install without issues?
yes no issues
It seems that this sounds like a hardware issue. Have you also checked the manufacturers web site to see if there are any API calls that differs from Windows standards for the volume increase and decrease commands?
hmmm no:)
Well then if the hardware installed correctly and the hardware does not use their own API's to control volume and use the standard Microsoft API's and it is still not working then I am at a lost and do not know what else to have you do.