c# - WPF Application stealing focus -
what want do:
i want wpf app type in keystrokes onto other application has text fields, example, notepad.
what problem is:
if press button simulates keystroke ('a', example), app steals focus , 'notepad' not focused/active anymore, button not know send keystroke,
what im requesting: how wpf app not steal focus of other app can type in keystroke when press app's buttons, here's code:
private void button_click(object sender, routedeventargs e) { inputsimulator.simulatetextentry("1"); }
'inputsimulator' comes library got online, makes simulating keystrokes easy.
**update, clarification, want surface pro keyboard, keyboard want do, if press on it's keyboard, app active stays focused , sp3 keyboard able enter keystroke, how do app?
you'll need p/invoke user32.dll
, use findwindow
handle application trying write to, use setforegroundwindow
. can send keystrokes window.
see article on msdn quick sample: https://msdn.microsoft.com/en-us/library/ms171548.aspx
you can find tons of examples searching google p/invoke , windows api.