[how To ] creat key presser by C#

08/02/2011 16:44 ahmed4ever2u#1
as the title said
i wanna know how to do small things like key presser

( no one | no one | no one | tell me any shit out side my topic if you wanna help me So do it if you don't just ignor the topic !! )

edit: can any one fast programing akey presser and share its source :D
08/02/2011 16:46 Kraizy​#2
SendKeys.Send?
08/02/2011 16:51 ahmed4ever2u#3
:D can you explain more?
i'm just tring to learn something
little words won't be enough
08/02/2011 17:30 kevin_owner#4
Actually it gives you enough info
[Only registered and activated users can see links. Click Here To Register...]
that's the first hit on google. I've never really worked with C# only a few small programs and even I can see at this page what it does you'll need to give a string as parameter and it'll send to the focused window so if you got your browser selected it'll send that key to the browser if you got another window selected it'll send it to that window.

so with:
Code:
		SendKeys.Send("{ENTER}");
you'll send a enter.

you can't use it in the background to it has limitations.
08/03/2011 13:44 XchangliiX#5
A much better method
Quote:
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

const uint WM_KEYDOWN = 0x0100;

public static void PostMsg()
{
Process[] processes = Process.GetProcessesByName(pName);
foreach (Process p in processes)
{
PostMessage(p.MainWindowHandle, WM_KEYDOWN, (int)Keys.Y, 0); //wParam is your key
}

For x64

[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

That means

PostMessage(p.MainWindowHandle, (uint)WM_KEYDOWN, (int)Keys.Y, IntPtr.Zero);