Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

What is the Best Way to Send Keys to Webbrowser?

$
0
0
I'm currently trying to get my vb.net program to send simulate text entry to fill out forms in the webbrowser. I would normally just set the value of the webbrowser elements, but unfortunately the fields I'm trying to fill aren't in html, they're in a web-based Java Applet. Basically I have designed a robot to set focus to the webbrowser, and tab through the text fields entering data into each field. The data is numerical.

I have tried three methods to do this:

First I used SendKeys.Send(string) to send the values, but for some reason it consistently sends too many characters. For example instead of sending 83.1 it'll type 888833.1111. So obviously that's not good.

Then I did a little research and found that this is an occasional problem with sendkeys, so I tried implementing some code I found for this function called InputSimulator. It works well when I execute InputSimulator.SimulateKeyPress(key), but when I try sending strings via InputSimulator.SimulateTextEntry(string) it doesn't send anything at all.

Finally I tried some code that was given to me by a member of this forum.

Code:

For Each c In string
            If Not Char.IsNumber(c) AndAlso Char.ToUpper(c) = c Then keybd_event(VK_LSHIFT, 0, 0, 0)
            keybd_event(VkKeyScan(c), 0, 0, 0)
            keybd_event(VkKeyScan(c), 0, 2, 0)
            If Not Char.IsNumber(c) AndAlso Char.ToUpper(c) = c Then keybd_event(VK_LSHIFT, 0, 2, 0)
        Next

Now this function types the numbers very consistently which is exactly what I'm looking for. However it doesn't seem to include the decimal, so a string 83.1 will get typed 831.

So does anybody have any suggestion on what's the best way to approach this? I'm so close with this last method, I just need to include the punctuation it seems. Or is there perhaps some other, robust way to send keystrokes.

Thanks,
Michael

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>