|
You last visited: Today at 22:43
Advertisement
How to send keystrokes to a game
Discussion on How to send keystrokes to a game within the C/C++ forum part of the Coders Den category.
01/09/2012, 00:55
|
#1
|
elite*gold: 20
Join Date: May 2007
Posts: 1,166
Received Thanks: 82
|
How to send keystrokes to a game
Dear reader,
I am recently starting to learn C++.
I have the following problem:
I build this GUI program which should repeat my shouts
by a simple method.
Send a "space", then "up key", then "enter key" command.
Only this is, that it will not respons if the window is not focussed.
I want to be able to do these things even though when the window
is minimized for example. Could anyone tell me how to do it, or write
(link) to a tutorial so I can learn how to do it?
I think I have to hook to Final Fantasy XIV or something? but I have
no experience with hooks and that kind of stuff
Best regards
|
|
|
01/09/2012, 07:54
|
#2
|
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
|
Send/PostMessage.
|
|
|
01/09/2012, 15:29
|
#3
|
elite*gold: 20
Join Date: May 2007
Posts: 1,166
Received Thanks: 82
|
Hey MoepMeep, thanks for your reply!
Yes I tried Send/Post message but those do nothing for me.
Nothing happens at all.
My current code:
Quote:
// bring the window to the front
HWND GameWindow = FindWindow(0, L"Untitled- Notepad");
SetForegroundWindow(GameWindow);
// execute the loop
for( int i = 0; i < amount; i++ ){
// not the last loop so add a pause at the end
if( i < (amount-1))
{
PostMessage(GameWindow, WM_KEYDOWN, 'G', 0);
PostMessage(GameWindow, WM_KEYUP, 'G', 0);
Sleep(2000);
}
// last loop so dont add a pause at the end
else
{
PostMessage(GameWindow, WM_KEYDOWN, 'G', 0);
PostMessage(GameWindow, WM_KEYUP, 'G', 0);
}
}
|
|
|
|
01/09/2012, 15:32
|
#4
|
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
|
use GetLastError();
|
|
|
01/09/2012, 15:40
|
#5
|
elite*gold: 20
Join Date: May 2007
Posts: 1,166
Received Thanks: 82
|
Thanks I will give it a try right away
|
|
|
01/09/2012, 15:45
|
#6
|
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
|
the game most likely will ignore all keystrokes send to it while minimized, or doesnt even use the windows message pump to get keystrokes.
if it doesnt use the message pump for keystrokes you have to hook the method its using to check for keystates (will most likely be DirectInput) and hook it.
Tut:  (German though, but full code sample for a directinput hook.)
if it doesnt react to keystrokes sent to it while minimized you have to reverse and find out how it checks whether its minimized/maximized and accepts keystrokes.
both are a lot of work - have fun.
edit:
btw. instead of saying "thanks" in your posts to moepmoep you can press that little "*THANKS" button right down at the post to increase our Thanks Counter and to maximize our E-*****-Size.
Thanks in advance
|
|
|
01/09/2012, 15:48
|
#7
|
elite*gold: 20
Join Date: May 2007
Posts: 1,166
Received Thanks: 82
|
yeah thats what I was thinking about lol. Hooking, but I have totally no knowledge on how to do that or how that works haha.
I know that someone made a bot called OttoBot which does that though, he sends keys and everything to the game minimized or not, it does not matter lol. Thats what I wanted to learn, how to send keys even if something is minimized haha.
|
|
|
01/09/2012, 15:53
|
#8
|
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
|
editied smth in my post look up.
|
|
|
01/09/2012, 16:30
|
#9
|
elite*gold: 20
Join Date: May 2007
Posts: 1,166
Received Thanks: 82
|
awesome thanks Dr. Coxxy!!!
and your E-*****-Size is going to expend :P:P
|
|
|
01/10/2012, 20:41
|
#10
|
elite*gold: 20
Join Date: May 2007
Posts: 1,166
Received Thanks: 82
|
Is there any ENGLISH tutorial on how to do hooking and so on? cause my german is not good enough to understand the link you gave me  its awesome but, my german is not good enough lol =)
|
|
|
01/10/2012, 20:52
|
#11
|
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
|
gamedeception ;o
|
|
|
01/13/2012, 22:47
|
#12
|
elite*gold: 0
Join Date: Jul 2007
Posts: 84
Received Thanks: 8
|
From my WoW Anti AFK. Works if it's in the background, too.
Code:
HWND hwnd = FindWindow(NULL, "World of Warcraft");
SendMessage(hwnd, WM_KEYDOWN, VK_LSHIFT, NULL); // push key
Sleep(10); // hold key. not always works without this.
SendMessage(hwnd, WM_KEYUP, VK_LSHIFT, NULL); // release key
VK_LSHIFT is left shift. For a list look here:
|
|
|
01/13/2012, 23:47
|
#13
|
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
|
Quote:
Originally Posted by IceTray
From my WoW Anti AFK. Works if it's in the background, too.
Code:
HWND hwnd = FindWindow(NULL, "World of Warcraft");
SendMessage(hwnd, WM_KEYDOWN, VK_LSHIFT, NULL); // push key
Sleep(10); // hold key. not always works without this.
SendMessage(hwnd, WM_KEYUP, VK_LSHIFT, NULL); // release key
VK_LSHIFT is left shift. For a list look here: 
|
we/he already stated that sendmessage doesnt work 4 his game.
Quote:
Yes I tried Send/Post message but those do nothing for me.
Nothing happens at all.
|
|
|
|
01/14/2012, 01:24
|
#14
|
elite*gold: 0
Join Date: Jul 2007
Posts: 84
Received Thanks: 8
|
Quote:
Originally Posted by Dr. Coxxy
we/he already stated that sendmessage doesnt work 4 his game.
|
Maybe because there is no break between push key and release key. That most didn't work when I try it. But with a little break it works fine.
|
|
|
 |
Similar Threads
|
Simulating Keystrokes
11/18/2011 - General Gaming Releases - 6 Replies
Hi folks,
usually I am not releasing my stuff. But here is a small hint for "do it yourself" people, how to simulate keystrokes for Warhammer Online.
The usual way to do that via Postmessage or kbdevent does NOT work here, because Warhammer is a DirectInput game.
It cost me some hours to figure out a proper but easy way how to do it:
INPUT input;
|
Game Starting *Don't Send*
08/25/2011 - Dekaron - 5 Replies
When I start dekaron, it says Game Starting *Don't Send*, i tried reinstalling so many time, what should I do?
|
can someone send me game.exe *German*
11/30/2010 - Shaiya Hacks, Bots, Cheats & Exploits - 1 Replies
hi can some1 pls help me i accidentally deleted the game.exe of German Shaiya pls send 1 the original... [email protected] tnx alot
|
can any body send me the latest version of the game client?
11/16/2008 - Conquer Online 2 - 0 Replies
i tried downloading the latest version of the client but i can't download it..
can anybody send me the latest game client in my yahoo email account? is it possible? [email protected].. thanks
|
How can i send keystrokes to an application in background
04/09/2008 - Archlord - 3 Replies
i need something like a macro that can send keystrokes to an application in background and loop the sending in delay of 2 minutes or something... Any1 have an idea how can i do this or where can i download such program?
|
All times are GMT +1. The time now is 22:44.
|
|