[Help]Toggle Key[Solved]

Posts 1–6 of 6 · Page 1 of 1
[Help]Toggle Key[Solved]
Just a hopefully simple question, I have a hotkey that turns a spammer on, just one to turn it off. I want the same key that turns it on, to turn it off.

Code:
Public Class Form1


    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Short


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        spam.Enabled = True

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        spam.Enabled = False
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
        Dim f7 As Boolean
        f7 = GetAsyncKeyState(Keys.F7)
        If f7 = True Then
            spam.Enabled = True
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles spam.Tick
        SendKeys.Send(TextBox1.Text)
        SendKeys.Send("{Enter}")
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        hotkeys.enabled = True
        spam.Enabled = False
        hotkeys2.Enabled = True
        spam2.Enabled = False
    End Sub


    Private Sub ComboBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.TextChanged
        Try
            spam.Interval = Val(ComboBox2.Text)

            If Val(ComboBox2.Text) = 0 Then
                spam.Interval = 100
            End If
        Catch
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        spam2.Enabled = True
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        spam2.Enabled = False
    End Sub
    Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
        Try
            spam.Interval = Val(ComboBox1.Text)

            If Val(ComboBox1.Text) = 0 Then
                spam.Interval = 100
            End If
        Catch
        End Try
    End Sub

    Private Sub hotkeys2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys2.Tick
        Dim f8 As Boolean
        f8 = GetAsyncKeyState(Keys.F8)
        If f8 = True Then
            spam2.Enabled = True
        End If
    End Sub
    Private Sub spam2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles spam2.Tick
        SendKeys.Send(TextBox2.Text)
        SendKeys.Send("{Enter}")
    End Sub
End Class
An idea on how to accomplish this, or even a helpful link would be appreciated

The reason I want a 'toggle' key, is to leave more keys accessible if I wanted
to add more features. Thanks to Blubb1337 I managed to learn how to make global hotkeys without a module ;o But now I'm having trouble making the same hotkey do different things.

My assumption would be something like:


Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
        Dim f7 As Boolean
        f7 = GetAsyncKeyState(Keys.F7)
        If f7 = True Then
             If
            spam.Enabled = True Then
            If F7 = True Then
            spam.Enabled = False
            End If
        End If
    End Sub
Then again, I absolutely SUCK at coding ;o
I didn't actually read through the code, but create a flag

[php]
Dim fON as boolean = False
[/php]

[php]
'If you want the flag on
fON = true
[/php]

[php]
'If you want the flag off
fON = false
[/php]
then you can use the flag in If Then Statements

[php]
If fON = true then

else

end if
[/php]

Btw , for all purposes , in this case Flag = Toggle On/Off, So fON = Toggle on/off

Quote Originally Posted by NextGen1 View Post
I didn't actually read through the code, but create a flag

[php]
Dim fON as boolean = False
[/php]

[php]
'If you want the flag on
fON = true
[/php]

[php]
'If you want the flag off
fON = false
[/php]
then you can use the flag in If Then Statements

[php]
If fON = true then

else

end if
[/php]

Btw , for all purposes , in this case Flag = Toggle On/Off, So fON = Toggle on/off

I'm sorry, but I don't understand =/
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
Dim f7 As Boolean
f7 = GetAsyncKeyState(Keys.F7)
If f7 = True Then
If
spam.Enabled = True Then
If F7 = True Then
spam.Enabled = False
End If
End If
End Sub
Man, this is easy. Nextgen is right, but you don't understand that. ok here you go:

Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
     Dim f7 As Boolean
     f7 = GetAsyncKeyState(Keys.F7)
     If f7 = True Then
If  spam.Enabled = True Then

spam.Enabled = False
Else
spam.Enabled = True

End If
End If
End Sub
This will toggle any action you want !! Hope this helps !
Quote Originally Posted by MJLover View Post
Man, this is easy. Nextgen is right, but you don't understand that. ok here you go:

Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hotkeys.Tick
     Dim f7 As Boolean
     f7 = GetAsyncKeyState(Keys.F7)
     If f7 = True Then
If  spam.Enabled = True Then

spam.Enabled = False
Else
spam.Enabled = True

End If
End If
End Sub
This will toggle any action you want !! Hope this helps !
Aha!! I get it now! Epic, that's kind of what I had in mind, but I had them chained together. Thank, to both of you ^^ I guess I just needed an example to understand a little bit =/
Marked Solved , Avoid posting unless necessary and <= 7 days
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us