Echilon
Echilon

Reputation: 10264

C#: Send input from inactive window

I'm trying to send input from a WPF Window which doesn't have focus. The idea is to create a virtual numpad, whereby pressing Alt+M for example sends Alt+Numpad0. I've got Michael Kennedy's global hooks working, but I can't find a way to:

1) Send keys from an inactive window

2) Swallow these keys so they're not processed by the application which has focus.

The second may become a non-issue once I get the first fixed.

System.Windows.Forms.SendKeys didn't work for this because I need to simulate the Alt+xxx combinations to generate the right characters. I also tried System.Windows.Input.InputManager.Process() from an MSDN post, but if the Window sending the input doesn't have focus, the InputSource I was using (second parameter - Keyboard.PrimaryDevice.ActiveSource) is null.

Any ideas?

Why a virtual numpad? Without a numpad on my laptop (Studio 1555) I can't enter symbols without opening charmap - thanks Dell!

Upvotes: 2

Views: 3193

Answers (1)

Andreas Zita
Andreas Zita

Reputation: 7570

Check out Windows Input Simulator for simulating keystrokes. Or use AutoHotkey to grab any keystroke and resend it as some other keystroke.

Upvotes: 1

Related Questions