I think this is an unusual question but here goes.

There is a winform app that has a window with controls on it that can only be operated via a keyboard. The design of how this works is really bad. I'm wondering if I can write a utility app that can identify this main app when it is running and be able to click on that other app with my mouse and have my app send the necessary keyboard commands to make it work?

I know each app has a unique ID and can be identified but I don't know if I have the ability to 'hook' into it with mouse commands and then stuff the keyboard buffer with keystrokes so the app thinks its getting its normal keys.

I'd like to be pointed in the direction to do further research on if this is possible at all.

Thanks...

The design of how this works is really bad.

It kind of depends on what controls and how the controls can only be operated by the keyboard. But I'll take your word for it. :)

I don't know if I have the ability to 'hook' into it with mouse commands and then stuff the keyboard buffer with keystrokes so the app thinks its getting its normal keys.

Yes, you can do this. It involves some non-trivial P/Invoke stuff to dip into the Win32 API so that you can find the appropriate process and manage focus to send messages. The idea is conceptually similar to a key logger, so I'd start there for research.

What operating system? Is this an in-house program or a publically available program? If publically available, what is it called? If in-house, please post a screen shot. The following may be of use:

SendInput function

keybd_event function
Note: This function has been superseded. It is recommended to use SendInput instead.

mouse_event function
Note: This function has been superseded. It is recommended to use SendInput instead.

SetFocus function

GetWindowText function

GetClassName function

EnumWindows function

EnumChildWindows function

Process Class

PInvoke

This is not an exhaustive list of the functions that you may need, but some to get you started. Researching the above should lead you to any other ones you may need.

Edited 1 Year Ago by cgeier

The OS is Win7.

The app is Microsofts Flight Simulator X. There is a flight panel that has buttons on it and only operates using these buttons. I'd like to be able to write a small app that would allow me to mouse over that panel, over various buttons and when I mouse click, have the panel react like I actually pressed the Enter key on that button.

Are you using a touchscreen or an actual mouse? Are you sure that the "buttons" you are trying to operate are actually clickable or are they images (with no clickable components)?

Have you tried searching for: flight simulator x panels

to find a panel that may work as you desire?

Here is a product that claims to allow you to create/edit panels:
FS Panel Studio

Edited 1 Year Ago by cgeier

The screen is all graphics, so the buttons are drawn to look like buttons but the whole panel is graphics. The 'buttons' may not be clickable.

From what I recall in using the program, not all of the items one may perceive as buttons, knobs, switches, etc are clickable, but MS does allow one to create keyboard shortcuts for some items. I haven't created any panels, but I believe that you may be able to achieve what you want by creating your own panel (or modifying an existing one). See my previous post.

Well, I'm starting out slowly.

I'm starting with this code to just find the target app. I'm testing it using notepad.

In the code below I'm looping through thenotepad processes and when I find it or find one, I grab the handle.

My ShowWindow() errors. I'd like to control (at this starting out point anyway) showing, hiding the notepad window, bringing it to the front, etc.

I need some help with the ShowWindow line.

Thanks...

            System.Diagnostics.Process[] ieProcs = Process.GetProcessesByName("NOTEPAD");
            if (ieProcs.Length > 0)
            {
                foreach (System.Diagnostics.Process p in ieProcs)
                {
                    this.Text = p.ProcessName;
                    IntPtr i = p.MainWindowHandle;
                    // 0 hide
                    // 1 show
                    ShowWindow(i, 1); // syntax err here
                }
            }

Edited 1 Year Ago by rfresh

This article has been dead for over six months. Start a new discussion instead.