Jump to content
Sign in to follow this  
Term!nX

Writing Macros in C++, simulated Keystrokes do not activate Hotkeys

Recommended Posts

Term!nX

Hi there,

for education purposes I rewrite my au3 macrobots for Guild Wars into C++ (further step is memory support). Actual no problem, but the simulated keystrokes do not activate Hotkeys. What I mean by this..:

I simulate the press of 8 ingame. But it does not give the desired effect, namely to use skill 8. The funny thing is, that the 8 is written correctly in the ingame-chat and textdocuments. So the Guild Wars surface gets the 8 but does not trigger the Hotkey.

First I tried the keybd_event function, as it did not work I tried SendInput. Here are the functions:

void sendakey(int mykey)
{

/* YOU HAVE TO COPY #define _WIN32_WINNT 0x0501
#include <windows.h> into the header. It is important that you first write the #define stuff before you include windows.h
I write this because I needed the help of a very kind person. Would have never found out on my own :) */


    INPUT input[2];
    memset(input, 0, sizeof(input));
    input[0].type = INPUT_KEYBOARD;


    input[0].ki.wVk = mykey;
    input[0].ki.dwFlags = 0;
    input[0].ki.time = 0;
    input[0].ki.dwExtraInfo = 0;

    input[1].ki.wVk = mykey;
    input[1].ki.dwFlags = KEYEVENTF_KEYUP;
    input[1].ki.time = 0;
    input[1].ki.dwExtraInfo = 0;

    SendInput(2,input,sizeof(INPUT));
}

2nd keybd_event:

void sendkey(int key)
{
     keybd_event(key, 0, 0, 0); 
     keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
}

In both cases I tried to set the Windows digitally in the foreground:

game_hwnd = FindWindow(NULL, "Guild Wars");
    ShowWindow(game_hwnd, SW_RESTORE);
    SetForegroundWindow(game_hwnd);
    SetFocus(game_hwnd);

Okay, my question:

How does au3 simulate keystrokes? Why does the au3 Send("string") function work? I hope these aren't deep secrets ;)

greeting

PS: I am NOT a C++ geek, so please take that into consideration :)

Edited by Term!nX

Share this post


Link to post
Share on other sites
Richard Robertson

I believe that AutoIt connects itself to the process or thread to allow it to post keystrokes more accurately.

Share this post


Link to post
Share on other sites
Term!nX

I tried this, either:

HWND targetHWND=0;
DWORD thisThread,otherThread;


targetHWND=FindWindowA(NULL,"Guild Wars");
if(targetHWND==0) {MessageBoxA(0,"Not Found","Error",0);}


//ThreadId 
thisThread=GetCurrentThreadId();
otherThread=GetWindowThreadProcessId(targetHWND,NULL);



//Attach
if(!AttachThreadInput(thisThread,otherThread,true)) {
    MessageBoxA(0,"Miss","not successful",0);
}

Desperated :)

Edited by Term!nX

Share this post


Link to post
Share on other sites
Richard Robertson

I don't know anything about attachments to other threads. I'm afraid you will have to wait for someone with a little more background.

Share this post


Link to post
Share on other sites
Term!nX

how about AutoItX ?

Shall I post in this Forum? Dont know what you mean by this, but I wont use a different language since I want to educate myself in C++. Therefore I really need to get a solution for this problem :)

Hm, do you think the Send("") function is included in the official SourceCode files? Then I could look up how the creators of au3 simulated a keystroke.

So, I looked up the sendkeys.cpp sourcecode file and found the specified function. But however, I am not skilled enough to understand this function 100%. Is the WinAttach()-function a userdefined function or is it included in one of the headerfiles, e.g. the WinAPI?

Edited by Term!nX

Share this post


Link to post
Share on other sites
piccaso

You can use autoitx from c/c++ too but if you want to do it the hard way you have to study sendkeys.cpp closer.

and for WinAttach() and your education:

come on, read the class definition :)

if your looking at Send(), scroll down ~2 pages.

After Send() comes SendRaw() and then WinAttach()


CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites
Term!nX

atm im rly drunk but i tink i can get the sense of your post.. i MUST code in c++.. it is not important to me to bot money in GW, I just want to educate myself in Cp++. I want to study C++ this is the most important goal. everything else is suvimportant :)

Share this post


Link to post
Share on other sites
Richard Robertson

AutoItX is a dll you can link to with your C++ application. Piccaso's idea is the easiest. The dll is part of the installation of AutoIt.

Share this post


Link to post
Share on other sites
Term!nX

No other way? so that im completely seperated from autoit? There is an option "hardware check" in the keybd_event function. Useful for my problem?

Share this post


Link to post
Share on other sites
Term!nX

I tried this. I used VK_RETURN and 0x0D .. not working for GW. Nevermind, after a week of testing without a result, I decided to use autoitx. Thanks anyway :)

Share this post


Link to post
Share on other sites
Term!nX

Okay some researches gave the result, that GW blocks Inputs sent by windows. It only accepts inputs directly from the device driver.

Therefore I have to write a program which sends the inputs to the driver, not to the process :)

Share this post


Link to post
Share on other sites
Richard Robertson

How do you send something to a driver? If you can figure out how to do that, share it with us, because I'd quite like to learn that.

Share this post


Link to post
Share on other sites
jvanegmond

How do you send something to a driver? If you can figure out how to do that, share it with us, because I'd quite like to learn that.

Same here. Although, I think that even although all drivers are different the most of them do not allow this.. Perhaps this could be done in a hackish kind of way, but not by going through the default routes.

Share this post


Link to post
Share on other sites
Term!nX

I dont know how to..

But I am really interested how autoit sends the keystrokes. Because autoit emulated keystrokes work for gw. Can I figure the technique out by reading through the sourcecode?

Share this post


Link to post
Share on other sites
jvanegmond

I dont know how to..

But I am really interested how autoit sends the keystrokes. Because autoit emulated keystrokes work for gw. Can I figure the technique out by reading through the sourcecode?

There's only way to find out. I say, yes.

Share this post


Link to post
Share on other sites
voidvoid

hey man i think the problem is in this line SendInput(2,input,sizeof(INPUT));

because u r not sending 8 you are sending everything that is INPUT and that includes type and whatever the structure holds

Share this post


Link to post
Share on other sites
Valik

You just fucked a four year old corpse. How does that make you feel?

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×