-
Jan 5th, 2023, 01:37 PM
#1
Thread Starter
New Member
Capslock Start/Stop
Start the program with the capslock key. I want to stop it with the capslock button, can you help me?
Code:
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
-
Jan 5th, 2023, 03:07 PM
#2
Re: Capslock Start/Stop
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.
-
Jan 5th, 2023, 03:15 PM
#3
Re: Capslock Start/Stop
Code:
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:
Code:
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
-
Jan 6th, 2023, 08:36 AM
#4
Thread Starter
New Member
Re: Capslock Start/Stop
Originally Posted by techgnome
Code:
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:
Code:
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
it's just stopping. When I press capslock again, it doesn't work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|