Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Aion
You last visited: Today at 19:46

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++]Sending Keydowns to Aion

Discussion on [C++]Sending Keydowns to Aion within the Aion forum part of the MMORPGs category.

Reply
 
Old   #1
 
jackicola's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 129
Received Thanks: 15
[C++]Sending Keydowns to Aion

Hey,
I'm trying to send Keydowns to Aion, I tried a few methods but nothing worked yet:
Code:
#include <windows.h>

int main()
{
	INPUT ip;
	Sleep(5000);

	ip.type = INPUT_KEYBOARD;
	ip.ki.wScan = 0; 
	ip.ki.time = 0;
	ip.ki.dwExtraInfo = 0;
	ip.ki.wVk = 0x41; 
	ip.ki.dwFlags = 0;
	SendInput(1, &ip, sizeof(INPUT));

	Sleep(1000);

	ip.ki.dwFlags = KEYEVENTF_KEYUP;
	SendInput(1, &ip, sizeof(INPUT));
	return 0;
}
Code:
#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{

	HWND hWnd = FindWindowA(NULL, "AION Client");
	if(!hWnd)
	{
		cout << "HWND Failed" << endl;
		getchar();
		getchar();
		exit(1);
	}


	Sleep(5000);

	PostMessage(hWnd, WM_LBUTTONDOWN, NULL, NULL);
	Sleep(100);
	PostMessage(hWnd, WM_LBUTTONUP, NULL, NULL);
}
Both doesn't work... Can someone help me please?

Greets!
jackicola is offline  
Old 11/14/2012, 22:01   #2
 
elite*gold: 0
Join Date: Feb 2006
Posts: 629
Received Thanks: 195
Foreground
SendInput can be used if the window is active. There are a few things worth noting about this implementation: A real-world use case will need to be more complex for extended/system keys. SendInput also sends the Low Level Keyboard Hook Flag: INJECTED (), which will give the target application an opportunity to detect the injected input. There are bots out there which use SendInput and have not caught a ban, but I don't personally feel comfortable doing this.

As for specifically why your example isn't working, some of the properties of ip might be overwritten when it is passed into SendInput, try setting wVk, type and ki after the first call to SendInput is made; every example I can find explicitly sets each property before each call.

Background
There are many restrictions to sending input to background/minimized windows (or active windows) with SendMessage/PostMessage.

First, when sending input with SendMessage or PostMessage the physical state of the device persists and receives priority in some cases. This means if you emulate input and the target application calls GetKeyState it will return a negative result unless the user happens to be pressing the key at the time the input is emulated.

Similarly, if you try to emulate movement such as running, turning (like your SendInput example), backpedaling or strafing by sending multiple WM_CHAR messages as you would see with Spy++ or a similar message loop monitoring tool, it will not work. You cannot emulate repeat/"held down" buttons.

This problem also manifests itself with emulation of mouse input. I believe the mouse position will always reflect the actual position even if you have crafted the messages to specify otherwise, because of the same physical status problem.

So you can emulate keyboard keypresses to background windows, but as for holding keys or mouse manipulation, you're pretty much out of luck.

There only appear to be a few possible solutions, none of which are straightforward, easy and background compatible:
  • DDK: A filter (to manipulate emulated messages)
  • DDK: A driver (to emulate them closer to the kernel, instead of via WINAPI)
Both of those are fairly heavy topics and don't appear to be well-documented openly on the Internet. You can check out if you're interested in digging deeper.
  • SendInput to active window, possibly with LLKHF_INJECTED/LLMHF_INJECTED patched out of kernel (heh)


Hopefully this is helpful to you.
lucid is offline  
Thanks
1 User
Old 11/15/2012, 12:06   #3
 
jackicola's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 129
Received Thanks: 15
Wow, Wow, Wow! Great answer! I have it like this now:
Code:
#include <windows.h>

int main()
{
	INPUT ip;


	Sleep(5000);

	ip.type = INPUT_KEYBOARD;
	ip.ki.wScan = 0; 
	ip.ki.time = 0;
	ip.ki.dwExtraInfo = 0;

	
	ip.ki.wVk = 0x41; 
	ip.ki.dwFlags = 0; 
	SendInput(1, &ip, sizeof(INPUT));

	ip.ki.wVk = 0x41; 
	ip.type = INPUT_KEYBOARD;
	ip.ki.dwFlags = KEYEVENTF_KEYUP; 


	Sleep(1000);

	SendInput(1, &ip, sizeof(INPUT));

	return 0;
}
But it's still not working... Can you please help me again?
jackicola is offline  
Old 11/15/2012, 13:16   #4
 
elite*gold: 0
Join Date: Feb 2006
Posts: 629
Received Thanks: 195
Probably because you're not setting a scan code.

Check out
lucid is offline  
Thanks
1 User
Old 11/15/2012, 14:45   #5
 
jackicola's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 129
Received Thanks: 15
Can you please say me where and how I have to implement this in my code?
jackicola is offline  
Old 11/15/2012, 16:21   #6
 
elite*gold: 0
Join Date: Feb 2006
Posts: 629
Received Thanks: 195
I don't program in C so I can't test the code.

You must map the Virtual Key code (set here)
Code:
ip.ki.wVk = 0x41;
...to a scan code (set to 0 here)
Code:
ip.ki.wScan = 0;
...in referencing the documentation...
Quote:
Originally Posted by MapVirtualKey Documentation
MAPVK_VK_TO_VSC
0

uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0.
...it might look like this:
Code:
ip.ki.wScan = MapVirtualKey(ip.ki.wVk, 0)
If it still doesn't work it might be worth taking a look through documentation for each of these elements to verify everything.

Function reference:

Input Structures:
lucid is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
C++ - Sending WM_WM_LBUTTONDOWN to Aion
07/04/2012 - Aion - 1 Replies
Hey, can anyone help me? I try to send a Message to Aion via SendMessage(): #include <iostream> #include <Windows.h> using namespace std; int main() {
Aion 1.9.0.3 sending keystrokes in background mode
08/29/2010 - Aion - 1 Replies
Hello to all! I'am trying to send keystrokes in BACKGROUND MODE to AION client using C++ (Builder2009): I do it like that: ... PostMessage(Window,WM_KEYDOWN, VK_OEM_MINUS, 0x00020001); ... This function works good for me, but as i can see i can't send WASD or VK_MENU(ALT) and more, something like game protection



All times are GMT +2. The time now is 19:46.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.