[VB2010] Toggle Switch style hotkey?

07/10/2011 17:53 Just.a.Guy#1
Hi,

I've developed a application for a game, which have some hotkeys. But now, i want to make a hotkey that, when is pressed the first time, a timer will start. When pressed again, the timer will stop, then when pressed the third time, the timer would start. Can someone help me?
07/10/2011 18:47 Kraizy​#2
Use a little variable:
PHP Code:
Dim var as Boolean

//Hotkey_Pressed:
var = True = var = False //switches between true & false

Select case var
   Case 
True //if true then timer.start
      
Timer.Start
   
Case Else //if false then timer.stop
      
Timer.Stop
End Select 
07/10/2011 22:03 Just.a.Guy#3
didn't worked... I'm using GetAsyncKeyState...
07/11/2011 13:36 Kraizy​#4
Well, it would be helpful if you could tell me what didn't work..
If you are using GetAsyncKeyState you would already have created an event which is being called when pressing a key. There you have to put in the Select Case from above.
07/22/2011 20:49 Just.a.Guy#5
I'm sorry if i took so long to answer. I have this code to start my script
PHP Code:
 Private Sub Timer3_Tick(ByVal sender As System.ObjectByVal e As System.EventArgsHandles timkeys.Tick
        
'Função principal
        If (GetAsyncKeyState(Keys.ControlKey)) Then            
            timrsb.Start()
            timammo.Start()
            timrocket.Start()
            timhs1.Start()
            tim_i.Start()           
        End If

        If (GetAsyncKeyState(Keys.ShiftKey)) Then '
Stop script
            timrsb
.Stop()
            
timammo.Stop()
            
timrocket.Stop()
            
timhs1.Stop()
            
timjump.Stop()
            
tim_i.Stop()
            
timammo.Interval 4000
        End 
If    

    
End Sub 
GetAsyncKeyState is used with a timer, which interval is set to 1ms. I think that this is why is not working.