# Visual Basic > Visual Basic .NET >  Capslock Start/Stop

## StebX

Start the program with the capslock key. I want to stop it with the capslock button, can you help me?



```
Private Sub Timer50_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer50.Tick
      
        Dim capsstop As Boolean
        Dim capsstart As Boolean
        

        
        capsstart = GetAsyncKeyState(Keys.CapsLock)
        capsstop = GetAsyncKeyState(Keys.CapsLock)


        If capsstart = True Then
            Button3.PerformClick()
            Me.Text = "  -------->  ... STOP ..."
        End If

        If capsstop = True Then
            Button4.PerformClick()
            Me.Text = "  -------->  ... START ..."
        End If
```

----------


## PlausiblyDamp

You could try https://learn.microsoft.com/en-us/do...ol.iskeylocked as an easier way of figuring it out.

Also in your code calling the Getasynckeystate function twice is just going to return the same value twice (unless the caps lock is pressed at exactly the right time) so both of the variables will have the same value.

----------


## techgnome

```
        Dim capsstop As Boolean
        Dim capsstart As Boolean

        capsstart = GetAsyncKeyState(Keys.CapsLock)
        capsstop = GetAsyncKeyState(Keys.CapsLock)
```

These lines are useless... you're getting the same value from both calls ...

What you probably want is this:


```
        Dim capStatusOn As Boolean

        capStatusOn = GetAsyncKeyState(Keys.CapsLock)

        If capStatusOn = True Then
            Button4.PerformClick()
            Me.Text = "  -------->  ... START ..."
        Else
            Button3.PerformClick()
            Me.Text = "  -------->  ... STOP ..."
        End If
```

When the caps lock is on, it'll run the program ... hmmm... there probably should be another flag to indicate if it's already running (or not running) so it doesn't try to start it again once it is started (or try to stop it if it's already stopped)


-tg

----------


## StebX

> ```
>         Dim capsstop As Boolean
>         Dim capsstart As Boolean
> 
>         capsstart = GetAsyncKeyState(Keys.CapsLock)
>         capsstop = GetAsyncKeyState(Keys.CapsLock)
> ```
> 
> These lines are useless... you're getting the same value from both calls ...
> ...


it's just stopping. When I press capslock again, it doesn't work.

----------

