OnKeyDown Event (When does it initially fire ?)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ApexData@gmail.com

    #1

    OnKeyDown Event (When does it initially fire ?)

    I'm using the OnKeyDown event in hopes of capturing a key being held
    down during the initial startup of my application. Does anyone know,
    at what point the OnKeyDown event fires?

    I checked to see if the key would be captured in the OnOpen and OnLoad
    or Initial OnCurrent event, but this does not seem to be the case.
    Can I capture a key in these events?

    Public CkOnOpenKey As Boolean
    CkOnOpenKey = True 'Placed in the OnOpen event

    Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
    'Key interpreter. Restricts keys.
    If CkOnOpenKey Then
    If KeyCode = 88 Then
    MsgBox "The X key was pressed"
    End If
    End If
    End Sub

    Private Sub Form_Load()
    'Check if he X key is pressed and held during the app startup
    Call Pauser(2) 'Pause for 2 seconds
    'The message "The X Key was pressed" should appear, but doesn't
    CkOnOpenKey = False ' The app is running. Shut off the check
    End Sub

  • storrboy

    #2
    Re: OnKeyDown Event (When does it initially fire ?)

    It's not likely that a form can read an event that occurs before it's
    life cycle starts. Kind of like asking a 4 year old what happened 5
    years ago. However it may be possible to capture it with an API call.
    This is tested only so far as it displays X as the last button pressed
    (held down while opening form). May need to finagle it some to do what
    you want, might be a starting point. Gleaned from API-Guide.

    Insert into module..

    Private Declare Function GetAsyncKeyStat e Lib "user32" (ByVal vKey As
    Long) As Integer

    Function GetPressedKey() As String
    Dim cnt As Long
    For cnt = 32 To 128
    'Get the keystate of a specified key
    If GetAsyncKeyStat e(cnt) <0 Then
    GetPressedKey = Chr$(cnt)
    Exit For
    End If
    Next cnt
    End Function

    Form event..

    Private Sub Command0_Click( )
    MsgBox GetPressedKey
    End Sub



    Comment

    • Tom Clavel

      #3
      Re: OnKeyDown Event (When does it initially fire ?)

      The keyDown event happens when you put the key down, but when before
      you open the application there is no event manager, so it won't fire.
      It does not look at a key that is already down. Either open the
      application from a different mdb, or have a form open on startup that
      will then allow you to process keystrokes. What are you trying to
      accomplish? tc


      ApexData@gmail. com wrote:
      I'm using the OnKeyDown event in hopes of capturing a key being held
      down during the initial startup of my application. Does anyone know,
      at what point the OnKeyDown event fires?
      >
      I checked to see if the key would be captured in the OnOpen and OnLoad
      or Initial OnCurrent event, but this does not seem to be the case.
      Can I capture a key in these events?
      >
      Public CkOnOpenKey As Boolean
      CkOnOpenKey = True 'Placed in the OnOpen event
      >
      Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
      'Key interpreter. Restricts keys.
      If CkOnOpenKey Then
      If KeyCode = 88 Then
      MsgBox "The X key was pressed"
      End If
      End If
      End Sub
      >
      Private Sub Form_Load()
      'Check if he X key is pressed and held during the app startup
      Call Pauser(2) 'Pause for 2 seconds
      'The message "The X Key was pressed" should appear, but doesn't
      CkOnOpenKey = False ' The app is running. Shut off the check
      End Sub

      Comment

      • ApexData@gmail.com

        #4
        Re: OnKeyDown Event (When does it initially fire ?)

        >What are you trying to accomplish? tc


        I have a Startup form that calls my MainMenu.
        The Startup Form checks to make sure its environment is up to par (ie
        Checks
        the Version of Access, Checks if all the files that support the app
        are available, etc...)

        This form is never displayed, and simply does as I mentioned and then
        calls the MainMenu.

        I wanted to have a Keypressed (ie HeldDown) on startup, that would
        allow me to launch a popup form before all these checks take place.
        This popup form would allow me to change the FE Data, that I hope to
        store info about the BE in.

        I guess I'll have to put in a Pre-Startup form to do this ???

        Thanks
        Greg

        Comment

        • ApexData@gmail.com

          #5
          Re: OnKeyDown Event (When does it initially fire ?)

          Hello Mike

          I tried the API call you supplied, and it worked. I'm not too
          familiar with the API calls and am wondering if this is considered
          unconventional, and if I will run into any issues with it depending
          upon the environment (ie Version of Access or Windows) ???

          I was hoping for a control sequence, like ctrl-alt-A Would I be able
          to implement this using this function?

          Where can I get more information on API calls (API Guide) ?

          Thanks Again
          Greg

          Comment

          • storrboy

            #6
            Re: OnKeyDown Event (When does it initially fire ?)

            On Mar 9, 6:02 pm, "ApexD...@gmail .com" <ApexD...@gmail .comwrote:
            What are you trying to accomplish? tc
            >
            I have a Startup form that calls my MainMenu.
            The Startup Form checks to make sure its environment is up to par (ie
            Checks
            the Version of Access, Checks if all the files that support the app
            are available, etc...)
            >
            This form is never displayed, and simply does as I mentioned and then
            calls the MainMenu.
            >
            I wanted to have a Keypressed (ie HeldDown) on startup, that would
            allow me to launch a popup form before all these checks take place.
            This popup form would allow me to change the FE Data, that I hope to
            store info about the BE in.
            >
            I guess I'll have to put in a Pre-Startup form to do this ???
            >
            Thanks
            Greg
            Or just use the Shift-Click method, make your changes and re-start it.
            Or display a splash screen for 5 seconds or show. Use the KeyDown or
            KePress events of this form to interupt the process.

            Comment

            • storrboy

              #7
              Re: OnKeyDown Event (When does it initially fire ?)

              Your #1 source for using API-functions in Visual Basic and classes for the .NET runtime!


              It's a great tool. There is another free one out there, but I can't
              remember what it's called. It was really goo too.
              I think it's no longer updated or maintained, but it has most of what
              you'd need in it.

              Since APIs can affect a great many things on a computer, most should
              be employed with care. Take the time to understand them before you use
              them. The MSDN web site details most if not all of them fairly well,
              although some can be awkward to find.

              They're not unconventional, but primarily used by more advanced users
              and developers. There is nothing wrong with using and sometimes they
              are better than the standard methods.

              Most of the APIs are supported by any Windows version newer than 95,
              but some do require the NT based versions (NT4, , 2000, XP).

              Comment

              • ApexData@gmail.com

                #8
                Re: OnKeyDown Event (When does it initially fire ?)

                Thanks again Mike for all the good info.

                >Or just use the Shift-Click method, make your changes and re-start it.
                This sounds interesting.

                If you don't mind! What is the Shift-Click method and can I use it
                without the API?

                Greg

                Comment

                • storrboy

                  #9
                  Re: OnKeyDown Event (When does it initially fire ?)


                  Hold down the Shift button while you double click the DB file icon or
                  a shortcut.
                  This prevents startup settings and the AutoExec macro (if there is
                  one) from running.
                  Make your changes or manually run other code to do so, then close and
                  restart normally.

                  (Reading my last few msgs - man I can't spell today)

                  Comment

                  Working...