4
Reply

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

Nick Nichols

Nick Nichols

Jun 17 2008 3:25 AM
29.3k
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!

Answers (4)