Results 1 to 4 of 4

Thread: Capslock Start/Stop

  1. #1

    Thread Starter
    New Member StebX's Avatar
    Join Date
    Nov 2018
    Posts
    3

    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

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    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.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member StebX's Avatar
    Join Date
    Nov 2018
    Posts
    3

    Re: Capslock Start/Stop

    Quote Originally Posted by techgnome View Post
    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
  •  



Click Here to Expand Forum to Full Width