Windows lock mode while sendkeys or mouse control c# - c#

So I've got application that uses webbrowser and going through specified website.
At the end of the process it clicks on button and Download dialog box appear. Problem is: to download this file I have to either SendKeys or position properly mouse and simulate clicks.. When I have remote desktop open it works well, but when I disconnect SendKeys give error "Access denied" - I believe it's related to windows lock mode, and mouse is not moving at all..
Is there any possibility that I can make it work? I found that there is no other option to download that file than SendKeys or simulate mouse position and clicks.. I have to stick to webbrowser.

Why are you trying to visually click on the button, or link? just in DocumentCompleted event of the WebBrwoser invoke the click event:
public void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
wb.Document.GetElementById("someElementId").InvokeMember("click");
}
Of course in this example I have used GetElementById() however you may use any method or loops, ... to find the element you want.

Related

problem of opening a webPage in webBrowser c# control in place of IE control

For my project I used webBrowser control and when I launch an html site which has got an input(type) button with onclick javascript function which process ending on window.open target="_blank", it's internet explorer window that's is opening in place of a new page of webBrowser.
I program in c# code with winform technology and I used webBrowser System.Windows.Forms.
So which function could I used to open the page of this site in webBrowser window in place of IE window.
Thanks you for your help.
M.A.
Read about WebBrowser.Navigating event:
You can handle the Navigating event to cancel navigation if certain conditions have not been met, for example, when the user has not completely filled out a form. To cancel navigation, set the Cancel property of the WebBrowserNavigatingEventArgs object passed to the event handler to true. You can also use this object to retrieve the URL of the new document through the WebBrowserNavigatingEventArgs.Url property.
To open page in default browser, for example:
private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
Process.Start(e.Url.ToString());
}
Finally,
I used the package reference "SHDocVm" of "Microsoft Internet Controls" and I place a function handler NewWindow3 in the function "DocumentCompleted" of webBrowser and it's ok, a window.open() javascript function with target="_blank" opens a new page of webBrowser.
Truly yours.
M.A.

UWP Xbox One page navigation when using WebView

Usually when running a UWP app on Xbox the B button on the controller is handled automatically and will return you to the previous page.
I have a page which contains a WebView, when you use the directional buttons to place the focus box around that control, the B button no longer responds. You can use the A button to take control of the WebView and display the pointer and the B button then will return focus back as above but I cannot navigate back using the B button until you move the focus box to a different control. This also happens using AdControl since this uses WebView.
I have tried to capture KeyDown:
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
private void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
Debug.WriteLine(args.VirtualKey.ToString());
}
This responds with GamePadB, GamePadX etc but not when the focus box is around the WebView.
Is there anyway I can find out when the GamePad buttons (specifically B) are pressed when the focus box is around the WebView (or AdControl) and the control isn't engaged so I can manually invoke the backstack navigation?
Since this issue happens when using the XY focus mode for the app, if your OS version is 14393 or higher, one workaround for this issue is to use the mouse mode for this page which contains the webview by setting RequiresPointer="WhenFocused" as following:
<Page RequiresPointer="WhenFocused">
...
</Page>
And set another page to XY focus mode by using the following code in the app.xaml.cs:
this.RequiresPointerMode =
Windows.UI.Xaml.ApplicationRequiresPointerMode.WhenRequested;
For more information, please try to refer to the following article:
https://msdn.microsoft.com/en-us/windows/uwp/input-and-devices/designing-for-tv#mouse-mode

Making sure that a C# form has focus when it should

I am a fairly new to Visual C# but have coded in Delphi for a long time. I have created a form that has a simple panel that is hidden unless you type in a particular key on the keyboard (I do have "KeyPreview" set for true for the form and I am using the KeyDown event to handle determining if the correct key was pressed and to make the panel visible/invisible). Just beneath the panel is a webBrowser component.
What is happening is as follows:
When my form initially starts, I have code for the "Shown" event that makes sure the form has focus initially:
private void Form1_Shown(object sender, EventArgs e)
{
if (!Focused)
{
Focus();
}
}
When the form is focused at this point, my code for detecting the proper keystroke to get the panel to appear or disappear works fine.
Here is where things get strange and I'm not sure of what to do. There are two parts I am dealing with for what is wrong:
If I click on another form and then on the caption bar of my form again to get focus on my form and try a keystroke, the keystroke detection does not work. However, if I click on another form and then back on my form one more time, the keystroke detection for the form does work. What can I do to make sure that this works each time my from has focus again?
If I click on the web browser component within my own form, the KeyDown code for the form no longer gets enacted. Even if I click on the caption bar for the form, the KeyDown event does not work. What do I need to do to assure that, if a component within my form is clicked, my form will still respond for the KeyDown event?
Thanks in advance for any advice.
I can't say why your caption bar seems to be intercepting key events. It may be that various components on the form can have focus and thus capture keyboard events. I know the web browser control works this way. You may consider capturing keyboard events globally.
I saw something on Codeproject that shows how to do this. I hope this helps.
They use UserActivityHooks.
UserActivityHook actHook;
void MainFormLoad(object sender, System.EventArgs e)
{
actHook= new UserActivityHook(); // crate an instance
// hang on events
actHook.OnMouseActivity+=new MouseEventHandler(MouseMoved);
actHook.KeyDown+=new KeyEventHandler(MyKeyDown);
actHook.KeyPress+=new KeyPressEventHandler(MyKeyPress);
actHook.KeyUp+=new KeyEventHandler(MyKeyUp);
}
As for the webbrowser control, of course it is going to interecept keyboard events. Users often have to enter text in forms and developers often code javascript on webpages to specifically hook into keyboard events. So the webbrowser control must be able to capture those.

How to control WPF Controls using Kinect hand pointer?

I have been developing a desktop application in C# that uses Kinect to detect gestures.I want to obtain the user information from Google+ using google+ APIs.
The problem is,as I use Kinect hand pointer I can click only elements like kinect tile buttons provided by Kinect region.
I use embedded browser control for authenticating Google+.But for accessing Google+ using OAuth 2.0, I need the consent from the user .provided the user clicks the Allow access button which can't be done by Kinect hand pointer.
Is there any way to manipulate the mouse click programmatically or to access the browser using the Kinect hand pointer?
You can't mouseclick programically, but You can trigger the onclick event handler manually, like:
Button_Click(object sender, EventArgs e) {} // - the function that handles the onclick
You trigger it manually like this:
YourKinectFunction()
{
Button_Click(this, new EventArgs());
}
It will work just as if you clicked the button with mouse.
The Button_Click(object sender, EventArgs e) is the function which is executed when the event happens. If you trigger the event in your code, the handler will fire. The function doesn't 'know' who triggered the event (unless you specify it in sender parameter).

How to close Find window in a webbrowser control

I use a WebBrowser control and it's find functionality:
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.Select();
SendKeys.Send("^f");
}
Which works fine. Only problem that there is a case when user can make WebBrowser unvisible to perform some other tasks:
webBrowser1.Visible = false;
But Find window remains visible. Any suggestions?
Thank you.
To close, try this
webBrowser1.Select();
SendKeys.Send("^f");
SendKeys.Send("{ESCAPE}");
There is no easy/direct way to control the Find dialog. One way to close the Find dialog is by sending "ESCAPE" to the dialog when it has focus. If you send "^f" prior to sending "ESCAPE", that will force the find dialog to get focus.

Categories

Resources