Hello everyone.
I have what I believe to be a simple question, yet I can not find anything that is helpful to me.
Basically I have an application, that I want to use to control external applications. My program will run either embedded within another program or minimized to the system tray. So SendKeys is out because it only works if the controlled application has focus, which it will not.
So my conclusion is the windows API. I have never used the windows API, and from my experience the past few days I am not sure I want to!
So I am using user32.dll like this (these are not written in stone and are used by looking at other examples):
FindWindow() works perfectly. I can get the handle of the window. And the sendmessage function works as well with the example I pulled it from which calls the close command of the window like this:
Now this is all fine and dandy, but the question becomes, how do I send the keypress "A" or "B" or "Ctrl+D" to some window?
I read that the command "WM_KEYDOWN = 0x0100" should be used, but what is the argument? Is it the character code in hex? Is it some random thing? I have not seen any working code or full samples of code anywhere. If someone could link me to some fully working code to do this, or just post a sample I would be highly appreciative.
Thankyou in advance...
I have what I believe to be a simple question, yet I can not find anything that is helpful to me.
Basically I have an application, that I want to use to control external applications. My program will run either embedded within another program or minimized to the system tray. So SendKeys is out because it only works if the controlled application has focus, which it will not.
So my conclusion is the windows API. I have never used the windows API, and from my experience the past few days I am not sure I want to!
So I am using user32.dll like this (these are not written in stone and are used by looking at other examples):
Code:
[DllImport("user32.dll")] public static extern int FindWindow( string lpClassName, // class name string lpWindowName // window name ); [DllImport("user32.dll")] public static extern int SendMessage( int hWnd, // handle to destination window uint Msg, // message int wParam, // first message parameter int lParam // second message parameter );
Code:
const int WM_SYSCOMMAND = 0x018; const int SC_CLOSE = 0x053; int WindowToFind = FindWindow(null,"Untitled - Notepad"); int result = SendMessage(WindowToFind, WM_SYSCOMMAND, SC_CLOSE, 0);
I read that the command "WM_KEYDOWN = 0x0100" should be used, but what is the argument? Is it the character code in hex? Is it some random thing? I have not seen any working code or full samples of code anywhere. If someone could link me to some fully working code to do this, or just post a sample I would be highly appreciative.
Thankyou in advance...
Comment