Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How can I make user set hotkeys to press a button?

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 
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?
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!!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by QU35TFeb 10, 2022 10:19 AM 2 128 Feb 10, 2022 10:19 AM
Last Post: QU35T
[.NET] by FateNov 5, 2020 12:46 PM 3 154 Nov 5, 2020 12:46 PM
Last Post: Fate
[Python] by ICUPApr 3, 2020 08:21 AM 3 186 Apr 3, 2020 08:21 AM
Last Post: lockhead