Jump to content

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


Recommended Posts

Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
Posted

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
Posted

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

  • 2 weeks later...
Posted

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?

  • Administrators
Posted

You need to send the scan codes as well as the VK code for it to work in most games.


 

Posted

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

Posted

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

Posted

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.
Posted

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?

  • 4 years later...
Posted

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

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
  • Recently Browsing   0 members

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