2

I'm currently using SendKeys.SendWait(text); in C# but SendKeys sending the key global and I have to activate my application and then send it. And another problem is when I type something in my keyboard (in another app) and the SendKeys function activates (in my app) mistakes happen.

So how can I send a message to my application regardless what application is active and what I type in my keyboard?

2
  • What is the purpose of this application, can you provide some relevant code you already have? Commented Jun 18, 2011 at 7:42
  • Well it a bot program - using webbrowser control. And i want to type message and send it. I cant do it with changing value of the input form... so i have to send keys to the application. About the code you want - there is noting to show. i just use the above function to send keys and that is it, but i want to change that function to match my requirements. Commented Jun 18, 2011 at 8:17

2 Answers 2

2

SendMessage() does what you want. You'll need to use it like:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

const UInt32 WM_CHAR = 0x0102;
const int VK_Q = 0x51; // taken from http://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx

SendMessage(handleToTheInputForm, WM_CHAR, VK_Q, 1);
Sign up to request clarification or add additional context in comments.

Comments

1

You will need to get a handle on the other application's window so that you can bring it to focus and reliably send your keystrokes to it,

Have a look at this tutorial

http://www.codeproject.com/KB/cs/SendKeys.aspx

1 Comment

Yes i do that now but im saying again mistakes happen. i don't want my application to be dependent on that what application is active...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.