I would like to create a bot that repeats the same action many times. Is there any way I can get more info about a click event. Lets say I click somewhere on the opened file explorer window. Can the program tell that I clicked on a specific area or button in that window? Can I make the program click or type on a specific(opened) window? Thanks
-
2You will probably need the Lib "user32.dll" Offtopic: You will probably get loads of hate on stackoverflow for trying to interact with different applications by faking user-input (which you are probably about to). – Luke Aug 03 '16 at 12:10
-
2This question lacks detail. I barely understand what you're trying to accomplish, and what I do understand currently makes this question seem too broad. Please try to create a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Visual Vincent Aug 03 '16 at 12:12
-
OP: If you want to click on or send key presses to a specific window you would first have to give it focus, then you can send [mouse clicks](http://stackoverflow.com/questions/10355286/programmatically-mouse-click-in-another-window) and [key presses](http://stackoverflow.com/questions/1220820/how-do-i-send-key-strokes-to-a-window-without-having-to-activate-it-using-window) to it. – Visual Vincent Aug 03 '16 at 12:22
-
What I want to do is make a program that learns where I want to click or type and then does it. I want to tell the program which windows to click or type, not just where to click on the screen in pixels. – John Mitromaras Aug 03 '16 at 12:23
-
You got it! Is there any function in vb to do this? I mean the click and type(not the focus) – John Mitromaras Aug 03 '16 at 12:26
-
1UI Automation can tell you lots of things about whatever gadget is located at a certain position. System.Windows.Automation namespace, take it for a test drive with the acccheckui.exe applet that you find back in the SDK's bin\x86\AccChecker subdirectory. – Hans Passant Aug 03 '16 at 12:40
-
1The first link I gave you is perfectly convertible to VB.NET using an [online converter](https://www.google.com/search?q=Convert+C%23+to+VB.NET), the other one requires you to do the [P/Invoke](https://msdn.microsoft.com/en-us/library/aa719104(v=vs.71).aspx) on your own. However perhaps UI Automation would be the better choice (I have never used it myself, but a lot of people talk about it)? -- Also, if you are to use the method(s) I gave you you are required to give a window focus first. A non-focused window doesn't handle mouse events. – Visual Vincent Aug 03 '16 at 21:42
1 Answers
Yes the program can tell when you click on a specific button. Whatever button it is that you clicked on will have its click event fired, if it exists. In order to manually tell the program to perform this action, you can implement the phrase..
btn.PerformClick()
where "btn" is the name of whatever button you are needing to click. Whenever this phrase is called, the btn_Click event handler will be fired just the same as if you yourself actually clicked the button.
To do the same thing with an actual window or form in your program is trickier because there are no built in methods you can call to trigger a windows form click event. But it is possible. The code that will define a window's event handler and trigger it will be..
Private Sub myWindow_Click() Handles MyBase.Click
'code you want to run on click event here
End Sub
myWindow_Click() 'where you want the click to be triggered
The above would be much simpler to simulate in a method call however.
And lastly to simulate the typing of text into a window, you could simply access the text property of the control you are wanting to alter, and then change that text property to the desired text. But judging from your question, you are wanting this to be done in a similar fashion to how a human would. This can also be accomplished with some work, using a timer interval that appends to the text of the control.
Lets say for example, you wanted "hello world" to be typed into a text box on screen as a person would. Add a timer control to your form and set its interval to 250 or however fast you want the word to be type and in a method..
Dim str as String = ""
Dim pos as Integer = 0
Public Sub humanType(word as String)
str = word
Timer1.enabled = true
End Sub
public Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
myTextBox.Text = myTextBox.Text + str[pos]
pos = pos + 1
If pos = str.length Then
Timer1.enabled = false
End If
End Sub
If you have never worked with timer intervals before, this tutorial has some good info on them for VB.Net. http://www.techrepublic.com/article/perform-actions-at-set-intervals-with-vbnets-timer-control/
Hope it helps!

- 838
- 7
- 17
-
Thank you very much. I will try it. The fact is that I dont like the vb documentation microsoft provides. It was always easier for my to discover new methods and technics in c, c++ and java documentations. Is there any better vb documentation that you use? – John Mitromaras Aug 04 '16 at 13:51
-
1I don't have any specific documentation I use for vb.net. Most of what I know about VB.net I learned from working as an intern using the program. When there's something new I don't understand, my main resource is pretty much Stack Overflow. Sometimes I use the Microsoft documentation, but I agree that it is kind of clunky and harder to digest. And other than that the only good site I'm familiar with is probably http://www.dotnetheaven.com – Luke Aug 04 '16 at 14:05