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).
Related
I have an application, ParentApp, which launches another application, ChildApp.
ParentApp displays a form while the ChildApp is running - just a kind of Childapp is currently running display with a Cancel button which kills ChildApp.
I want ParentApp to be unusable while ChildApp is running, so whenever someone clicks on ParentApp I want to bring the ChildApp to the foreground, which is fine.
So I've added this event handler to the ParentApp which responds to the Activated event of the form.
private void ParentAppForm_Activated(object sender, EventArgs e)
{
IntPtr childHwnd = _childApp.MainWindowHandle;
SetForegroundWindow(childHwnd );
}
(GotFocus didn't seem to work)
Unfortunately, if the user clicks the Cancel button on the ParentAppForm, the event handler for that button is never hit, because the Activated event fires first and sets the foreground window to another process.
Is there around this - to allow the button event to fire even though the application is not in the foreground?
As a quick workaround, you could check whether the mouse pointer in inside the area described by the Button.Bounds when the Form is activated.
You can translate the mouse pointer position to the Form.Bounds coordinates using PointToClient with the Cursor.Position coordinates.
Something like this:
private void ParentAppForm_Activated(object sender, EventArgs e)
{
if (this.button1.Bounds.Contains(this.PointToClient(Cursor.Position)))
ChildForm.Close(); //Or ChildApp.Kill()
else
ChildForm.BringToFront(); //Or SetForegroundWindow(ChildApp.Handle)
}
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.
In my WP8 app that controls Lego Mindstorms I have a Button with UIElement.Hold Event that triggers method runMotor() When I release the Button motor keeps on going but I would like it to stop. Method for stopping is stopMotor(), I've already tried to assign it to KeyUp Event but it doesn't work. Any solutions?
You can try to call stopMotor() in ManupulationCompleted event. Note that ManipulationCompleted event will get invoked after any gesture manipulation including Tap, Double Tap, Hold, and other gesture. Take that into account. If application scenario is still simple, checking if motor already running before calling stopMotor in ManipulationCompleted event handler maybe enough :
private void MyButton_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if(isMotorRunning) stopMotor();
}
I am writing a metro app where it makes sense for focus to jump to a single text box anytime the user starts typing. But I can't figure out how to implement this functionality locally, without modifying other user controls to detect keydown and forward focus to the text box.
In WinForms I would have used the form's "KeyPreview" property, which caused any key presses within the form's controls to fire form KeyDown/KeyPress/KeyUp events. I can't find any equivalent in metro.
I tried the naive solution of just forcing focus to the text box anytime it left, but that has obvious problems (e.g. buttons flicker instead of staying highlighted when you click and hold on them).
How can I ensure any keyboard typing goes to a specific text box?
The event needs to be placed on the current core window, which is the root element all controls are nested on.
Windows.UI.Xaml.Window.Current.CoreWindow.KeyDown += (sender, arg) => {
// invoked anytime a key is pressed down, independent of focus
}
Here you go ...
Responding to keyboard input (Metro style apps using C#/VB/C++ and XAML)
&&
Implementing keyboard accessibility (Metro style apps using C#/VB/C++ and XAML)
Pay special attention to routed events. There are examples there too.
Hope this helps.
In your xaml code u bind these to events to page::
Loaded="pageRoot_Loaded_1"
Unloaded="pageRoot_Unloaded_1"
and inside these methods u have to bind and unbind ur events for keydown or keypress
private void pageRoot_Loaded_1(object sender, RoutedEventArgs e)
{
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
}
private void pageRoot_Unloaded_1(object sender, RoutedEventArgs e)
{
Window.Current.CoreWindow.KeyDown -= CoreWindow_KeyDown;
}
I'm working on a Silverlight application and am trying to use 3D support in my app. I have enabled 3D support with this line:
<param name="enableGPUAcceleration" value="true" />
Also, the application is running on localhost:80 via IIS and this has permission for 3D usage set to Allow.
I have a DrawingSurface in a xaml page and attached its Draw event in which I simply clear the surface to red. The Draw does not fire. So I tried invalidating the DrawingSurface on MouseLeftButtonDown. Here's some code:
private void TestDrawing_Draw(object sender, System.Windows.Controls.DrawEventArgs e)
{
GraphicsDeviceManager.Current.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(255, 0, 0));
}
private void TestDrawing_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (GraphicsDeviceManager.Current.RenderMode == RenderMode.Hardware)
{
TestDrawing.Invalidate();
}
}
Checking in debugmode, I find that the MouseLeftButtonDown event does fire. The GraphicsDeviceManager.Current.RenderMode is set to RenderMode.Hardware and the Invalidate() method is executed. But, the Draw event still does not fire.
I've created a testproject which runs via a Developer server on a specific port (50814). Again, enableGPUAcceleration is set to true and permission has been set to Allow. This testproject does fire the Draw event.
So... my large application, running on an IIS server (localhost:80) with enableGPUAcceleration set to true and permission set to Allow does not fire the Draw event. A simple testproject running a Developer server on port 50814 with enableGPUAcceleration set to true and permission to Allow does fire the Draw event.
I've no idea how to enable 3D for my application. Do you guys have any suggestions?!
your code had the draw function working for only once, to make it work continuously, the draw event should be like this:
public void drawingsurface_draw(object sender, DrawEventArgs e)
{
//do some thing here
e.InvalidateSurface();
}