Simple question - What is the equivalent of a "Send Key" ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

    Simple question - What is the equivalent of a "Send Key" ?

    For example, how could you programatically "click" on a button in a Form ?


  • =?ISO-8859-1?Q?Lorenz_H=F6lscher?=

    #2
    Re: Simple question - What is the equivalent of a "Send Key" ?

    Hi Rob,

    if you have some code like

    Private Sub btnOK_Click(... ..)
    MsgBox("Hi there")
    End Sub


    und you want to run it anywhere else simply call this procedure like
    any other procedure by its name:

    btnOK_Click

    If you sometimes don't want to fill in all the arguments of these
    reserved event procedures change the code into:

    Private Sub btnOK_Click(... ..)
    MyOK
    End Sub

    Private Sub MyOK()
    MsgBox("Hi there")
    End Sub

    and call MyOK instead of btnOK_Click.

    bye, Lorenz

    Comment

    • kimiraikkonen

      #3
      Re: Simple question - What is the equivalent of a "Send Key" ?

      On Sep 29, 1:00 pm, "Rob" <ro...@yahoo.co mwrote:
      For example, how could you programatically "click" on a button in a Form ?
      Assuming you have a event sub that handles Button1.Click like:

      Private Sub Button1_Click(B yVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles Button1.Click

      ' Code block here when button is pressed

      End Sub

      ....and if you want to execute the same code block inside Button1_Click
      as if Button1 is clicked, to do so, you can simply try to call sub
      from anywhere:

      Button1_Click(s ender, e)


      Hope this helps,

      Onur Güzel

      Comment

      • Bill McCarthy

        #4
        Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

        Hi Rob,

        "Rob" <robc1@yahoo.co mwrote in message
        news:68qdnQnSSP i1NX3VnZ2dnUVZ_ u2dnZ2d@comcast .com...
        For example, how could you programatically "click" on a button in a Form ?
        Button has a PerformClick method.
        Alternatively use My.Computer.Key board.SendKeys

        Comment

        • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

          #5
          RE: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

          I've normally used SendKey to send to an external application. With that in
          mind, assuming you want to click a button in an external application, the
          equivalent could be to use send keys to send "{ENTER}". You have to navigate
          in the external app so the active button is selected. I did this with
          sendkeys {TAB}. Fortunatly for me the external application was a well
          defined interface, meaning, upon startup, I knew how many tabs to hit to get
          to my button of interest.

          If you are talking about programatically clicking a button in your own app,
          the other answers are appropriate.

          "Rob" wrote:
          For example, how could you programatically "click" on a button in a Form ?
          >
          >
          >

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

            "Rob" <robc1@yahoo.co mschrieb:
            For example, how could you programatically "click" on a button in a Form ?
            If you are talking about other processes: P/invoke + 'SendInput'.

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

              Rob,

              Why would you use an event when you can direct invoke the method?

              \\\
              Button_ClickEve nt(me,nothing)
              ///

              This works as well as the button has not the focus.

              Cor

              "Rob" <robc1@yahoo.co mschreef in bericht
              news:68qdnQnSSP i1NX3VnZ2dnUVZ_ u2dnZ2d@comcast .com...
              For example, how could you programatically "click" on a button in a Form ?
              >

              Comment

              • Phill W.

                #8
                Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

                Cor Ligthert[MVP] wrote:
                Why would you use an event when you can direct invoke the method?
                Button_ClickEve nt(me,nothing)
                This works as well as the button has not the focus.
                It might do, but IMHO, it's a bad habit to get into.

                PerformClick() does all the same checks as clicking the button manually
                (e.g. you can't PerformClick a disabled button) and you don't have to
                worry about getting hold of valid EventArgs to pass to the "method"
                call. OK, for Click events they're pretty simple, but just try it with
                some of the /other/ events. ;-)

                Also, the "sender" argument should be the Control /raising/ the event,
                not the form /handling/ it, so ...

                Button1_Click( Button1, EventArgs.Empty )

                .... would be more correct.

                HTH,
                Phill W.

                Comment

                • Cor Ligthert[MVP]

                  #9
                  Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

                  Phill,

                  Do what you want, I have the oposite expirience as you.

                  Cor

                  "Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschreef in bericht
                  news:gbt7co$j0t $1@south.jnrs.j a.net...
                  Cor Ligthert[MVP] wrote:
                  >
                  >Why would you use an event when you can direct invoke the method?
                  >
                  > Button_ClickEve nt(me,nothing)
                  >
                  >This works as well as the button has not the focus.
                  >
                  It might do, but IMHO, it's a bad habit to get into.
                  >
                  PerformClick() does all the same checks as clicking the button manually
                  (e.g. you can't PerformClick a disabled button) and you don't have to
                  worry about getting hold of valid EventArgs to pass to the "method" call.
                  OK, for Click events they're pretty simple, but just try it with some of
                  the /other/ events. ;-)
                  >
                  Also, the "sender" argument should be the Control /raising/ the event, not
                  the form /handling/ it, so ...
                  >
                  Button1_Click( Button1, EventArgs.Empty )
                  >
                  ... would be more correct.
                  >
                  HTH,
                  Phill W.

                  Comment

                  • Tom Shelton

                    #10
                    Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

                    On 2008-09-29, Rob <robc1@yahoo.co mwrote:
                    For example, how could you programatically "click" on a button in a Form ?
                    >
                    >
                    Can you be more specific? Are you talking about a form in your application or
                    in another applciation? In otherwords, cross process or same process?

                    --
                    Tom Shelton

                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: Simple question - What is the equivalent of a &quot;Send Key&quot; ?

                      "Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kschrieb:
                      >Why would you use an event when you can direct invoke the method?
                      >
                      > Button_ClickEve nt(me,nothing)
                      >
                      >This works as well as the button has not the focus.
                      >
                      It might do, but IMHO, it's a bad habit to get into.
                      >
                      PerformClick() does all the same checks as clicking the button manually
                      (e.g. you can't PerformClick a disabled button) and you don't have to
                      worry about getting hold of valid EventArgs to pass to the "method" call.
                      OK, for Click events they're pretty simple, but just try it with some of
                      the /other/ events. ;-)
                      >
                      Also, the "sender" argument should be the Control /raising/ the event, not
                      the form /handling/ it, so ...
                      >
                      Button1_Click( Button1, EventArgs.Empty )
                      >
                      ... would be more correct.
                      I agree. It fulfills the contract of the event. Nevertheless, I would not
                      call the event handler directly.

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                      Comment

                      Working...