2 posts in this topic
I recently wanted to know how to differentiate between a mouse click and a touch click on controls in your GUI.
This can be interesting when using picture controls as buttons in combination with this UDF here.
No one could help me, so I tried my best to get it to work. And it works now! Unfortunately only for Windows 8 and above, as I had to use functions which are unavailable for older OS.
Additionally this was my first time writing DLLCalls myself. I hope (and think) that there are no mayor mistakes in it,
So here's the sample code:
The _WinAPI_Base64Decode is written by @UEZ (as well as the way to use PNG as button (from binary) - thanks for that!)
On Windows 7 there is the WM_TOUCH function which should handle touch events, but I couldn't get it to work on controls ..??
If you will get the x/y coordinates of a touch (even when you touch on controls) you could make the "EvaluateProximityToRect" check yourself - as this function is not available in Windows 7. Shouldn't be that hard.
Btw.: this here is the MSDN articel related to this topic: https://msdn.microsoft.com/en-us/library/windows/desktop/hh454931(v=vs.85).aspx
So thats it. Any questions and comments welcome!
I'm currently wondering if there is somehow to actually make autoit click inside a minimized program? & sent keystrokes ?
2nd question, how can i make it do a mouse click at e.g. x200,y200 while the are at like x354,y313 (This is purely an example.) would love to be able to do other shizz on my pc while the script is running if possible.
If this ISNT possible can u recommend a language / other scripting program which are able to do this ? willing to start over learning a new coding/scripting language.
I've encountered a small issue i just cant seem to program my way out of...
What im doing is: ;or rather, what im trying to do is
Pixelsearch for a color, within a part of my screen,
If color is present, i will rightclick it, for a menu to appear,
in which i want to Leftclick an option. Simplicity itself.
The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick
What can be done, but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
(Not sure if that makes sence, but maybe the code below will help you understand)
You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull
$pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF) ;This color is what i need to rightclick to bring up the menu
If not @Error then ;If the color is present
(Mouseclick("Right", $pos, $pos, 1, 1) ;Rightclick it, to bring up menu
;Here comes the part i cannot get to work
$x = MousegetPos(X) ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
$y = MousegetPos(Y) ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick
MouseClick("Left", $x, $y-30, 1, 1) ;This was supposed to give me a leftclick that is 30pixels below the rightclick.
(The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both.
Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys)
I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums.
Maybe while im at it, can i ask, what good does the  and  do, when using a "$variable" as coordinate?
Thanks in advance
I’m trying to click the “assign a playlist” url in this application (see info.png)
I don’t know if it is flash or not.
The control ID changes on every launch.
I can’t use mouseclick because it needs to be scheduled at night on a server.
So just ControlClick is left as an option.
I can find the handle to the window but not to the control, be it through text or classname, clas or advanced mode.
The mouse cursor doesn't even move after these commands.
$handle = WinGetHandle("[ACTIVE]")
ControlClick($handle, "", "[CLASS:TFlickerFreePaintBox.UnicodeClass; INSTANCE:1]",'left', 1, 54, 138)
ControlFocus("Q-MATIC Monitor™ 3", "", "[TFlickerFreePaintBox.UnicodeClass1]")
Controlclick("Q-MATIC Monitor™ 3", "",", "primary", 1, 54, 55)
ControlClick($handle, "", "", "Left", 1, 54, 55)
ControlClick("Q-MATIC Monitor™ 3", "", "[TEXT:Assign to playlist]")
ControlFocus ( "Q-MATIC Monitor™ 3", "", "TFlickerFreePaintBox.UnicodeClass")
What other parameters are possible for this?
I've got a simple little script that is trying to step through data in a datagrid. I have written and rewritten this thing to try and keep it running, but it just keeps coming up with values I just don't think it can get. I've played with the timing and it seems to run a little better when slowed down, but setting my $delay higher and higher gets me less and less improvement, but starts to really drag the process to a crawl. Removing the sleeps entirely isn't even that bad.
Every time I send a ^C to copy a value, I verify it, and then when I'm done with it, I reset the Clipboard with a known value that will never show in my data and reverify the clipboard. So either my reset/verification is not doing it's job or my mouse double click is not getting the coordinates updated. Neither of these options are great because I'm running out of ideas how to make sure I get what I want. About all I can do at this point is attempt my copy, then validate that the clipboard isn't my reset string, isn't zero length, and THEN match it to a date REGEX to see if it's the data from the correct column. That would be triple checking something that shouldn't need to be checked once. Scrip and output below:
$desiredDate = "2/9/2015" $yCoord = 290 $yStep = 15 $recDisplay = 9 ;number of rows to read before starting to scroll $totalRec = 0 $PONList = "" $delay = 250 $dcDelay = 12 $count = 0 $clipReset = "chicken" $oCoastal = WinActivate("Find FOC") WinWaitActive($oCoastal) if @error Then msgBox(1, "winactivate error", @error) Exit endif AutoItSetOption("MouseCoordMode", 0) AutoItSetOption("SendKeyDownDelay", 100) ClipPut("") While 1 ;get date ;MouseMove(284, $yCoord, 1) MouseClick("left", 284, $yCoord, 2, $dcDelay) Sleep($delay) while 1 MouseClick("left", 284, $yCoord, 2, $dcDelay) ;Sleep($delay) Send("^c") ;Sleep($delay) $thisDate = clipGet() if StringCompare($thisDate, $clipReset) <> 0 and StringLen($thisDate) > 0 Then resetClip($clipReset) ExitLoop EndIf WEnd ConsoleWrite($count & ": Date: " & $thisDate) ;check date matches what we want ;if not StringCompare($desiredDate, $thisDate) = 0 Then ;with some date functions, this could be improved to a date range if StringRegExp($thisDate, $desiredDate) = 0 Then ;just check to see if the desired date exists inside what was copied ;we have reached the end of our records MsgBox(1, "Found " & $totalRec & " total records", $PONList) Exit ;or exitloop endif ;get pon ;MouseMove(81, $yCoord, 1) MouseClick("left", 81, $yCoord, 2, $dcDelay) Sleep($delay) While 1 MouseClick("left", 81, $yCoord, 2, $dcDelay) ;Sleep($delay) Send("^c") ;Sleep($delay) $thisPON = clipGet() if StringCompare($thisPON, $clipReset) <> 0 and StringLen($thisPON) > 0 Then resetClip($clipReset) ExitLoop EndIf WEnd ConsoleWrite(" PON:" & $thisPON & @CRLF) ;Check if we want this record if StringCompare(StringMid($thisPON, 10, 1), "D") = 0 Then ;We want this record! $totalRec += 1 $PONList = $PONList & ", " & $thisPon EndIf if $recDisplay >= 1 Then ;still in the first 10 records and need to move the mouseclick position down by a record $yCoord += $yStep $recDisplay -= 1 Else ;reached the bottom of the data grid and need to click the down arrow in the bottom right of the grid to advance one record MouseClick("left", 650, 438,1) ;Sleep($delay) endIf ;consolewrite($recDisplay & @CRLF) $count += 1 Wend func resetClip($val = "") Do ClipPut($val) Until StringCompare(ClipGet(), $val) = 0 EndFunc And here's a sample output. Everything looks great until the last row. This was not the last row in the data and should not have stopped here, but you can see the PON is either still on the clipboard, or the mouse click did not update the coordinates and copied the MouseClick commands didn't move to the coordinates:
0: Date: 2/9/2015 PON:173714357INN0001 1: Date: 2/9/2015 PON:173708683DID0001 2: Date: 2/9/2015 PON:173708683DID0003 3: Date: 2/9/2015 PON:173546121INN0001 4: Date: 2/9/2015 PON:173701848INN0001 5: Date: 2/9/2015 PON:173454114INN0001 6: Date: 2/9/2015 PON:173708683DID0002 7: Date: 2/9/2015 PON:173714373DID0001 8: Date: 2/9/2015 PON:173709684INN0001 9: Date: 2/9/2015 PON:173621964INN0001 10: Date: 2/9/2015 PON:173710242CHC0001 11: Date: 2/9/2015 PON:855440C 12: Date: 2/9/2015 PON:173531625INN0001 13: Date: 2/9/2015 PON:173717963DID0001 14: Date: 2/9/2015 PON:173717560DID0001 15: Date: 2/9/2015 PON:173713978DID0001 16: Date: 2/9/2015 PON:173710221INN0001 17: Date: 2/9/2015 PON:173713002INN0001 18: Date: 2/9/2015 PON:173456352RGN0001 19: Date: 2/9/2015 PON:173712598DID0001 20: Date: 2/9/2015 PON:173709807DID0001 21: Date: 2/9/2015 PON:173616984INN0001 22: Date: 2/9/2015 PON:173646606INN0001 23: Date: 2/9/2015 PON:173649988INN0002 24: Date: 2/9/2015 PON:173712524INR0001 25: Date: 2/9/2015 PON:173710904DID0001 26: Date: 2/9/2015 PON:173717004INN0001 27: Date: 2/9/2015 PON:173712871INN0001 28: Date: 2/9/2015 PON:173426776RGN0001 29: Date: 2/9/2015 PON:173418924RGN0001 30: Date: 2/9/2015 PON:173712465INR0001 31: Date: 2/9/2015 PON:173712465INR0002 32: Date: 2/9/2015 PON:173712524INR0002 33: Date: 2/9/2015 PON:173710788INR0001 34: Date: 2/9/2015 PON:173710788INR0002 35: Date: 2/9/2015 PON:173712737DID0001 36: Date: 2/9/2015 PON:173717129INN0001 37: Date: 2/9/2015 PON:173718061DID0001 38: Date: 2/9/2015 PON:173717663INN0001 39: Date: 2/9/2015 PON:173718181DID0001 40: Date: 2/9/2015 PON:173714071DID0001 41: Date: 2/9/2015 PON:173692375INN0002 42: Date: 173692375INN0002