cookietr How do I cheat?
Reputation: 0
Joined: 21 Nov 2009 Posts: 1
|
Posted: Sat Nov 21, 2009 7:46 pm Post subject: [C#] Simulating a keypress (without release)? |
|
|
Hi, I need to interact with an external application running, and send specific keypresses & releases. I've tried to use the SendKeys class, but it does only half of the job, as the keypress is being sent with an immediate keyrelease to the external applications.
I need to be able to simulate a "key hold down" for the external app. I'm now trying to use the SendMessage thing, but for now it won't work at all and I don't even get errors.
Here's my code:
Code: | //headers
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
|
The actual attempt to press a button:
Code: | IntPtr windowHandle = GetForegroundWindow();
SendMessage(windowHandle, WM_KEYDOWN, (IntPtr)((int)VK.VK_1), (IntPtr)0x20001);
|
Please advise |
|