Trigger a hotkey from the vbs script

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Trigger a hotkey from the vbs script

Post by Erwin Hanzl »

Hello experts,

What EXACT command structure can I use to trigger a HotKey.
I would be grateful to you for a helpful answer.
Thanks

Code: Select all

Sub PlayNext
  on error resume next
  If (SDB.Player.isPlaying) And (Not SDB.Player.isStartingPlayback) Then
	SDB.Player.Next
	'The following song is played and should be marked at the same time.
	SendKeys {F8}   ' ?????????????????????
  End if
End Sub
MMW 4.1.31.1919 Gold-Standardinstallation
Peke
Posts: 17851
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Trigger a hotkey from the vbs script

Post by Peke »

Hi,
Before I go into more details can you please explain what would be the end result?

eg. Send key to other app, invoke action in MM, send keyboard event?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Trigger a hotkey from the vbs script

Post by Erwin Hanzl »

Hello Peke,

Thank you for your efforts.

invoke action in MM and send keyboard event

I have a playlist of songs that have never been played.
1. I double-click the first song and listen to it.
2. If I like the song, I trigger this script and the next song plays - but it has no focus.
3. Now I decide: delete the current song? YES
Not possible because the current song has no focus yet.

I have the HOTKEY for the F8 key:
"General: Focus tracklist on currently playing item" assigned.
Last edited by Erwin Hanzl on Mon Jan 18, 2021 2:48 am, edited 1 time in total.
MMW 4.1.31.1919 Gold-Standardinstallation
Peke
Posts: 17851
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Trigger a hotkey from the vbs script

Post by Peke »

Hi,
I guess it would be the best to have two scripts eg. one for like and one for dislike/delete. As soon as you hear tracks is to assigned global variable and you can control it with script no focus needed.

You can use that info to show on screen if you also want to check before you decide and switch to next track.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Trigger a hotkey from the vbs script

Post by Erwin Hanzl »

Hello Pavle,
Thanks for your answer - but I can't do anything with it.

It is very simple:
Set F8 key: "General: Focus tracklist on currently playing item" assigned.

Code: Select all

Sub PlayNext
  'on error resume next
  If (SDB.Player.isPlaying) And (Not SDB.Player.isStartingPlayback) Then
	SDB.Player.Next

	Dim a
	Set a = CreateObject("WScript.Shell")
	a.SendKeys "{F8}"
   End if
End Sub
And finally, I assign a hot key to this script.
Tools> Options> General ... HOTKEYS
"General: Execut script: PlayNext"
MMW 4.1.31.1919 Gold-Standardinstallation
Peke
Posts: 17851
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Trigger a hotkey from the vbs script

Post by Peke »

Hi,
Hmmm, that still do not explain why you need focus on Current track when you can just ignore it and use additional script with command to delete track if you do not like it and select next track or use your existing Script to Like track and go to next.

Other approach would be to register On play Event and focus on current playing track. eg. something like this.

Code: Select all

Script.RegisterEvent SDB, "OnPlay", "SDB_OnTrackPlay" 

Dim InEventHandler : InEventHandler = False ' Control variable (shows if event handler is executing)

Sub SDB_OnTrackPlay(TrackList) 
    If InEventHandler Then Exit Sub         ' Prevent executing event handler from within itself
    InEventHandler = True                   ' Event starts --> set control variable

	Dim a
	Set a = CreateObject("WScript.Shell")
	a.SendKeys "{F8}"
End Sub
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Trigger a hotkey from the vbs script

Post by Erwin Hanzl »

Hello Pavle,

thank you for your solution, but why a second script to delete?
With my solution, I only need to press the 'Del' key and I'm on the safe side.

Thank you for the Error-Handler
Best regards, Erwin
MMW 4.1.31.1919 Gold-Standardinstallation
Peke
Posts: 17851
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Trigger a hotkey from the vbs script

Post by Peke »

Hi,
Two scripts because to eliminate need for executing Focus and have direct shortcut to delete track and move to next.

re Error-Handler: My pleasure, it was good to see I am not senile ;)
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Post Reply