Scripting AppActivate

How can be this controlled in that simulator? Can HIDmacros be used with this application?
Post Reply
ttocsic
Posts: 3
Joined: 04 Nov 2019, 18:30

Scripting AppActivate

Post by ttocsic » 07 Nov 2019, 16:16

Hello. Thanks for this great piece of software.
I'm a little new to scripting but i'm a power google user so bear with me.
I'm attempting to create a macro that switches windows to Spotify and sends the space bar which should pause/play. Spotify doesn't support global hotkeys so the window must be in focus.

I attempted the following:

Code: Select all

Dim wsh
Set wsh = CreateObject("Wscript.Shell")
wsh.AppActivate "Spotify"
SendKeys " "
I tested this upon first opening Spotify and it worked fine.
The problem is when Spotify starts playing something, the window title (as per script tools) changes to the artist and song, even though windows task manager lists the process as "Spotify".

Is there a way i can call the process name instead of the window title?

admin
Site Admin
Posts: 620
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Scripting AppActivate

Post by admin » 07 Nov 2019, 23:33

I'm not aware of such way. But I don't consider myself as windows scripting expert :-)
Petr Medek
LUAmacros author

ttocsic
Posts: 3
Joined: 04 Nov 2019, 18:30

Re: Scripting AppActivate

Post by ttocsic » 08 Nov 2019, 15:34

I made a little workaround by pinning spotify in the 3rd position on the task bar. Windows lets you activate task bar items with windows key and the position number (i.e. #3).
So my new script reads:

Code: Select all

sendkeys "#3"
sleep (200)
sendkeys " "
Except now I've learned about the (already documented) Sleep bug. It seems as though the script runs the sleep before any of the other commands.
I know you have no intentions of fixing this bug but is there any script I can use as a workaround to insert a delay between keys?

ttocsic
Posts: 3
Joined: 04 Nov 2019, 18:30

Re: Scripting AppActivate

Post by ttocsic » 08 Nov 2019, 22:05

FOUND IT!!
viewtopic.php?f=5&t=28

my new script is

Code: Select all

hidmacros.sendkeysslow "#3 ", 200 
works consistently so far. The only glitch is if the window is already in focus, #3 will toggle it to the background.
Will do more experimenting with the appactivate method.

Post Reply