Skip to content

SendKeys for WPF?

June 15, 2007

Perhaps this will be useful to somebody… (mail thread, read bottom-to-top)

From: Answerer

You should consider intercepting the input at a common parent, and then invoking methods/commands on the separate controls.  For example, you can change selection of the list boxes programmatically.

From: Asker

I’ll look at KeyDown.  Is it still spoofing if the app is sending keys to itself?   In my scenario if the user presses the Up/Down keys I want to navigate through a vertical listbox or if they are using the Right/Left keys I want to navigate through a horizontal listbox.   Since you can’t have focus on both listboxes at once I thought by capturing the Page’s KeyUp I might be able to broker control for both listboxes.

From: Answerer

Not generally.  You are describing input spoofing, and we work hard to prevent it.

1) PInvoke to SendInput – this is the official way to simulate input.  It pushes the input through all of the expected code paths, and is indistinguishable from real input.

2) Raise the KeyDown event on the element you care about – there are bits of state that you cannot pass around with this method.

From: Asker
Is there a way to send keys to a WPF control like a listbox?  So let’s say I’m handling the KeyUp event for a Page or Window, can I pass that keystroke over to a specific control?

From → WPF

2 Comments
  1. Madushan permalink

    Never mind — found a cool solution at codeplex for this

    http://inputsimulator.codeplex.com/

  2. Madushan permalink

    I don’t know whether this is active site (last update 2007)

    But here’s my problem.

    I want to make a client software that can control media applications. How can I sent media keys to any running media apps ? I’d prefer a WPF way as my client end will have a simple UI.

    If not, please let me know of a P/Invoke based way.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: