Select the application window and PostMessage

202 views Asked by At

I created the application (KeySimulator) which is running on the Windows VM. This app is sending an 'ENTER' key to another application (DraftSight). DraftSight is running on the same VM. Maine purpose of my app is to select DraftSight and click 'ENTER' just in case if any messages are pop up on the DraftSight. Everything is working except my app sometimes is not recognizing the DS app. My app is running 24/7 and I have a Task to start my app on a log-in or if my app is not running. This is my code for that function:

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("USER32.DLL")] public static extern bool SetForegroundWindow(IntPtr hWnd);

IntPtr draftSightHandle = FindWindow("Qt5QWindowIcon", null);

SetForegroundWindow(draftSightHandle);

const UInt32 WM_KEYDOWN = 0x0100; PostMessage(draftSightHandle, WM_KEYDOWN, (int)Keys.Enter, 0);

0

There are 0 answers