Hi, i'm trying to make a soundboard and I can make buttons play a sound, but I want the user to be able to select a key, and everytime he presses that key, the sound will play.
Anyone know how to do this?
Okey.
Timer needs to have 10 ms delay or less, you can change the key by selecting a key in Keys.<KEYHERE>.
IF you want the user to set the key, try a combo box of all the keys.
PHP Code
<?php Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If GetAsyncKeyState(Keys.A) Then Button1.PerformClick() System.Threading.Thread.Sleep(100) End If End Sub
DO NOT DEAL WITH THIS MEMBER
If this is global, look into RegisterHotKey with PInvoke. Just remember to free it on FormClosing.
(May 29, 2015 12:16 PM)wizardwizard Wrote: Okey.
Timer needs to have 10 ms delay or less, you can change the key by selecting a key in Keys.<KEYHERE>.
IF you want the user to set the key, try a combo box of all the keys.
PHP Code
<?php Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If GetAsyncKeyState(Keys.A) Then Button1.PerformClick() System.Threading.Thread.Sleep(100) End If End Sub
Thank you sir, appreciated.
(May 29, 2015 12:16 PM)wizardwizard Wrote: Okey.
Timer needs to have 10 ms delay or less, you can change the key by selecting a key in Keys.<KEYHERE>.
IF you want the user to set the key, try a combo box of all the keys.
PHP Code
<?php Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If GetAsyncKeyState(Keys.A) Then Button1.PerformClick() System.Threading.Thread.Sleep(100) End If End Sub
However when I press A it doesn't want to play the sound?
I've added the code you gave to the timer but nothing happens when I press A or any other button if I set it to another?
DO NOT DEAL WITH THIS MEMBER
PHP Code
<?php Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer Dim hotkey As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True Timer1.Interval = 100 End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick hotkey = GetAsyncKeyState(Keys.A) If hotkey = True Then Button1.PerformClick() System.Threading.Thread.Sleep(100) End If End Sub
There you go, hope this helps
(Jun 3, 2015 09:00 AM)LUOIdeRentA Wrote: PHP Code
<?php Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer Dim hotkey As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True Timer1.Interval = 100 End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick hotkey = GetAsyncKeyState(Keys.A) If hotkey = True Then Button1.PerformClick() System.Threading.Thread.Sleep(100) End If End Sub
There you go, hope this helps
Thank you so much got it working now!!
(Jun 3, 2015 09:00 AM)LUOIdeRentA Wrote: PHP Code
<?php Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer Dim hotkey As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True Timer1.Interval = 100 End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick hotkey = GetAsyncKeyState(Keys.A) If hotkey = True Then Button1.PerformClick() System.Threading.Thread.Sleep(100) End If End Sub
There you go, hope this helps
Thank you so much got it working now!!
|