Question

Hi ive developed a application that works with my site by using

SendKeys.send("{ENTER}") to submit info on one of my forms.

Is there a way to stop it from running outside the application?

For example im trying to run the program in the background and when im browsing my facebook or on google it randomly keeps hitting enter.

Any help is greatly appreciated thanks for your time.

No correct solution

OTHER TIPS

The short answer is to look at the windows available for a process and check the titles to see if it's the page you want.

If System.Diagnostics.Process.GetProcessesByName("firefox").MainWindowTitle = 'My Page Title'
    ...
End If

That said, there are much better ways to do this - If you're using firefox, look into GreaseMonkey, if in Chrome, look at TamperMonkey.

Both allow you to inject custom javascript into any page whose url matches a pattern you choose. In effect, you could write some Javascript to submit a form (say) 30 seconds after page load.

This would have the benefit of working if a different tab is selected as well as not requiring a whole application.

The SendKeys.Send method will indiscriminately send the key stroke to the active application. There is no way to use this API to target a specific application.

You could change your app to try and verify the active application is the one you want to send keys too. This is destined to be a flaky process though. No matter how good your verification is it's always possible that the active app is switched to another app after your verification completes.

If VerifyActiveAppIsTarget() Then
  SendKeys.Send("{Enter}")  ' Active app could change before this runs

I would persue a different solution for sending data between my apps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top