I've built a C# application that takes another window handler and its process like in this post, I can send some command from my application to the window via PostMessage and this window reacts accordingly even when inactive.
The problem appears when I press the ALT and this window reacts on ALT + my_key_command like a hotkey. Please, explain how to prevent ALT keypress event handling in specific window from my application? Is this possible?
I want to blind only this window for ALT key. Here's example:
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
[STAThread]
static async Task Main()
{
await Task.Delay(TimeSpan.FromSeconds(5));
IntPtr window = GetForegroundWindow();
while (true)
{
int processId;
GetWindowThreadProcessId(window, out processId);
Process[] processes = Process.GetProcessesByName("iexplorer");
var process = findProcessById(processes, processId);
if (process != null)
{
PostMessage(process.MainWindowHandle, WM_KEYDOWN, 0x74, 0);
}
Thread.Sleep(5000);
}
}
static private Process findProcessById(Process[] processes, int id)
{
Process result = null;
foreach (Process proc in processes)
{
if (proc.Id == id)
result = proc;
}
return result;
}