0

I've been trying to figure this out using

   '[DllImport("user32.dll", EntryPoint = "FindWindow")]
    private static extern IntPtr FindWindow(string lp1, string lp2);

    [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool SetForegroundWindow(IntPtr hWnd);

    private void button1_Click(object sender, EventArgs e)
    {
        IntPtr handle = FindWindow(null, "Notepad");
        if (!handle.Equals(IntPtr.Zero))
        {
            if (SetForegroundWindow(handle))
            {
                SendKeys.Send("(KEY)");


            }
        }
    }
}

} `

But I basically want to reverse that. Ex: When I presss insert in notepad, it will show my form.

Marcin
  • 1
  • Something like this? https://social.msdn.microsoft.com/Forums/vstudio/en-US/c061954b-19bf-463b-a57d-b09c98a3fe7d/assign-global-hotkey-to-a-system-tray-application-in-c?forum=csharpgeneral – L.B Nov 30 '18 at 22:06
  • If NotePad has the focus, your code won't run, unless you are using keyboard hooks. – LarsTech Nov 30 '18 at 22:07
  • Okay, well instead of doing the global hooks, is it possible to make that when the application is not selected, and a button is pressed on any application, the form would show? – Marcin Nov 30 '18 at 22:15
  • Re-read my comment again. – LarsTech Nov 30 '18 at 22:17
  • you need to be more specific about your scenario - e.g. is the other app under your control, or what is that you're trying to do exactly. On manipulating other app, here is [one post](https://stackoverflow.com/questions/16196272/get-all-controls-by-findwindowex/16198186#16198186) of mine that might be related. It depends on whether it's keyboard or mouse activated, whether it's a general solution or for some specific case. Global hooks are one way to go but there's UI automation in some case and so on. – NSGaga-mostly-inactive Nov 30 '18 at 22:27

0 Answers0