Thumbs upSolvedHotkeys on VB Program

Posts 1–10 of 10 · Page 1 of 1
Hotkeys on VB Program
Hiya I have tried many things to setup hotkeys on my VB programs and I really need to know how to get it to work!
1 time I got it but only 1 worked!
and 1 time I saw it didn't work if u had a theme and use theme button!
Any help??
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetKeyState(ByVal virtualKeyCode As Keys) As Boolean
End Function
Example:

Timer1_Tick Event:

If GetKeyState(Keys.F1) Then MessageBox.Show("Pressed Key: F1")


Timer 1:
Interval: 100 /Or what you like
Enabled: True /To have it active
Quote Originally Posted by Jorndel View Post


Example:

Timer1_Tick Event:





Timer 1:
Interval: 100 /Or what you like
Enabled: True /To have it active
Isn't it better to declare a single hotkey as boolean or declare multiple hotkeys as a single boolean and use And in between, then say

If ahotkey = true and bhotkey = True Then
'something happens
End If

That's what I use.
Quote Originally Posted by Cryptonic View Post


Isn't it better to declare a single hotkey as boolean or declare multiple hotkeys as a single boolean and use And in between, then say

If ahotkey = true and bhotkey = True Then
'something happens
End If

That's what I use.
You do as you please OFC
I just informed him about the function and gave an example on how to use it
Quote Originally Posted by Jorndel View Post


You do as you please OFC
I just informed him about the function and gave an example on how to use it
Yeah, under textbox1.textchanged
Quote Originally Posted by Cryptonic View Post


Yeah, under textbox1.textchanged


I removed the part as I didn't think correctly
-You can hook an keyboard input to the process but... This could be detected by most games

You have the form1.keydown/pressed event

But as it's to be hotkey(s). That won't work
Quote Originally Posted by Jorndel View Post




I removed the part as I didn't think correctly
-You can hook an keyboard input to the process but... This could be detected by most games

You have the form1.keydown/pressed event

But as it's to be hotkey(s). That won't work
Keydown is glitchy for me
I got the keydown to work I guess, but when I try to use e.SuppressKeyPress = True it fails. Though, if you want to talk about it go to the thread I made, don't wanna hijack thread :P
What i sometimes do is make the key only tick once so it wont repeat untill you release and press again.

On a timer with 50 or lower. Doesn't really matter if you have it lower since it only ticks once anyway.

Code:
If Keystate(Keys.F2) Then MsgBox("Only execute once")
Code:
#Region "Keys"

    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Keys) As Short

    Dim hKeys As New Dictionary(Of Keys, Boolean)

    Public Function Keystate(ByVal key As Keys) As Boolean
        Dim St As Integer = GetKeyState(key)
        If Not hKeys.ContainsKey(key) Then hKeys.Add(key, False)
        If St = -127 OrElse St = -128 Then
            If Not hKeys(key) Then
                hKeys(key) = True
                Return True
            End If
        Else
            hKeys(key) = False
            Return False
        End If
        Return False
    End Function

#End Region
well thx I got it last night but then it stoped working!
ill fix it soon! but thx for your help
/Solved
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?