[C#] Question about SendKeys

11/14/2013 04:23 MyDooMJr#1
Does anyone ever worked with SendKeys on C# with 12sky2?

I can't find a way to make SendKeys.Send() working.

For example:
I set a global hotkey on F10, whenever I press it it was supposed to do this for example:
PHP Code:
SendKeys.Send("4"
Whenever I press F10, he don't do the function to press number 4 for me.
So when I do press ENTER (for the chat) and press F10 . It types the 4 on the chat.

I don't understand why this works when pressing F10:
PHP Code:
SendKeys.Send("{ENTER}");
                    
SendKeys.Send("Hello world!");
                    
SendKeys.Send("{ENTER}"); 
It send "Hello world!" in the chat, but when I try to make it pressing AoE key it does not.

I hope you understood my question..
This is only to Programmers that understand C# and might have a solution for this.

P.S: Yes I am using:
PHP Code:
[DllImport("user32.dll")]
        private static 
extern bool RegisterHotKey(IntPtr hWndint iduint fsModifiersuint vk);

        [
DllImport("user32.dll")]
        private static 
extern bool UnregisterHotKey(IntPtr hWndint id); 
To detect if the key was pressed etc, that is working fine.

Thanks!
11/14/2013 06:35 Requi#2
Try it with Send/PostMessage.
Have you started it as admin?

Does the game have a hackshield?
11/14/2013 15:26 MyDooMJr#3
Quote:
Originally Posted by Requi View Post
Try it with Send/PostMessage.
Have you started it as admin?

Does the game have a hackshield?
1- I will see what I can do with Send/postMessage soon.
2- No I didn't but I suppose it does on debug mode, gonna check later.
3- The game is protected by X-TRAP. But still how come it does work typing ingame chat, and it does not press the skills :(
11/14/2013 21:27 Requi#4
I've no idea. But it doesn't start with admin rights while debugging.
Made same Mistake a while ago.
11/14/2013 23:35 MyDooMJr#5
Quote:
Originally Posted by Requi View Post
I've no idea. But it doesn't start with admin rights while debugging.
Made same Mistake a while ago.
Ran the app as admin same effect.

Could you let me a link where I could learn that PostMessage thing or so ? Thanks. Google is a lil messy
11/15/2013 12:38 Mega Byte#6
Game uses Dinput8 for keyboard input for everything other than textboxs *and pressing enter to show /send chat*

You can code a Dinput hook that lets you simulate keys, it also has an array of bytes that it reads the state of keyboard into. Prehaps set them to 0x80 and the key is pressed maybe.

Or you can use PostMessage i think with some weird settings I can't remember what they were.

If using on anti hacks they will prevent this method so go with injected dll and dinput fun times...

Here is one I prepared eariler...
D3DSendKeys.h
Code:
#ifndef __D3DSENDKEYS_H__
#define __D3DSENDKEYS_H__

// for a full list of keys see
// http://msdn.microsoft.com/en-us/library/ee418641.aspx
// or dinput.h

#include <dinput.h>
#pragma comment(lib, "dinput.lib")

void ClickLeftMouse();
void PressKey(WORD scan);

#endif
D3DSendKeys.cpp
Code:
#include "D3DSendKeys.h"

void ClickLeftMouse()
{
	INPUT inp;
	inp.type = INPUT_MOUSE;
	inp.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
	SendInput(1, &inp, sizeof(INPUT));
	Sleep(20);
	memset((void*)&inp, 0, sizeof(INPUT));
	inp.type = INPUT_MOUSE;
	inp.mi.dwFlags = MOUSEEVENTF_LEFTUP;
	SendInput(1, &inp, sizeof(INPUT));
}


void PressKey(WORD scan)
{	
	INPUT inp[2];
	memset(inp,0,sizeof(INPUT));
	inp[0].type = INPUT_KEYBOARD;
	inp[0].ki.dwFlags = KEYEVENTF_SCANCODE;
	inp[0].ki.time = 1;
	inp[1] = inp[0];
	inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;
	inp[0].ki.wScan = inp[1].ki.wScan = scan;
	SendInput(2, inp, sizeof(INPUT));
}
But of course thats C++ not C#

As for learning API's check out pinvoke and msdn maybe ;)

good luck :P

Edit:
Back before I switched to C++ for game hacks, I had made Map Fun in C#.
Check out frmMain.cs here, [Only registered and activated users can see links. Click Here To Register...]
I may have had some basic sendkey functionality working to use skills or pickup items.
But I can't remember 100%..