WPF Application stealing focus - c#

What i want to do:
I want my WPF app to successfully type in keystrokes onto any other application that has text fields, for example, notepad.
What the problem is:
If i press any button that simulates a keystroke ('A', for example), my app steals focus and now that 'notepad' is not focused/active anymore, my button does not know where to send the keystroke,
What im requesting: How do i get my WPF app to not steal the focus of any other app so that i can successfully type in a keystroke when i press my app's buttons, here's my code:
private void button_Click(object sender, RoutedEventArgs e)
{
InputSimulator.SimulateTextEntry("1");
}
'InputSimulator' comes from a library that i got online, it makes simulating keystrokes easy.
**Update, for clarification, i want something like Surface Pro Keyboard, this keyboard does exactly what i want to do, if i press on it's keyboard, the app that is currently active stays focused and sp3 keyboard is able to enter a keystroke, how do i do this for MY app?

You'll need to p/invoke user32.dll, use FindWindow to get a handle for the application you are trying to write to, then use SetForegroundWindow. Then you can send keystrokes to that window.
See the article on MSDN for a quick sample: https://msdn.microsoft.com/en-us/library/ms171548.aspx
You can also find tons of examples by searching google for p/invoke and Windows API.

Related

How to open TabTip keyboard in a UWP app in desktop mode on button click

I am currently working in a UWP application. I have a situation where I need to open the taptip keyboard. The device needs to be in desktop mode and the keyboard should open on a button click. Is there any way I can achieve this functionality?
I know it works fine in tablet mode when a text box gets focus but I need to get it done in desktop mode and on a button click.
I know it can be done from a console application using System.Diagnostics.Process but I need a way around for uwp app.
The user can enable the tip to show when a text box gets focus in a desktop app by setting the "Show the touch keyboard when not in tablet mode and there's no keyboard attached". Apps should generally defer to the user's preferences on this rather than trying to override this themselves.
That said, you can show and hide the InputPane via the InputPane.TryShow and InputPane.TryHide methods.
You'll do essentially the same from a desktop app via the IInputPaneInterop and IInputPane2 interfaces. Launching tabtip.exe explicitly is limited and not generally recommended.

Winforms Rich Textbox allow scrolling when mouse over

I have simple chat application with Rich Textbox to display messages and Textbox to write them. I'd like to have same behaviour as facebook chat does, which is having focus on the Textbox but being able to use mouse wheel to scroll the one I'm hovering over. So as an example: I'm writting something in the Textbox but in the meantime I want to scroll the Rich Textbox upwards by using my mousewheel without loosing focus on the Textbox. Facebook chat has this exact behaviour.
Semi pseudo code I came up with:
private void richTextBox_MouseOver(object sender, EventArgs e)
{
MouseWheelScroll -> richTextBox scroll, msgTextBox don't scroll
}
I confirm Dmitriy Zapevalov's insight, Windows 10 Operative System
has a new interesting feature:
Scroll inactive windows when I hover over them
This is exactly the behaviour you desire, I can confirm it works both
in Winform and WPF application and in general it is the behaviour of
any window I see on my monitor. It is enabled by default, user can
disable it.
It is a little bit tricky to reproduce that on c# applications
running on windows Xp, Vista, 7 or Windows 8, you can find that issue solved in C++ here and in manuell answer here

how to simulate a mouse click on a background application in c#

I have a c# forms application and I want to simulate a mouse click of a button of background application without having to bring the program into focus. This is for an email spammer that I have been working on and I need to bring up a new email.
please help
thanks
Since you didn't have any code to share, I'll point you to Process.Start(), and here are a few examples of its implementation.

WPF: How to interact with inactive window?

Is it possible to interact with an inactive window from another window? I want to focus a textbox in a window without making it active, and then send keystrokes and mouse events to it. It seem to be possible to send messages to inactive windows using SendMessage but could it be possible to also focus a textbox in the window and send keystrokes to it, without ever making the window active?
Have a look at the same question worded a little different here
Quote #Kevin Montrose: "Windows assumes that the activate window is the one getting keyboard input. The proper way to fake keyboard input is with SendInput, and you'll notice that it sends messages to the active window only."
Did you have a look at UI Automation?
Getting a pattern and invoking it isn't that hard. The only thing I am not sure about is whether or not the window will get the focus.
Of course this will only work in the same process.

How can you detect when the user clicks on the notification icon in Windows Mobile (.NET CF 3.5)

Surfing the net, I came across this:
this code that shows how to display a notification at the bottom of the screen on a Windows Mobile device. My question is, is there a way to either specify which options are displayed beneath the notification (on the taskbar) or is there a way to detect when the user clicks on the notification itself, so that I can react to that programmatic ally.
With this specific API, the key is in the SHNOTIFICATIONDATA's hwndSink member. When the notification is clicked, the hwnd you pass in here will get the click message. For this it's simplest to pass in a MessageWindow's handle.
You might also look at the CeSetUserNotification API instead. It's actually quite a bit more robust in what it allows you to do and how you can get notifications back at the app.

Categories

Resources