Request for very simple script.

tarxsix

n00b
Joined
Dec 18, 2010
Messages
23
Hi, Sorry to bother you with this but I know very little about scripting.
I'm looking for a file that I could run that would select a already running WinAmp and press 'c' (the pause button).
I'm running Windows 10 Pro.

I've been trying to look up on how to do this but cant put it together in my head. Can anyone help?

Regards,
Tar.
 

JVene

n00b
Joined
Apr 25, 2019
Messages
21
A lot depends upon what language you're willing to use. "Script" is not well defined as to what tools you can use.

The basic notion is to obtain a handle to the desktop (the parent to all top level windows), loop through all that exist looking for the winamp name (probably part of the title), then sending a message to that app for the keystroke for the 'c'.

I think C# and VB can do this (I don't use either much), but it is certainly possible in C/C++ (not exactly for a novice, though).
 

tarxsix

n00b
Joined
Dec 18, 2010
Messages
23
A lot depends upon what language you're willing to use. "Script" is not well defined as to what tools you can use.

The basic notion is to obtain a handle to the desktop (the parent to all top level windows), loop through all that exist looking for the winamp name (probably part of the title), then sending a message to that app for the keystroke for the 'c'.

I think C# and VB can do this (I don't use either much), but it is certainly possible in C/C++ (not exactly for a novice, though).
Thank for the reply! I guess I would like to use something free? Would I need to install something? Honestly I thought I would just need to enter some text into notepad and save it as a bat file? Or do you mean the language that I would be using in notepad?
 

tarxsix

n00b
Joined
Dec 18, 2010
Messages
23
Sure.. powershell can do something like that.
https://stackoverflow.com/questions/17849522/how-to-perform-keystroke-inside-powershell

C# can, but you would need to install an IDE like visual studios to compile the app.
https://stackoverflow.com/questions/523405/how-to-send-text-to-notepad-in-c-win32
Thanks! Using PowerShell I tried creating the script and it opened WinAmp the first time but did not the 2nd as the window name changes with every song. So I tried the following:

$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('* Winamp *')
Sleep 1
$wshell.SendKeys('c')


But that did not work also. Any suggestions?
Also to run the ps1 file I have to right click and 'run with powershell'. Can I save it as a executable?
 

ryan_975

[H]F Junkie
Joined
Feb 6, 2006
Messages
14,865
Try something like this ( haven't tested it ):

$proc = get-process winamp
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate($proc.MainWindowTitle)
Sleep 1
$wshell.SendKeys('c')
 
  • Like
Reactions: xx0xx
like this

tarxsix

n00b
Joined
Dec 18, 2010
Messages
23
Try something like this ( haven't tested it ):

$proc = get-process winamp
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate($proc.MainWindowTitle)
Sleep 1
$wshell.SendKeys('c')

It's working! Thanks so much! And everyone else!
 

t4keheart

Weaksauce
Joined
Sep 24, 2019
Messages
109
Just wanted to suggest, learn a little python. I'm a sys admin by trade but focus almost all of my efforts on developing python modules to automate everything. Python is super simple once you get a grip on it and has so many standard libraries for just about anything you want to do... had somebody not done this in powershell first, I was going to whip something up which would have taken probably 2 minutes!
 
Top