Func Terminate ( ) ; Script off function as it works in an infinite loop
Exit 0
Endfunc
HotKeySet ( "{ESC}" , "Terminate" ) ; Binds off function to ESC key
FileChangeDir ( "C: Program FilesQIPUsersXXXXXXXXXXHistory" ) ; Changes the working directory
while 1 ; Starts endless script loop
$ Search = FileFindFirstFile ( "* .txt" ) ; It searches for txt files in the working directory and returns the search value to the $ Search variable
if $ Search = - 1 then ; Checks the presence of files on the contents of the variable
Sleep ( 1000 ) ; If no files are found, wait a second and start the cycle again.
else ; If txt file is found, then ...
$ File = FileFindNextFile ( $ Search ) ; Enter file name into $ File
$ Log = FileRead ( $ File ) ; Filing file contents into $ log variable
$ Log = StringSplit ( $ Log , @LF ) ; Since in QIP one message consists of three lines (marking the message as incoming or outgoing, author’s name / date / time of sending the message and the message itself), it makes an array of variables in which each element is equal to one line
$ Mess = $ log [ 3 ] ; The message itself enters the $ Mess variable
FileDelete ( $ File ) ; Deletes history file
MsgBox ( "0" , "" , $ Mess , 1 ) ; For a second, it displays a message with a command that the script will now execute - this is implemented for debugging
WinActivate ( '[REGEXPCLASS :(? I) {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}]' ) ; It makes the Foobar window active, implemented by referring to the class, since the title of the player changes depending on the composition being played.
WinWaitActive ( '[REGEXPCLASS :(? I) {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1]]' ) ; Waiting for Foobar window to become active.
$ Check = StringInStr ( $ Mess , "local" ) ; Checks the entry of the word "local" in the message text
if $ Check = 1 then ; If "local" is at the beginning of the message, then ...
$ Mess = StringTrimLeft ( $ Mess , 6 ) ; "Cuts off" the first 6 characters in the message (the word local followed by a space)
Send ( "^ f" ) ; Send CTRL + F keystroke
WinWaitActive ( '[REGEXPCLASS :(? I) {483DF8E3-09E3-40d2-BEB8-67284CE3559F}]]' ) ; We are waiting for the track search window to open.
Send ( $ mess ) ; Enters the request message content
Sleep ( 500 ) ; Waiting half a second
Send ( "{TAB}" ) ; Sends TAB keystroke
Sleep ( 500 ) ; Waiting for
Send ( "{TAB}" ) ; Sends keystroke TAB (makes an active element of the window in which the search result is displayed)
Sleep ( 500 ) ; Waiting for
Send ( "{DOWN}" ) ; Sends the DOWN keystroke (the first track found by the search is highlighted)
Sleep ( 500 ) ; Waiting for
Send ( "{ENTER}" ) ; Includes found track
Sleep ( 500 ) ; Waiting for
WinClose ( '[REGEXPCLASS :(? I) {483DF8E3-09E3-40d2-BEB8-67284CE3559F}]]' ) ; Close the search box
continueloop ; Returns to the beginning of the loopless while loop
endif ; If the word "local" is not at the beginning of the message, then the script continues reading from here ...
$ Stop = StringRegExp ( $ Mess , "stop" ) ; ... looking for the entry of the word "stop" in the message
$ VolUp = StringRegExp ( $ Mess , "louder" ) ; Looks for the entry of the word "louder" in the message
$ VolDown = StringRegExp ( $ Mess , "quieter" ) ; Looks for the entry of the word "quieter" in the message
$ VolMax = StringRegExp ( $ Mess , "loud" ) ; Looks for the entry of the word "loud" in the message
$ VolMin = StringRegExp ( $ Mess , "quiet" ) ; Looks for the word "quiet" in the message
if $ Stop = 1 then ; If the word "stop" is sent, then ..
Send ( "! X" ) ; ... send ALT + X, which pauses / continues playback
continueloop ; Returns to the beginning of the loopless while loop
endif
if $ VolUp = 1 then ; If the word "louder" is sent, then ...
Send ( "! {UP}" ) ; ...
Send ( "! {UP}" ) ; ...
Send ( "! {UP}" ) ; ...
Send ( "! {UP}" ) ; ...
Send ( "! {UP}" ) ; Press the ALT + UP key combination 5 times, which slightly increases the volume
continueloop ; Returns to the beginning of the loopless while loop
endif
if $ VolDown = 1 then ; If the word "louder" is sent, then ...
Send ( "! {DOWN}" ) ; ...
Send ( "! {DOWN}" ) ; ...
Send ( "! {DOWN}" ) ; ...
Send ( "! {DOWN}" ) ; ...
Send ( "! {DOWN}" ) ; Press the ALT + DOWN key combination 5 times, which slightly decreases the volume
continueloop ; Returns to the beginning of the loopless while loop
endif
if $ VolMax = 1 then ; If the word "loud" is sent, then ...
Send ( "! C" ) ; ... send the shortcut key ALT + C, which turns on the maximum volume
continueloop ; Returns to the beginning of the loopless while loop
endif
if $ VolMin = 1 then ; If the word "silent" is sent, then ...
Send ( "! Z" ) ; ... will send the key combination ALT + Z, which turns on the minimum volume (does not turn it off at all)
continueloop ; Returns to the beginning of the loopless while loop
endif
; If not one of the standing ups did not work, then ...
Send ( "^ q" ) ; Sends the CTRL + Q key combination, which is responsible for opening the Foobar plugin window, which searches for music on VKontakte
WinWaitActive ( "vk.com audio Search" ) ; Waiting until the plugin window is active.
ControlCommand ( "vk.com audio Search" , "" , "ComboBox1" , "SetCurrentSelection" , 6 ) ; From the drop-down list "What services to search for" selects vk.com (VKontakte)
Sleep ( 500 ) ; Waiting half a second
ControlFocus ( "vk.com audio Search" , "" , "Edit1" ) ; Makes the query input line active.
Sleep ( 500 ) ; Waiting for
Send ( $ mess ) ; Sends the contents of the message from QIP to the input line
Sleep ( 5000 ) ; Wait 5 seconds while the plugin is looking for a track
while 1 ; I do not know how else to implement what will happen next, except with the use of an infinite loop
$ i = ControlListView ( "vk.com audio Search" , "" , "SysListView321" , "GetItemCount" ) ; Pushes the number of tracks found into the variable $ i
if $ i = 0 then ; If no tracks are found (the plugin sometimes does not find results from the first time)
ControlClick ( "vk.com audio Search" , "" , "Button1" ) ; Clicks on the "Stop Search" button
Sleep ( 500 ) ; Waiting for
ControlClick ( "vk.com audio Search" , "" , "Button1" ) ; Click on the "Search" button
Sleep ( 5000 ) ; Waiting for
exitloop ; Exits from the inner infinite while loop (from the second time it always finds)
else
exitloop ; If you did not find it the first time, then, most likely, the name of the track was entered incorrectly and the script also leaves the internal while loop
endif
wend
ControlListView ( "vk.com audio Search" , "" , "SysListView321" , "Select" , 1 ) ; Selects the second track from the search result (the first one is often for some reason 00:00 and does not play)
ControlClick ( "vk.com audio Search" , "" , "Button3" ) ; Adds a second track to the playlist.
WinClose ( "vk.com audio Search" ) ; Closes the plugin window
WinWaitActive ( '[REGEXPCLASS :(? I) {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1]]' ) ; Waiting for Foobar window to become active.
Sleep ( 500 ) ; Waiting half a second
Send ( "{END}" ) ; Sends
Sleep ( 500 ) ; Waiting for
Send ( "{ENTER}" ) ; Sends keystroke ENTER, which includes the track
endif
wend ; Returns to the beginning of the loopless loop
Source: https://habr.com/ru/post/145550/
All Articles