Jump to content

ControlClick problem [UNSOLVED]


 Share

Recommended Posts

Hey guys...i have created a program that finds something in a window and then right-clicks on it...but the window is not maximized so i need to find the actual object. Now i know where the object is on my screen. Let's say it's at [x,y]. This is what i did...

$WinPos = WinGetPos("ABC","","")

x = x - $WinPos[0] ; gives me a new 'x' and 'y' mathematically depending on where the object is on the screen and what the position of the window is

y = y - $WinPos[1]

So now TECHNICALLY it should work...but it doesn't...

IF i have my mouse in the window it actually ends up right-clicking at wherever the mouse is...which is also wrong....why is it not working :-(

Edited by ARozanski
Link to comment
Share on other sites

  • Moderators

You have absolutely not provided enough information, or even proper code snippet of what you are doing (WinGetPos() only has 2 parameters, your example is using 3).

Try re-thinking what you are asking, then post a proper question with a proper code snippet.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Link to comment
Share on other sites

You are totally RIGHT! i am extremely sorry, i re-read my own post and couldn't even understand what i was trying to say...hehehe...

Ok, here goes again.

I am trying to create a B O T for a game that right-clicks on a target whenever a specific target comes into focus on the window. Now, Since i want to be using my computer while this thing is running, everything i have done works with ControlSend and ControlClick and the window is NOT maximized... but the ControlClick does not work for me...

so this is what happens...

ControlClick "Sends a mouse click command to a given control" to "the x,y position to click within the control." -- Therefore, it will not be the usual x,y in my screen BUT the x,y in the window of the game...

Code:

$WinPos = WinGetPos("Game","")
         $target[0] = $target[0] - $WinPos[0]
         $target[1] = $target[1] - $WinPos[1]

        ControlClick("Game","","","Right",1,$target[0],$target[1]) ;

BUT it does not work. I does not right click on the target. But if i have my mouse over the window it will however right-click on where ever my mouse is at, at that moment.

Link to comment
Share on other sites

  • Moderators

You'll have to translate WinGetPos()'s "screen" coordinates to "Client" coordinates (Control functions only work within the client area of the window).

Might do a search for ScreenToClient.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You'll have to translate WinGetPos()'s "screen" coordinates to "Client" coordinates (Control functions only work within the client area of the window).

Might do a search for ScreenToClient.

Thanks...i will change my code to ScreenToClient becuase it is less sloppy, but my function already finds the x,y of the target BECAUSE - it already knows the screen x,y of the target and then i work it out by subtracting the x,y value on the target (in the screen) by the x,y value of the position of the window...my problem is that the controlclick is not working...

Link to comment
Share on other sites

  • Moderators

Thanks...i will change my code to ScreenToClient becuase it is less sloppy, but my function already finds the x,y of the target BECAUSE - it already knows the screen x,y of the target and then i work it out by subtracting the x,y value on the target (in the screen) by the x,y value of the position of the window...my problem is that the controlclick is not working...

If you have the "Screen" xy coords, then ScreenToClient is all you would need.

Func _ScreenToClient($h_wnd, $i_x, $i_y); Returns an array, [0] = x, [1] = y
    If IsString($h_wnd) Then $h_wnd = WinGetHandle($h_wnd)
    
    Local $t_xy_coords = DllStructCreate("int x; int y")
    DllStructSetData($t_xy_coords, "x", $i_x)
    DllStructSetData($t_xy_coords, "y", $i_y)
    
    DllCall("user32.dll", "int", "ScreenToClient", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_xy_coords))
    
    Local $a_ret_coords[2] = [DllStructGetData($t_xy_coords, "x"), DllStructGetData($t_xy_coords, "y")]
    Return $a_ret_coords
EndFunc
Just pass the handle or the window name, your x coord, and your y coord.

It will return a 2D array, [0] = x client, [1] = y client.

edit:

removed redundant code

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Sorry, i dont think you understand me...my program works out the X,Y of the target IN the control window. i even checked it out...its 100%...but something is wrong with my CONTROLCLICK - it just doesn't click where i ask it to :-/ ... i fact - i think it doesn't click at all in the control window

thanks again...

Edited by ARozanski
Link to comment
Share on other sites

  • Moderators

Sorry, i dont think you understand me...my program works out the X,Y of the target IN the control window. i even checked it out...its 100%...but something is wrong with my CONTROLCLICK - it just doesn't click where i ask it to :-/ ... i fact - i think it doesn't click at all in the control window

thanks again...

So what you are saying is... "SmOke_N, I have the x and y "Client Coordinates", however ControlClick() is still failing"?

1. You are not using any control identifier.

2. I'm done with the cloak and dagger... There's no replication script, and no idea what to even test in.

Might try manipulating _MouseClickPlus() to suit your needs.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

So what you are saying is... "SmOke_N, I have the x and y "Client Coordinates", however ControlClick() is still failing"?

1. You are not using any control identifier.

2. I'm done with the cloak and dagger... There's no replication script, and no idea what to even test in.

Might try manipulating _MouseClickPlus() to suit your needs.

Sorry SmOke_N, I do not mean to be disrespectful and there is no cloak and dagger... I have explained everything! I agree, my first post was stupid, but i explained everything after that.

1) I have a game with a target that appears every no and then

2) When he does so, i find the target using PixelSearch (it works fine)

3) I get the x,y coords of the target on the SCREEN

4) I get the Window position (wingetpos) of the game window and with that

i work out where the target it IN the window using the x,y coords of the screen. I checked it, the coords IN the window are correct.

5) I activate the window (WinActivate) incase that is the problem

6) I use ControlClick to click on the target. (THIS DOESN'T WORK)

That's ALL...somewhere in the program i even use ControlSend and it works without a control ID...

my question is - WHY is my ControlClick not working... i have checked everything.

P.S. i found no functions called: _MouseClickPlus() - where should i look please

Link to comment
Share on other sites

CAN ANYONE RESOLVE THIS OR SHOULD I JUST GIVE UP???

PLEASE

If you know the exact coordinates where you need to click then you just need MouseClick not ControlClick.

If you are contemplating giving up after such a brief effort then I have very little hope for you :).

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

If you know the exact coordinates where you need to click then you just need MouseClick not ControlClick.

If you are contemplating giving up after such a brief effort then I have very little hope for you :).

Brief effort?? i've been sitting waiting for a valid answer the whole night =\ PLEASE HELP! hehe...

I switched back to MouseClick, i pretty much ended up doing this:

1) Save MousePos

2) Save the active window title

3) Activate the game

4) Click the mouse

5) move back to where the mouse was and activate the previous window

It's REALLY sloppy and annoying but it works for now...i REALY want this ControlClick to work...

again...PLEASE HELP! I'm certain there is someone on this forum with enough competence to help me!

Edited by ARozanski
Link to comment
Share on other sites

Brief effort?? i've been sitting waiting for a valid answer the whole night =\ PLEASE HELP! hehe...

I switched back to MouseClick, i pretty much ended up doing this:

1) Save MoustPos

2) Save the active window title

3) Activate the game

4) Click the mouse

5) move back to where the mouse was and activate

It's REALLY sloppy and annoying but it works for now...i REALY want this ControlClick to work...again

PLEASE HELP! I'm certain there is someone on this forum with enough competence to help me!

You've been waiting the whole night? Wow.

You can't be serious.

Presumably between steps 3 and 4 in your list you moved the mouse to the correct position. Have you tried adding a delay so you can see where the mouse click is made?

As far as competence is concerned I suspect you could fix it yourself if you carefully checked and tested each step, adding something to help you debug your script and so on.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You've been waiting the whole night? Wow.

You can't be serious.

Presumably between steps 3 and 4 in your list you moved the mouse to the correct position. Have you tried adding a delay so you can see where the mouse click is made?

As far as competence is concerned I suspect you could fix it yourself if you carefully checked and tested each step, adding something to help you debug your script and so on.

I believe that he's waiting for the full code :)

Cheers m8... i really admire your patience.

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

You've been waiting the whole night? Wow.

You can't be serious.

Presumably between steps 3 and 4 in your list you moved the mouse to the correct position. Have you tried adding a delay so you can see where the mouse click is made?

As far as competence is concerned I suspect you could fix it yourself if you carefully checked and tested each step, adding something to help you debug your script and so on.

Well - the mouseclick version works just fine - that was child's play...but for SOME REASON ControlClick does not. I don't know, MAYBE it just doesn't work all the time...who knows...im just waiting for an answer...as far as checking all possible problems:

1) i checked that the calculations for the x,y coords in the game window were correct (they are)\

2) i activated the window just incase that was the problem (like the helpfile said) - didnt solve anything...

3) i moved the mouse over the game and it clicks where ever my mouse is - which means that the controlclick function works to some extent...just not the desired extent :-(

Link to comment
Share on other sites

  • Moderators

Well - the mouseclick version works just fine - that was child's play...but for SOME REASON ControlClick does not. I don't know, MAYBE it just doesn't work all the time...who knows...im just waiting for an answer...as far as checking all possible problems:

1) i checked that the calculations for the x,y coords in the game window were correct (they are)\

2) i activated the window just incase that was the problem (like the helpfile said) - didnt solve anything...

3) i moved the mouse over the game and it clicks where ever my mouse is - which means that the controlclick function works to some extent...just not the desired extent :-(

I don't think you've heard or understood a thing I've said... GL.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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