Jump to content

Controlsend() not working? Tried all parameters i can think of...


Recommended Posts

Hi, i'm trying to send a "r" key to a minimized application.

I've tried several different approaches i found in the help file and the forums, but can't get any to work.

When i use AutoItv3WindowInfo, i cannot find the control id number either (I did enable the Options -> Highlighting controls), so i've tried different work-arounds there too.

1) No 3rd parameter.

$app = "Application"
controlSend($app, "", "", "{r}")

2) Using PID for 3rd param.

$app = "Application"
$pid = WinGetProcess($app)
controlSend($app, "", $pid, "{r}")

3) Using zero for 3rd param.

$app = "Application"
controlSend($app, "", 0, "{r}")

None are sending the "r" to the application.

Can anyone offer me some help please?

Thank you.

Link to comment
Share on other sites

Also tried:

4) To find the ControlID:

$app = "Application"
$cid = ControlGetFocus($app)
MsgBox(1,$app, $cid)
This is returning an empty box, just like the au3Info tool.

5) To run using "null" $cid...

$app = "Application"
$cid = ControlGetFocus($app)
controlFocus($app, "",$cid)
controlSend($app, "", $cid, "{r}")
Doesn't work either.
Link to comment
Share on other sites

I used the drop tool and dropped it directly into the application, here is the summary tab:

>>>> Window <<<<
Title:  Application
Class:  SFMainWindow
Position:   0, 0
Size:   1158, 890
Style:  0x14CA0000
ExStyle:    0x00000100
Handle: 0x0037044E

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 0x000100FE

>>>> Mouse <<<<
Position:   617, 284
Cursor ID:  0
Color:  0x2C1E10

>>>> StatusBar <<<<

>>>> Visible Text <<<<


>>>> Hidden Text <<<<
Link to comment
Share on other sites

Nope, that's not working either. I tried

1) ControlSend('[CLASS:SFMainWindow]', '', '', 'r')
2) ControlSend("[CLASS:SFMainWindow]", "", "", "{r}")
3) ControlSend("[CLASS:SFMainWindow]", "", 0, "{r}")

No luck for any.

Edited by Dart
Link to comment
Share on other sites

Problematic, you need to find a way to reference a control to successfully send it a keystrokes. Maybe you can use WinList() or the _WinAPI_GetWindow() functions to get a reference and use this handle either in the first or the third parameter of the ControlSend() function. Otherwise, you'll need the window to be the focused window to send keystrokes successfully.

Example:

#include <Constants.au3>
#include <WinAPI.au3>

Run('notepad.exe')
WinWaitActive('[CLASS:Notepad]')
$hWnd = WinGetHandle('[CLASS:Notepad]')
$hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)

WinSetState($hWnd, '', @SW_MINIMIZE)
WinWaitNotActive($hWnd)
ControlSend($hWnd, '', $hChild, 'r')
; ControlSend($hChild, '', '', 'r')
WinSetState($hWnd, '', @SW_RESTORE)

Notepad is not a good example but just to demonstrate the procedure...

Edit: {r} has no special meaning so it's not the problem although you're right the it's syntactically not correct.

Edited by Authenticity
Link to comment
Share on other sites

No, this isn't working either. I thought it was, but it's just emulating a regular "send" command.

So here is something i've noticed. The window-handle and the control-handle are different. The window-handle is unique to the application i'm trying to automate (lets call it X). The control-handle is being passed on from X to the next application i try to run (say SciTE or Iexplorer; call it Y). The r button is in a loop. So if i switch from program X to Y, then the r is just repeated into Y. This totally negates the objective of using controlSend in the first place.

I am guessing here, but could it be that X is somehow protected against automation? If it is, there must be something (control values) showing up somewhere? Perhaps they are just invisible to the Au3Info. How do i get to the data? I'm not trying to do any hacking here, so if i'm approaching something borderline non-legit, please just make me aware. I'm just trying to automate some repetitive tasks. I also find this a very useful/interesting learning problem toward learning to script with AutoIT. I am a relatively new at using programming languages other than my Civil Engineering C++ core curriculum requirement.

Link to comment
Share on other sites

I think you could find something useful from using AHK Window Info.

It can show all controls of a window. But, it may use CPU quite high at times.

Never had any issue with ControlSend, so I'm not sure if it can help.

Good luck.

Link to comment
Share on other sites

I think you could find something useful from using AHK Window Info.

It can show all controls of a window. But, it may use CPU quite high at times.

Never had any issue with ControlSend, so I'm not sure if it can help.

Good luck.

You've really mentioned something very touchy. Great job. Maybe you should look up on the history!

@OP- try winspy++. Have you done what Authenticity suggested with _WinAPI_GetWindow()?? What is the application you are trying to automate?

Link to comment
Share on other sites

Brett,

The program i'm trying to automate is Darkfall Online (DF). Ya,i'm trying to make a game bot, but that's what i find fun and interesting. Applying scripting/programming to games allows me to learn. It's not like my bot is going to play the entire game for me, just automate some functions.

I hope that at some point the time i've invested into learning to script will offer me a base from which to program in a more professional setting; maybe automating some tasks related to traffic pattern designs.

Back to the issue,

The post below Authenticity suggesting _WinAPI_GetWindow() is my response to having tried that technique. It was unsuccessful in that in order for they keystrokes to work, DF had to have focus.

Ok, i'm getting set to try winspy++. If that doesn't work i will try MDCT's suggestion. First though, i'm going to see what Brett is talking about relating to history of MDCT's topic. I guess a forum/google search should get it done.

I'll update when done.

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