[Solved]Set volume?

Posts 1–7 of 7 · Page 1 of 1
[Solved]Set volume?
How would I set the volume through vb?

Never found a good solution so its up to you guys now/yea

Hejsan
Quote Originally Posted by Zoom View Post


Thats for VB6, thanks anyways.

Any other solutions?
I created a smooth volume up / down code for my language. It's the simplest solution.

First declare this:
Private Declare Sub keybdevent Lib "user32"( ByVal bVk As Byte , ByVal bScan As Byte , ByVal dwFlags As Integer , ByVal dwExtraInfo As Integer )

Then create a timer and set its interval to 100. Add the following code to it:

For i As Integer = 1 To 100
Call keybdevent(Keys.VolumeUp,0,0,0)
Next

This will gradually increase the volume of the system.
To decrease the volume, just replace Keys.VolumeUp with Keys.VolumeDown.


You can simulate any key like this.

Hope this helps !!
Quote Originally Posted by Hassan View Post
I created a smooth volume up / down code for my language. It's the simplest solution.

First declare this:
Private Declare Sub keybdevent Lib "user32"( ByVal bVk As Byte , ByVal bScan As Byte , ByVal dwFlags As Integer , ByVal dwExtraInfo As Integer )

Then create a timer and set its interval to 100. Add the following code to it:

For i As Integer = 1 To 100
Call keybdevent(Keys.VolumeUp,0,0,0)
Next

This will gradually increase the volume of the system.
To decrease the volume, just replace Keys.VolumeUp with Keys.VolumeDown.


You can simulate any key like this.

Hope this helps !!
Had to change

Private Declare Sub keybdevent Lib "user32"( ByVal bVk As Byte , ByVal bScan As Byte , ByVal dwFlags As Integer , ByVal dwExtraInfo As Integer )

to:
Code:
  Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
and:

[html] For i As Integer = 1 To 100
Call keybd_event(Keys.VolumeUp, 0, 0, 0)
System.Threading.Thread.Sleep(40)
Next[/html]

/Solved
Quote Originally Posted by Zoom View Post


Had to change

Private Declare Sub keybdevent Lib "user32"( ByVal bVk As Byte , ByVal bScan As Byte , ByVal dwFlags As Integer , ByVal dwExtraInfo As Integer )

to:
Code:
  Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
and:

[html] For i As Integer = 1 To 100
Call keybd_event(Keys.VolumeUp, 0, 0, 0)
System.Threading.Thread.Sleep(40)
Next[/html]

/Solved
Oh shit..I used my custom VB.NET wrapper and it ignored the underscore. Sorry for that.

+ The effective way would be setting the interval of the timer to match ya needs. Timers work asynchronously so the application won't hang !!
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us