Skip to content

C# Keyboard Emulator, SendKeys, and user32.dll's SendMessage

Nick Nichols

Asked Jun 16, 2008, 11:25 PM EDT4 answers
Share
LinkedInX
Hello all,

I am trying to get my program to emulate keyboard strokes and send to other programs. Currently I am using:

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

and this is proving to be a headache. The way I implemented it, it works fine. I can send keystrokes to almost any program but Notepad (dont know why that wont work but I am guessing it is because there is the "Edit" subwindow inside it).

Anyways, people using the software cant figure out the title/class required. So I want to make a global keyboard presser basically. Something that programs with hotkeys can capture and also any program.

Is the basic SendKey function all that is needed? Will this trigger global hotkeys in other programs too? (I want this to happen, not prevent it!)

Is there a way to emulate an actual keyboard somehow? Maybe actually register a virtual keyboard?! I am just thowing out ideas here.

Thanks in advance!

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • +1

    Hi can you send me the code of SendMessage function. I  facing a challenge to give WM_KEYDOWN and WM_KEYUP event for F1 key on other application using SendMessage function.Please mail me on

    [email protected]

     

    Thanks

    +1
  • +1

    Hi can you send me the code of SendMessage function. I  facing a challenge to give WM_KEYDOWN and WM_KEYUP event for F1 key on other application using SendMessage function.Please mail me on

    [email protected]

     

    Thanks

    +1
  • 1 short reply
    • +1
      anyone?
      +1