Jump to content

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


Term!nX
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

  • 2 weeks later...

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.
Link to comment
Share on other sites

  • 4 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...