Jump to content
c7aesa7r

Controlsend & stored handle

Recommended Posts

Posted (edited)
$key = "{a}"
$hwd = '0x001C1000'
$hwd2 = WinGetHandle("[CLASS:TFormMain]")

consolewrite("hwd  = " & $hwd & @CR )
consolewrite("hwd2 = " & $hwd2 & @CR)

ControlSend($hwd,"","",$key)
ControlSend($hwd2,"","",$key)

image.png.0c08c7b0a133af3972c70c17ada6f251.png

In the script above when i use ControlSend with handle (hw2) stored by WinGetHandle it work perfectly, and when i use ControlSend with the handle (hwd) stored in a variable it never works.

Don't want be rude, but im not looking for alternative ways to my script, i would like just understand why with hwd2 it works and hwd don't.

Edited by c7aesa7r

Share this post


Link to post
Share on other sites

hwd is a string, not a handle

hwd2 is a handle

 

Thy this:

$h1 = WinGetHandle("[active]")
$h2 = '0x000504C8'
ConsoleWrite(IsHWnd($h1) & @CRLF)
ConsoleWrite(IsHWnd($h2) & @CRLF)
ConsoleWrite($h1=$h2 & @CRLF)
ConsoleWrite("" & @CRLF)

consoloutput is:

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
1
0
False
+>13:43:14 AutoIt3.exe ended.rc:0

 


UDF: _SingleScript()                                        If you like my post, just click the like button :)        here -->

Share this post


Link to post
Share on other sites
Posted (edited)
8 hours ago, Nine said:

Use this to actually create a handle (with or without ' or ")


$hwd = HWnd (0x001C1000)

😸Gracias.

 

@Nine how can i call a value stored in var?  I tried execute,call.😳😳

I mean when $var be = 1 Then $x = carlos, $var be = 2 ,$ x = etc

$var = 0
$x = 0

If $var = 1 Then $x = carlos
If $var = 2 Then $x = bea
If $var = 3 Then $x = thaynara
If $var = 4 Then $x = pedro

While 1

$var = $var + 1
Execute($var)
ConsoleWrite($x & @LF)

WEnd

 

Edited by c7aesa7r

Share this post


Link to post
Share on other sites

@c7aesa7r

Use Switch statement instead of If, and use the equal operator to assign a value to your variables.

Maybe you should read this post :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

@FrancescoDiMuro i have read the link you post, but im still dont understand how do it, i also look in help for switch

 

$var = 0
$x = 0

Switch $var

Case $var = 1
$x = 1

Case $var = 2
$x = 2

Case $var = 3
$x = 3

Case $var = 4
$x = 4

EndSwitch


While 1

$var = $var + 1
ConsoleWrite("var = " & $var & @LF)
ConsoleWrite("x = " & $x & @LF)
sleep(500)

If $var = 5 Then $var = 0

WEnd

 

I also tried:

$var = 0
$x = 0

While 1

$var = $var + 1

If $var = 1 Then $x = "carlos"
If $var = 2 Then $x = "bea"
If $var = 3 Then $x = "thaynara"
If $var = 4 Then $x = "pedro"

If $var = 5 Then ExitLoop

WEnd

While 1

$var = $var + 1
ConsoleWrite($x & @LF)
sleep(500)
If $var = 5 Then $var = 0

WEnd

Im trying $x have value according to actual $var number

Edited by c7aesa7r

Share this post


Link to post
Share on other sites

@c7aesa7r

In the first script, you assign to $var the value of 0, then Switch it from 1 to 4 pretending to have some output, then you enter in an infinite loop which increments $var from 0 to 5, and resets it continuously when it reaches the value of 5, always printing $x = 0.

In the second script, you have a loop that stops as soon as $var reaches 5, but to the variable $x is assigned always the last value before exiting the loop ($var = 4), then you enter again in an infinite while loop where you continuously increment $var until it's resetted to 0 when it reaches the value of 5.

27 minutes ago, c7aesa7r said:
WEnd

Im trying $x have value according to actual $var number

Then use Switch statement in an appropriate way, as it is showed in the Help file, and design a little bit of logic before write the script.


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

-Edit-

I did it, nothing with "Switch" @FrancescoDiMuro  thank you for your 'precious' :shifty: help, i dont know why people come in others post with no intention to help and only say go "look help file".

$var = 0
$x = 0

While 1

$var = $var + 1
Call("Sel")
ConsoleWrite("var = " & $var & @LF)
ConsoleWrite("x = " & $x & @LF)
ConsoleWrite(" "  & @LF)
sleep(2000)

If $var = 5 Then $var = 0

WEnd


Func Sel()

Select

Case $var = 1
$x = 1

Case $var = 2
$x = 2

Case $var = 3
$x = 3

Case $var = 4
$x = 4

EndSelect

EndFunc

 

Edited by c7aesa7r

Share this post


Link to post
Share on other sites
Posted (edited)
7 hours ago, c7aesa7r said:

i dont know why people come in others post with no intention to help and only say go "look help file".

That's because the Help file is the very first resource of Help from which you can see in details how to use a function, thanks for the example(s) included.

Why everyone should even waste his/her time to explain something that is already explained in details somewhere else? Lazyness? :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

you can also convert a string to handle via HWND function.  That's what I use to pass handles between scripts in command line execs.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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

×
×
  • Create New...