Question:
Microsoft Visual Basic automatic button press.?
Mattmatician
2006-05-28 09:10:33 UTC
In Microsoft Visual Basic, how do you make a button seem as if it has been pressed. Like every 10 seconds the program presses the "f" button. How do you do that?
Three answers:
Bambang S
2006-05-28 09:51:38 UTC
Write an OnClick event for your button, and put whatever you want to run when the button is pressed. Then use a Timer component, set the Interval property to 10,000 (it's in milisecond) and write an OnTimer event where you call the button's OnClick procedure from it.
anonymous
2006-05-28 16:57:11 UTC
In VB .NET, you use a timer control, this is located on the standard toolbar that lies to the left of the screen.



Then I think you would create this procedure:



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

'this code will call the command button procedure

button1_click(sender, e)

End Sub



Like people said up above, you must set the interval of the timer and call the start method of the instance of the timer object that you create. So something like this:



timer1.start



I think you put that code into the timer_tick procedure. This is how it is done with VB .NET I think people up above are explaining it how it would be accomplished with Visual Basic 6.



-----------------------

edited

-----------------------



I just re-read your question and I think you may have wanted to press the "f" key on the keyboard.



If that is the case, you use this procedure.



Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress



End Sub



So put the form1_KeyPress(sender,e) in the timer1 object.



I am not for sure on how to disguish which key has been pressed at the moment, but invoking that procedure will do the same thing as if you pressed a key on the keyboard.
anonymous
2006-05-28 16:52:37 UTC
Call the event (function or method) you've associated with the onclick action of your button. This is a so called "software mouse".


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...