Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Implementation of Send VS ControlSend

  • Please log in to reply
4 replies to this topic
  • Guests
  • Last active:
  • Joined: --
So, from my understanding, the two following commands should (most of the time) behave identically.

Send, {keys}
ControlSend, , {keys}, A

Sadly, however, there are cases in which this isn't the case and I'm confused as to why.

First example: if I'm using Chrome or IE to play a flashgame...

Send, {Left}
will successfully send a left movement to the game

ControlSend, , {Left}, A
Will do nothing of interest

A second example: if I open any folder (lefts use "My Documents" for now)

If my curser is in the address bar and I
Send, {Left}
Then the curser will move one to the left.

If I
ControlSend, , {Left}, A
Then, again, nothing of interest happens

If, however, I go to Google and place my curser in the search bar, both send and control send work just fine.

Here is my question... how do I get the two to function identically?
I would like to be able to get my scripts to work in the background by replacing all calls to "Send, {key}" with "ControlSend, , {key}, ahk_id %windowID%"

  • Guests
  • Last active:
  • Joined: --

Here is my question... how do I get the two to function identically?

You can't. They use entirely different methods, hence the difference in capabilities.

  • Guests
  • Last active:
  • Joined: --
If I look at the Send command in the AutoHotKey documentation, the very first line reads:

"Sends simulated keystrokes and mouse clicks to the active window."

Which is what lead me to believe that a ControlSend to the "active window" should also "send simulated keystrokes and mouse clicks to the active window".

So how and why do the two differ?

I understand that the two commands are different... I don't understand what about that difference makes one fail to work. It seems to me that there must be a way in which to "ControlSend" keystrokes to any place that a keystroke can be sent...

  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The help file describes, in laman's terms, the effect of the command. In actual fact, ControlSend sends messages directly to a window or control which are ordinarily sent by Windows in response to keyboard input. If the target program does not respond to those messages but instead monitors keyboard activity via some other method, it will not have the desired effect.

Send uses one of three different APIs provided by the OS to simulate keyboard input. These APIs may in turn generate messages identical to the ones generated by ControlSend, but also affect the "keyboard state" of the active window's thread. If a program asks "is key x pressed", the answer may be "yes" if Send was used but "no" if ControlSend was used.

You don't need to understand it, just accept that they are different and use whichever command works for your purpose.

  • Members
  • 2067 posts
  • Last active: Feb 26 2016 09:30 AM
  • Joined: 10 Jul 2008

It's just a matter of goal.
Send just type key
ControlSend is designed to send a key to a control (so, it's the name of the command you see...).

In simple words :
Send simulate the a keystroke so it send the key at the place of the cursor (like in a text editor).
ControlSend send the key at a specific control not at the cursor position, but if the cursor it's in the control it send at the position of the cursor and if not it send at the begining and continue at the end of the previous key send.
You can try that with the Run command of Windows.
- type a text (notepad for example) use "Tab" to lost the focus from the Edit1 control
- use ControlSend Edit1, Test, Run
It should type Test in front of notepad (Testnotepad).
But if you use send it will just send Test to the button which has the focus.

Understood ? :)