C# about sending simulated keyboard events to another APP - c#

private void button3_Click(object sender, EventArgs e)
{
SetForegroundWindow(wndHandle);
SendKeys.SendWait("123");
}
I use WIN32 API ,use the Sendkey to achieve my target,but using the Sendkey has a disadvantage that "I have to SetForegroundWindow() before I use sendkey",it doesn't match my wish.
I want to click a button in the GUI which C# created, and then it will simulate the keyboard event to another app, and most important of all, I wish I don't have to set the window of app to be the ground window.
Does anyone have idea how to do it? I appreciate your help very much.
Does the target application must be currently active?

Related

How to put an exit icon that close the app in the main screen?

The title is the question right here, but to be more specific, i'll show the example. Exit icon as i want to do.
Execute the following lines of code in your icon's OnClickListener,
MainActivity.this.finish();
System.exit(0);
You can use the following code to terminate an application via a click event in Xamarin Forms.
For more details, you can refer to this thread.
private void Button_Clicked(object sender, EventArgs e)
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
}

How to send CTRL+S to MS Word?

I am working on a program that auto saves a Microsoft Office document after specific time (loop).
On a click of a button it will activate timer and after a given time delay it should send CTRL+S to Word and save the document.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
startTimer.Enabled = true;
stratTimer.Start();
}
private void startTimer_Tick(object sender, EventArgs e)
{
SendKeys.SendWait("^{s}");
MessageBox.Show("doc auto saved");
}
The problem is that SendKeys.Send("^{s}"); does not work.
How can I accomplish that?
SendKeys.SendWait sends keystrokes to the currently active window, so the keystrokes can be received by other window, like browser (if you are viewing this answer while the automation exe is running in the background). It is not a wise idea to send key strokes to arbitrary window.
This can partially explain why your code does not work in some cases. And it has other issues.
Just as MickyD's comment, don't use this "SendKeys" solution for automation nowadays. For auto save, VSTO is the right way to go.
See How to: Programmatically save documents.

What is the event which fires every time when i click outside for my wpf page?

i am developing windows application using wpf. I want to do some functionality when i click outside of my control created. for example, if i have Message-box open in my window, i want to do some function if i click outside of my Message-box window.
I tried,
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
.....
}
but its not working.. please any one tell me, what is the event fire when i click outside of my control?
you have two supposed solutions:
one of them is to get Mouse.X, Mouse.Y from System not from application, this article will help
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
second which is better is not using Dialog, but use PopUp window and this article will help
how to close a WPF Dialog Window when the user clicks outside it

how to auto focus an .Net winform application running in background

I have a weird problem, my .net win form application triggers a third party CRM application. When the customer is working with CRM application and clicks some button in my application, on first click the button does not trigger the event, only on the second click it responds.
The reason I suspect is that my application is not in focus.
I tried with the following code
private void XXXXX_MouseHover(object sender, EventArgs e)
{
this.BringToFront();
this.Focus();
}
But then its not working. I am new to .Net can any one point me how to fix this issue?
Any help is highly appreciated.
update: my toolstrip button.
btnbutton.Click += delegate(object sender, EventArgs e)
{
//some code to execute on button click.
};
Thanks
The .NET tool strip ignores clicks when the application doesn't have focus. This is just like how Words work. The idea here is that the user can click "anywhere" in the window without having to worry that he actually performs an action. Only when the window has focus will the click "count".
The post at http://blogs.msdn.com/b/rickbrew/archive/2006/01/09/511003.aspx describes how you can work around this. Basically, you inherit from ToolStrip and override the WndProc, and change the WM_MOUSEACTIVATE with the MA_ACTIVATEANDEAT result to the MA_ACTIVATE result.

Click to new window.xaml

im learning wpf for the first time,
i have made this far
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO: Add event handler implementation here.
}
lets say its my click button 'home' some how i have made a new window store.xaml at the same product.
how can i connect them ?
heres a sc
Your question seems a bit vague to me, if you simply want to display the store inside the same window you should not implement the content of the window directly but only use the window as a shell for your content, if your store is a window as well you should refactor it into a UserControl which then can be added to the window.
You can also use Pages, see the Navigation Overview for more info on that.

Categories