I wanted soundtap to keep recording after a song was done playing on YouTube so thus AutoRecord tool was made
program autorec; (* This code is very simple. It enumerates all window handles to find the button with classname "Button" and window text "Start Recording" if it doesnt find it at the first attempt it will open soundtap and try again. After all of that it looks to see if the window text not equals "Stop Recording" once that is true it will send a BM_CLICK message to that button and then repeats that process until the button handle is no longer valid. *) {$apptype console} {$Resource autorec-data.res} uses SysUtils,messages, windows,shellapi; var RecordBTN:hwnd; seError:hinst; rs:dword; recordcap:array[0..255]of char; hk:hkey; soundtap_exe:array[0..max_path]of char; function findbutton(hw:hwnd;lp:lparam):bool;stdcall; var classn,wndtext:array[0..255]of char; begin result:=true; getclassname(hw,classn,255); getwindowtext(hw,wndtext,255); if(comparetext(wndtext,'Start Recording')=0)and(comparetext(classn,'Button')=0) then begin recordbtn:=hw;result:=false;exit;end; //enumchildwindows(hw,@findbutton,1); end; procedure buttonClicked(hw:hwnd;umsg:uint;dwdata:dword;lresult:lresult);stdcall; asm nop end; begin recordbtn:=getdesktopwindow; writeln('delphijustin Autorecord for soundtap v1.0'); writeln('Not created by NCH Software'); writeln('Searching for record button...'); enumchildwindows(getdesktopwindow,@findbutton,0); if recordbtn=getdesktopwindow then begin //if first attept fails try launching SoundTap regopenkeyex(HKEY_LOCAL_MACHINE,'SOFTWARE\NCH Software\SoundTap\Settings',0, key_read,hk);//Open soundtap registry key and query install path rs:=sizeof(soundtap_exe); if regqueryvalueex(hk,'InstallerPath',nil,nil,@soundtap_exe,@rs)<>error_success then begin writeln('Could not find SoundTap');regclosekey(hk);exitprocess(1); end;//end if regqueryvalueex regclosekey(hk);seError:=shellexecute(0,nil,strcat(soundtap_exe,'\soundtap.exe'), nil,nil,sw_shownormal);if seerror<33then begin writeln(soundtap_exe,':', syserrormessage(seerror));exitprocess(1);end;//end if seerror sleep(10000); //give about 10 seconds for soundtap to finsh loading enumchildwindows(getdesktopwindow,@findbutton,0);//attempt to find the button one last time if recordbtn=getdesktopwindow then begin writeln('Cannot find the record button'); exitprocess(1); end;//end if second attempt end;//end if first attempt writeln('Button found. Handle is 0x',inttohex(recordbtn,0)); while iswindow(recordbtn)do begin//check window text until the button is no longer valid sleep(5000); getwindowtext(recordbtn,recordcap,255); if comparetext('Stop Recording',recordcap)<>0then sendmessagecallback(recordbtn,bm_click,0,0,@buttonclicked,0); //so far SendMessageCallback is the only method end; writeln('Button handle no longer valid'); end.