Jump to content

Sending to inactive windows?


Recommended Posts

I searched the help documents and this forum... so I don't know if it's just me or I'm missing something...

Is there a way to send keystrokes to a window that is not in focus... I.E... let's say I wanted to run IE while the macro sent keystrokes to an application so that I can freely do whatever else I want while it runs?

Any help much appreciated, thank you.

Link to comment
Share on other sites

You want to look the Control* functions in the helpfile. They'll allow you to send various actions to any window provided you have its title and/ or text.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Yeah I tried that... apparently it "can't" send keystrokes with an ALT and I also can't seem to get it to send the {ENTER} key.

Example:

ControlSend( "Gameofsomekind", "", "", "{ENTER}", 0);

won't work? Or how about

ControlSend( "Gameofsomekind", "", "", "!1", 0);

I checked the other Control* options and couldn't come up with anything useful

Link to comment
Share on other sites

Regarding your enter and alt problem, you can't use flag 0 for that. You need to either use flag 1, or leave it off since 1 is the default. Flag 0 will send the keys in "raw" mode where special keys (like the ! modifier for alt and {ENTER} for the enter key will not be translated.)

Okay, I messed up and mentally reversed the flags. I even consulted the helpfile and just read it wrong :D

If you still have problems with the state modifiers (such as shift, alt, or control) you should check out my ControlSendPlus function. The only thing my ControlSendPlus will fix is the state modifiers appearing not to be sent properly.

Minor edit

Major edit to correct problem (see above)

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Regarding your enter and alt problem, you can't use flag 0 for that.  You need to either use flag 1, or leave it off since 1 is the default.  Flag 0 will send the keys in "raw" mode where special keys (like the ! modifier for alt and {ENTER} for the enter key will not be translated.)

[optional] Changes how "keys" is processed:

flag = 0 (default), Text contains special characters like + to indicate SHIFT and {LEFT} to indicate left arrow.

flag = 1, keys are sent raw.

The reason why its not working is because you need the "Class" of the window.

For example: (Send to a new notepad file)

ControlSend("Untitled", "", "Edit1", "{Enter}")

You can get the class by using the Spy tool from AutoIt.

From Help File

When using a control name in the Control functions, you need to add a number to the end of the name to indicate which control. For example, if there two controls listed called "MDIClient", you would refer to these as "MDIClient1" and "MDIClient2".

Wich means the first Class Ends with 1

Hope it helps

Edited by Doxie

Were ever i lay my script is my home...

Link to comment
Share on other sites

Hmm...still doesn't seem to work properly...

If it's any help here's the code I'm using. It's a simple looping macro to raise summoning skill in FFXI *shrug*

Sleep(3000);Delay before running script

;Initializers***********

$summon = 1;
$avatar = 1;
$mp_out = 0;


While $summon = 1

AutoItSetOption("SendKeyDelay", 40); 
AutoItSetOption("SendKeyDownDelay", 100); 

Do

Sleep(250);

If $avatar = 1 Then ControlSend("FFXiApp", "", "FFXiClass1", "^5");
If $avatar = 2 Then ControlSend("FFXiApp", "", "FFXiClass1", "^6");
If $avatar = 3 Then ControlSend("FFXiApp", "", "FFXiClass1", "^7");
If $avatar = 4 Then ControlSend("FFXiApp", "", "FFXiClass1", "^8");
If $avatar = 5 Then ControlSend("FFXiApp", "", "FFXiClass1", "^9");
If $avatar = 6 Then ControlSend("FFXiApp", "", "FFXiClass1", "^0");

$avatar = $avatar + 1;
$mp_out = $mp_out + 1;

if $avatar = 7 Then $avatar = 1;

Sleep(11000);

Until $mp_out = 55;

Send("^H");
Sleep(155000);
Send("^H");
Sleep(2000);
$mp_out = 0;

WEnd

The game doesn't seem to register those ^ keys no matter what...though if I send them with a standard "Send" command they register just fine. I also tried using FFXiClass without a number and no go there either.

Edited by Mephs
Link to comment
Share on other sites

If $avatar = 1 Then ControlSend("FFXiApp", "", "FFXiClass1", "^5");

Is the name of the window FFXiApp, and you checked the class with Spy?

Open a new txt file and try this in your script while the new txt is minimized.

ControlSend("Untitled", "", "Edit1", "Living la vida loca")

Were ever i lay my script is my home...

Link to comment
Share on other sites

Whopsie, you're right Doxie. I even read the helpfile entry to make sure I had my information straight before I posted, so I just mixed up the numbers. 1 is pretty close to 0, right? :D

My above post has been modified.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

If $avatar = 1 Then ControlSend("FFXiApp", "", "FFXiClass1", "^5");

Is the name of the window FFXiApp, and you checked the class with Spy?

Open a new txt file and try this in your script while the new txt is minimized.

ControlSend("Untitled", "", "Edit1", "Living la vida loca")

Yeah spy said the class was "FFXiClass" and the window is FFXiApp

I already know that will work in notepad... just trying to figure out why it won't get this thing right...I tried everything I possibly could. I can get it to type words into the client no problem, btw... it's just those darned CTRL keystrokes that dont seem to register.

Anyway I tried your ControlSendPlus function... doesn't seem to work too well HOWEVER I did notice it was able to send the control stroke to the program with no trouble... -now- the only problem is it wont hti the number after the stroke to trigger the macro.

If $avatar = 1 Then ControlSendPlus("FFXiApp", "", "FFXiClass1", "^5", 2)

I also tried the other flags with it and still nothing. 2 seemed to be the closest.

Edited by Mephs
Link to comment
Share on other sites

I've heard that games often capture keystrokes to avoid bots... just what I've heard here, like, about every time someone trys this...

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Possible also, but then how come I can send them with just plain Send()?

And also I seem to be able to send the CTRL stroke as it causes the macro bar to pull up but doesn't send the key to activate the macros I want it to. So that can't be the case... :D

Gah this is irritating lol.

Link to comment
Share on other sites

maybe it ignores input to the control you're trying to send to when this macrobar thing is up? maybe that's a different control?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

I already know that will work in notepad... just trying to figure out why it won't get this thing right...I tried everything I possibly could.  I can get it to type words into the client no problem, btw... it's just those darned CTRL keystrokes that dont seem to register.

Anyway I tried your ControlSendPlus function... doesn't seem to work too well HOWEVER I did notice it was able to send the control stroke to the program with no trouble... -now- the only problem is it wont hti the number after the stroke to trigger the macro.

If $avatar = 1 Then ControlSendPlus("FFXiApp", "", "FFXiClass1", "^5", 2)

I also tried the other flags with it and still nothing.  2 seemed to be the closest.

I have tested all flags of my UDF with the Command Interperter, and they seem to function as expected. Some games may not work with it since it does use a combination of global modifiers (depending on the flag) and locally sent keystrokes (via ControlSend.) It all boils down to how your app or game detects keys. The only thing my ControlSendPlus function is designed to fix is an issue of shift, control, and/or alt keys not being sent correctally.

As for the difference in my flags, 2 and 3 do the same thing regarding the control key (this key would be sent globally before each key.) The difference is only in the handeling of the alt key, where 3 would still send that locally. If you aren't using any alt keys, then flags 2 and 3 will end up with the same result.

Possible also, but then how come I can send them with just plain Send()?

It could be a problem detecting any locally sent keys. You said that the control key didn't register until you used my UDF with flag 2? That would be globally sending the control key, and locally sending the 5 key. From the information you've provided, I'm guessing your game is rejecting locally sent keys. Either that, or you've incorrectally defined the title, text, and/ or control name. Just becase the control key was sent with my UDF doesn't mean the ControlSend worked. How about checking the return of my function? It will return 0 if any key failed to send due to a bad window or control title (just like ControlSend does.)

Readability edit

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

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

  • Recently Browsing   0 members

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