This tutorial will show you how to send keys to an inactive window by using Windows Messages. The code sample is in C# but can easily be translated into C++ and VB.
Part 1 – Grabbing the Messages!
Part 2 – Writing the Application!
Source Code!
Enjoy.
thanks, these are very informative.
but how do i get in if notepad was inside a panel?
thanks
I still dont understand why do you have SendKeys and SendCharacter they do the same? Also the tutorials seems very complicated I dont understand everything. Can you upload a more detailed tutorial on YouTube that would be way better. Does this work the same when I use it for a game btw?
Hey could you help me a little with sendkeys tutorial?
I want to make it in vb.net
Tried,no errors but it wont work,i dont know what is the problem.
maybe this conversion “Win32.VkKeyScan(CChar(CStr(pKey)))”
This message is for Patrickssj6 , that guy who made the sendkeys tutorial.
I really need help
please contact me via email “matrix_boy84@yahoo.com” or via skype MALWARE442
Hi Patrick,
How do you simulate arrow keys? I have tried two methods different PostMessage,
public static extern bool PostMessage(int hWnd, uint Msg, uint wParam, uint lParam);
public static extern bool PostMessage(int hWnd, uint Msg, Keys akey, uint lParam);
where both works for a to z and other keys, but only the navigation keys do not work.
When I run the line below,
Win32.PostMessage(windowHandle, Win32.WM_KEYDOWN, Keys.Up, 0x01480001);
I get wParam:00000037 from my raw input, but when I press Up arrow on my keyboard, Spy++ registers wParam:00000026. Do you have any idea why this is happening? Or the most important question, do you have any idea how to send a keystroke representing Up arrow?
Have you tried using SendInput instead?
i can send to you my source to look a little and maybe you could fix the problem,i really need that fix very soon …
Can some one translate this to vb.net!
I found it for those who have the same problem here the solution :
// Win32.PostMessage(eClassHandle, Win32.WM_KEYDOWN, Win32.VkKeyScan(pChar), 0x00140001);
Win32.PostMessage(eClassHandle, Win32.WM_CHAR, 0x00000000 + (Int32)pChar, 0x00140001);
Win32.PostMessage(eClassHandle, Win32.WM_KEYUP, Win32.VkKeyScan(pChar), 0xC0140001);
Hi , I like this very much works perfect exept one thing. Some of my characters are sended wrong like
/ is 7 or T is t some other weird characters also how can I fix this .
Thank you .
I had the same problem at first…cannot remember how I solved it. In the additional parameters you can define the SHIFT state I believe.
can you check on your codes what is changed so I can try that .
thanks for reply
public void sendChar(char pChar)
{
Win32.PostMessage(eClassHandle, Win32.WM_KEYDOWN, Win32.VkKeyScan(pChar), 0x00140001);
Win32.PostMessage(eClassHandle, Win32.WM_CHAR, 0x00000000 + (Int32)pChar, 0x00140001);
Win32.PostMessage(eClassHandle, Win32.WM_KEYUP, Win32.VkKeyScan(pChar), 0xC0140001);
}
This is what I use, maybe it works for you?
thanks but this is the exact original code from the sample source that I use. π
I can get this to more for some programs but I can’t get it to work for games like halo or nexus. How could you send chars to these games?
Try to use SendInput instead.
I tried but it only sends input to the active window.
I did find it might be possible using get processIDofthread and attachThreadInput then setfocus then you send the input and last you detach your thread.
I’ll give it a try during my free and see how it works.
http://stackoverflow.com/questions/6165428/sendinput-to-minimized-window
I can’t test the above method because GetProcessIdOfThread only works on vista and higher. I’ll check the guiltySpark source to see how that works.
Yeah I said SendInput because I saw it somewhere in the GuiltySpark code.
Yah right! Key loggers, game botters… every evil you might think off! haha. THis is cool, anyway.
Thanks a lot! This is exactly what I need to create two applications and keep the focus in one application while the other application receives keyboard events!
Hi,
Thanks for posting this tutorial, very helpful. I have one question:
You code works perfectly when target window is Notepad however when target window is a Google Doc running in IE 7 no text gets sent β any thoughts?
Thanks.
Have you tried Spy++ and hover over Google Doc? It might not be running inside IE instead running in Flash or Java.
nc tut π
Maybe know how unfreeze Ex. L2.exe wheen minimaze game action lag.
anyone, can traslate the codes in vb please?
I like the tutorial. Can you provide some direction for the following? I want to send CTRL-SHIFT-R to a window every 60 seconds. Do you have an example of the “send key” code that repeats every n seconds?
Thanks,
R. C.
Just add a timer or use a loop with a timeout. Not very hard π
Hi,
Thanks for posting this tutorial, very helpful. I have one question:
You code works perfectly when target window is Notepad however when target window is a Google Doc running in IE 7 no text gets sent – any thoughts?
Thanks.
Hey awesome tutorial man.. i learned alot.
But now i was wondering .. how do you write a program that catches all keyboard input while inactive.. kinda like a keylogger but im not making that i want to make a media player that reacts on differen keys while inactive
I can write a tutorial on that as well. You have to use GetAsyncKeyState and check in a loop if your hotkeys are being pressed. Alternatively you can install a keyboard hook.
Yeah, I’d like to see a tutorial for this as well. I have an AI bot that needs to receive the human player’s input while inactive and the game is active.
Hey cool tut, I got it working for this older game I play. I was just wondering if I can make it so when I push the send button it sends the message and also pushes enter so it posts it in-game. I leave my console open and minimize the game and send it, it goes into the console but i have to re-open the game and push enter to send. Thanks.
I used this for Minecraft and I can easily send “Enter”. If the game requires for some reason focus then you can just make it go into focus by using the SetForegroundWindow() / SetActiveWindow() (can’t remember which one) API before sending Enter.
Hey thanks for the response, I hate to bother you with it but can you please show me how you got enter to work? My Spy++ in-game shows enter with the wParam “0000000D” so that’s what Ive been trying but its not sending anything. I’m a real amateur programmer so I hate asking because it’s something dumb on my part, but I’m lost here.
http://pastebin.com/aji3tLtJ
Try that code. Modify it so it works for you and just call it with “sendKey(Keys.Enter)”.
Thanks man works like a charm, I went with
” if (VM.windowExists())
{ VM.sendText(txtBoxSend.Text);
VM.sendKey(Keys.Enter);
}
else if (VM.windowExists())
VM.sendKey(Keys.Enter);
else
messagebox”
It sends it flawlessly. :). This is cool as hell, thanks for your help.
Edit: minus the first “VM.sendKey(Keys.Enter);” after it sends the textbox, thats not really there, thats how i first tried it and its why i added an else if.
Hi,
I’ve try to use this “wonderfull” tutorial with AERIA GAME Shaiya, but does not work. Using Spy++ all “Properties” windows data are “grey” and Keyboard can go into chat but not into the game.
Can you help me to understand why and how to solve it?
thanks much
Tesitos
I don’t know what it means if the Windows Data are gray but your game is probably a DirectX game which uses DirectInput for keyboard detection so this method probably won’t work. You have to dig (read reverse) deeper.
hey, this is a great tut, but i was wondering if you could make a tut for code injection. like lets say i wanted to make a program that injects a .dll into halo. or just modify halo’s memory with hotkeys for unlimited ammo and such. I know how to use trainer makers but i want to learn how to do things myself. Your tut’s are really helpful.
I won’t make a tutorial on how to inject a DLL but I can certainly write a tutorial on how to write a DLL Trainer.
Dev Mode has simply been removed from Halo PC. There is no security, the code simply does not exist anymore.
So this is kind of like keybd_event and sendinput api functions except this works on inactive windows. I wonder if this would work for halo. Again good tutorial.
btw I’ve been wondering if its possible to reenable dev for halo, not ce. I used findpattern to find an address which I think is for devmode, though when I try it, it freezes the game until i change it back. Maybe some security, if so is there a way around this? I know that addresses like deathless, infinite ammo, bottemless still exist in it, so maybe dev all together does too.