Jump to content
IAMK

How to ControlSend()?

Recommended Posts

IAMK

I have tried all different things (including bad workarounds) I could think of implementing or searching for...

I am unable to figure out how to press keyboard buttons in the window I wish to have access. NOTE: I have a GUI which I force to the top at all times (It's an overlay).

Here is my very simple code. An image sits at the top and presses 3 keyboard buttons (F2, then 2, then F2) when clicked on:

#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$K_GUI = GuiCreate("K_GUI_BUTTON", 500, 200, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW) ;Create a window-less GUI.
WinSetOnTop($K_GUI, "", 1) ;Keeps the window on the top.
WinSetTrans($K_GUI, "", "255") ;Make the window invisible.
$pic = GUICtrlCreatePic("image.jpg", 0, 0, 500, 200)
GUISetState()

While(1)
   $msg = GUIGetMsg()

   If $msg = $pic Then
      ControlSend("[TITLE:Shell]", "", "x", "{F2}{2}{F2}")
   EndIf

   Sleep(1000)
WEnd


I have tested that the image click works with a MsgBox(), but I can't get the keyboard inputs to work.

 

Thank you in advance.

myScriptImg.png

Edited by IAMK

Share this post


Link to post
Share on other sites
IAMK

Well, I guess I found a working workaround...

While(1)
   $msg = GUIGetMsg()

   If $msg = $pic Then
      MouseClick("Primary", 10, 10, 1, 0)
      Send("{F9}{5}{F9}")
   EndIf

   Sleep(1000)
WEnd

The mouseclick clicks on the window I was trying to control send to. I'm not too happy with this method though.
I would still like better solutions to this, if there are any.

Share this post


Link to post
Share on other sites
Jos

Have you checked the success of the ControlSend() as you are sending it to the ControlID "x" which I guess is your way of saying "any"?

Jos

 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
IAMK
On 4/24/2018 at 7:01 PM, Jos said:

Have you checked the success of the ControlSend() as you are sending it to the ControlID "x" which I guess is your way of saying "any"?

I looked at the help page for ControlSend() and saw "Edit1", which I thought was a random string, hence why I just renamed it to "x" for any, like you said.

After reading your comment, I realised that "Edit1" is an actual expected value...

Share this post


Link to post
Share on other sites
Zedna

As Jos said

try  ControlSend("[TITLE:Shell]", "", "", "{F2}{2}{F2}")

instead of previous  incorrect ControlSend("[TITLE:Shell]", "", "x", "{F2}{2}{F2}")

When ControlID is empty then it's sent to "active" control (with focus)

Edited by Zedna

Share this post


Link to post
Share on other sites
IAMK

@Zedna, Yes, I tried it again after re-reading and it worked. Thanks for the response.

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

×