Sign in to follow this  
Followers 0
konamer

Problem with ControlSend

9 posts in this topic

Hey Guys,

I have created a Script for Spotify which is almost working:

AutoItSetOption("MouseCoordMode", 0)
Opt("SendKeyDownDelay", 800)
_mouseclickplus( "Spotify", "left", 30, 400, 1 )
Sleep(200)
_mouseclickplus( "Spotify", "left", 468, 120, 1 )
Sleep(300)
ControlClick("Spotify","","Chrome_RenderWidgetHostHWND4","left", 5, 253, 573)
Sleep(300)
_mouseclickplus( "Spotify", "left", 17, 40, 1 )
Sleep(300)
_mouseclickplus( "Spotify", "left", 17, 40, 1 )
Sleep(600)
ControlSend("Spotify", "", "", "{ENTER}")
 
 
;===============================================================================
;
; Function Name:  _MouseClickPlus()
; Version added:  0.1
; Description:    Sends a click to window, not entirely accurate, but works
;                 minimized.
; Parameter(s):   $Window     =  Title of the window to send click to
;                 $Button     =  "left" or "right" mouse button
;                 $X          =  X coordinate
;                 $Y          =  Y coordinate
;                 $Clicks     =  Number of clicks to send
; Remarks:        You MUST be in "MouseCoordMode" 0 to use this without bugs.
; Author(s):      Insolence <insolence_9@yahoo.com>
;
;===============================================================================
Func _MouseClickPlus($Window, $Button = "left", $x = "", $y = "", $Clicks = 1)
Local $MK_LBUTTON = 0x0001
Local $WM_LBUTTONDOWN = 0x0201
Local $WM_LBUTTONUP = 0x0202
Local $MK_RBUTTON = 0x0002
Local $WM_RBUTTONDOWN = 0x0204
Local $WM_RBUTTONUP = 0x0205
Local $WM_MOUSEMOVE = 0x0200
Local $i = 0
Select
Case $Button = "left"
$Button = $MK_LBUTTON
$ButtonDown = $WM_LBUTTONDOWN
$ButtonUp = $WM_LBUTTONUP
Case $Button = "right"
$Button = $MK_RBUTTON
$ButtonDown = $WM_RBUTTONDOWN
$ButtonUp = $WM_RBUTTONUP
EndSelect
If $x = "" Or $y = "" Then
$MouseCoord = MouseGetPos()
$x = $MouseCoord[0]
$y = $MouseCoord[1]
EndIf
For $i = 1 To $Clicks
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", WinGetHandle($Window), _
"int", $WM_MOUSEMOVE, _
"int", 0, _
"long", _MakeLong($x, $y))
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", WinGetHandle($Window), _
"int", $ButtonDown, _
"int", $Button, _
"long", _MakeLong($x, $y))
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", WinGetHandle($Window), _
"int", $ButtonUp, _
"int", $Button, _
"long", _MakeLong($x, $y))
Next
EndFunc   ;==>_MouseClickPlus
Func _MakeLong($LoWord, $HiWord)
Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong
 
But the Controle Send /ControlSend("Spotify", "", "", "{ENTER}")/ is not working if spotify is minimized. When Spotify is on top the Script is working fine. 
Do you know whats the problem?

Share this post


Link to post
Share on other sites



Try ControlFocus on the control you want to send on before ControlSend


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.

Share this post


Link to post
Share on other sites

I tried it but it`s still the same result. It only works when Spotify is on top.

Share this post


Link to post
Share on other sites

for the title param in ControlSend use the class instead of the title, you can find that with the AutoIt info tool, I have had problems using titles in applications such as teamviewer.


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

I tried this also. But its still not working. Is there any other command then ControlSend to do it?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You can always try ControlClick (if you're clicking the enter button), but some controls will resist clicking unless they are the active window.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

The Problem is that the Coordinates always change. ENTER is the only way to do what i want. With Windactive it works well. But i want to use the script when i am playing some games so Spotify cant be on top. 

Share this post


Link to post
Share on other sites

Yes, I know that is why I put the remark in my post (ControlClick doens't have to use x and y just FYI), otherwise that is really all I can think of, other than having a script that looks for a hotkey to open it and send it "enter" and then minimize it.

Good luck though and happy holidays!


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Probably this can help you further if you search on google

Spotify has a process running called SpotifyWebHelper.exe on port 4380 which is normally used for the play buttons on Facebook and the embed players. Most people don't know this but there's a real API running on that port, Providing several functions that can be used in several types of responses including JSON and XML. They've added several methods to make sure that stuff only gets ran from the webbrowsers such as Origin and Referer headers checking and OAuth keys, but both are really easy to bypass. (you won't have to worry about this)

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
Sign in to follow this  
Followers 0