Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Hooking a Console Application to Notepad
    text
    copied!<p>What i want to do is create a simple windows application that will hook itself onto NotePad and then simulate a keystroke. I have the process of opening up NotePad, bringing it to the foreground and then simulate the number 1 being pressed. However, if I click off of notepad, whatever is active becomes what is being typed in. </p> <p>How do I bind this application to notepad, so that I can click and type in whatever, and this application will still push commands into notepad? </p> <p><a href="http://inputsimulator.codeplex.com/" rel="nofollow">This is the DLL i'm using to simulate keypressing</a>: </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; using WindowsInput; namespace NotePadTesting { class Program { [DllImport("USER32.DLL", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); // Activate an application window. [DllImport("USER32.DLL")] public static extern bool SetForegroundWindow(IntPtr hWnd); static void Main(string[] args) { Process[] processes = Process.GetProcessesByName("notepad"); if (processes.Length == 0) { Process.Start("notepad.exe"); processes = Process.GetProcessesByName("notepad"); } if (processes.Length == 0) { throw new Exception("Could not find notepad huh...."); } IntPtr WindowHandle = processes[0].MainWindowHandle; SetForegroundWindow(WindowHandle); for (int i = 0; i &lt; 500; i++) { System.Threading.Thread.Sleep(100); InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_1); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload