Results 1 to 6 of 6
  1. #1
    Alroundeath's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    331
    Reputation
    8
    Thanks
    29
    My Mood
    Amused

    [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
    Last edited by Alroundeath; 04-22-2010 at 06:47 PM.

  2. #2
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    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

    Last edited by NextGen1; 04-22-2010 at 06:56 PM.

  3. The Following User Says Thank You to NextGen1 For This Useful Post:

    Alroundeath (04-23-2010)

  4. #3
    Alroundeath's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    331
    Reputation
    8
    Thanks
    29
    My Mood
    Amused
    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 =/

  5. #4
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful
    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 !

  6. The Following 2 Users Say Thank You to MJLover For This Useful Post:

    Alroundeath (04-23-2010),NextGen1 (04-22-2010)

  7. #5
    Alroundeath's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    331
    Reputation
    8
    Thanks
    29
    My Mood
    Amused
    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 =/

  8. #6
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Marked Solved , Avoid posting unless necessary and <= 7 days

Similar Threads

  1. [Help Request] Help me to solve this ? :#
    By josias008 in forum Combat Arms Help
    Replies: 9
    Last Post: 08-06-2011, 12:05 AM
  2. help me. Bounty Cash AnD Third person ON / of toggle key
    By darkorlegend in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 14
    Last Post: 05-26-2011, 10:48 AM
  3. [Help]Keyboard key[Solved]
    By bo76 in forum Visual Basic Programming
    Replies: 15
    Last Post: 01-11-2011, 03:02 PM
  4. [Help] Missing Tabs [Solved]
    By zmansquared in forum Visual Basic Programming
    Replies: 18
    Last Post: 03-11-2010, 06:25 PM
  5. [Help]Custom GUI[Solved]
    By martijno0o0 in forum Visual Basic Programming
    Replies: 1
    Last Post: 03-07-2010, 06:43 AM