Jump to content

How to ControlSend()?


IAMK
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

  • Developers

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

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

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