add media commands and keycommand

#21-media-commands
sleevezipper 4 years ago
parent 086c10d126
commit f6d184fa2f

@ -190,6 +190,21 @@ This command allows you to run any Windows Commands. The command will be run in
|shutdown /s /t 300|Shuts the PC down after 5 minutes (300 seconds).| |shutdown /s /t 300|Shuts the PC down after 5 minutes (300 seconds).|
|C:\path\to\your\batchfile.bat|Run the specified batch file.| |C:\path\to\your\batchfile.bat|Run the specified batch file.|
### KeyCommand
Sends a keystroke with the specified key. You can pick [any of these](https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) key codes.
### Media Commands
There's several media commands available which are very self exlanatory.
- Play/Pause
- Next
- Previous
- Volume up
- Volume down
- Mute (toggle)
## Credits ## Credits
This project depends on work done by others and they should at least get a mention. Please note that this list is not complete yet. This project depends on work done by others and they should at least get a mention. Please note that this list is not complete yet.

@ -13,9 +13,11 @@ namespace UserInterface.ViewModels
public string Description { get => description; set => this.RaiseAndSetIfChanged(ref description, value); } public string Description { get => description; set => this.RaiseAndSetIfChanged(ref description, value); }
public bool ShowCommandInput { get => showCommandInput; set => this.RaiseAndSetIfChanged(ref showCommandInput, value); } public bool ShowCommandInput { get => showCommandInput; set => this.RaiseAndSetIfChanged(ref showCommandInput, value); }
public bool ShowKeyInput { get => showKeyInput; set => this.RaiseAndSetIfChanged(ref showKeyInput, value); }
private string moreInfoLink; private string moreInfoLink;
private bool showCommandInput; private bool showCommandInput;
private bool showKeyInput;
public string MoreInfoLink public string MoreInfoLink
{ {
@ -27,5 +29,6 @@ namespace UserInterface.ViewModels
public string Name { get; set; } public string Name { get; set; }
public string Command { get; set; } public string Command { get; set; }
public string Key { get; set; }
} }
} }

@ -20,6 +20,8 @@
<TextBlock Text="{Binding UpdateInterval, StringFormat= Update every {0} seconds}" HorizontalAlignment="Left" MinWidth="150"/> <TextBlock Text="{Binding UpdateInterval, StringFormat= Update every {0} seconds}" HorizontalAlignment="Left" MinWidth="150"/>
<ContentControl IsVisible="{Binding ShowCommandInput}" Margin="0 20 0 10">Command</ContentControl> <ContentControl IsVisible="{Binding ShowCommandInput}" Margin="0 20 0 10">Command</ContentControl>
<TextBox IsVisible="{Binding ShowCommandInput}" Text="{Binding Command}" Watermark="Rundll32.exe user32.dll,LockWorkStation" HorizontalAlignment="Left" MinWidth="300"/> <TextBox IsVisible="{Binding ShowCommandInput}" Text="{Binding Command}" Watermark="Rundll32.exe user32.dll,LockWorkStation" HorizontalAlignment="Left" MinWidth="300"/>
<ContentControl IsVisible="{Binding ShowKeyInput}" Margin="0 20 0 10">Key</ContentControl>
<TextBox IsVisible="{Binding ShowKeyInput}" Text="{Binding Key}" Watermark="0xAD" HorizontalAlignment="Left" MinWidth="300"/>
<Button IsVisible="{Binding ShowCommandInput}" Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Test">Test</Button> <Button IsVisible="{Binding ShowCommandInput}" Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Test">Test</Button>
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Save">Save</Button> <Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Save">Save</Button>
</StackPanel> </StackPanel>

@ -47,7 +47,7 @@ namespace UserInterface.Views
public async void Save(object sender, RoutedEventArgs args) public async void Save(object sender, RoutedEventArgs args)
{ {
var item = ((AddCommandViewModel)this.DataContext); var item = ((AddCommandViewModel)this.DataContext);
dynamic model = new { item.Name, item.Command}; dynamic model = new { item.Name, item.Command, item.Key};
string json = JsonSerializer.Serialize(model); string json = JsonSerializer.Serialize(model);
await this.client.InvokeAsync(x => x.AddCommand(item.SelectedType, json)); await this.client.InvokeAsync(x => x.AddCommand(item.SelectedType, json));
Close(); Close();
@ -62,46 +62,73 @@ namespace UserInterface.Views
item.Description = "This command lets you execute any command you want. It will run in a Windows Command Prompt silently. "; item.Description = "This command lets you execute any command you want. It will run in a Windows Command Prompt silently. ";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#customcommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#customcommand";
item.ShowCommandInput = true; item.ShowCommandInput = true;
item.ShowKeyInput = false;
break; break;
case AvailableCommands.ShutdownCommand: case AvailableCommands.ShutdownCommand:
item.Description = "This command shuts down the PC immediately. "; item.Description = "This command shuts down the PC immediately. ";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#shutdowncommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#shutdowncommand";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
case AvailableCommands.RestartCommand: case AvailableCommands.RestartCommand:
item.Description = "This command restarts the PC immediately. "; item.Description = "This command restarts the PC immediately. ";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#restartcommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#restartcommand";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
case AvailableCommands.LogOffCommand: case AvailableCommands.LogOffCommand:
item.Description = "This command logs the current user off immediately. "; item.Description = "This command logs the current user off immediately. ";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#logoffcommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#logoffcommand";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
case AvailableCommands.KeyCommand: case AvailableCommands.KeyCommand:
item.Description = "This commands can be used to send emulate a keystroke."; item.Description = "This command can be used to emulate a keystroke. It requires a key code which you can find by clicking the info button below.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#keycommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#keycommand";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = true;
break; break;
case AvailableCommands.PlayPauseCommand: case AvailableCommands.PlayPauseCommand:
item.Description = "This command plays or pauses currently playing media."; item.Description = "This command plays or pauses currently playing media.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#playpausecommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
case AvailableCommands.NextCommand: case AvailableCommands.NextCommand:
item.Description = "This command skips to the next media."; item.Description = "This command skips to the next media.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#nextcommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
case AvailableCommands.PreviousCommand: case AvailableCommands.PreviousCommand:
item.Description = "This command plays previous media."; item.Description = "This command plays previous media.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#previouscommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands";
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break;
case AvailableCommands.VolumeDownCommand:
item.Description = "Lowers the system volume.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands";
item.ShowCommandInput = false;
item.ShowKeyInput = false;
break;
case AvailableCommands.VolumeUpCommand:
item.Description = "Raises the system volume.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands";
item.ShowCommandInput = false;
item.ShowKeyInput = false;
break;
case AvailableCommands.MuteCommand:
item.Description = "Toggles muting the system volume.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#media-commands";
item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
default: default:
item.Description = null; item.Description = null;
item.MoreInfoLink = null; item.MoreInfoLink = null;
item.ShowCommandInput = false; item.ShowCommandInput = false;
item.ShowKeyInput = false;
break; break;
} }
} }

@ -197,8 +197,17 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
case AvailableCommands.PreviousCommand: case AvailableCommands.PreviousCommand:
commandToCreate = new MediaPreviousCommand(this._publisher, model.Name); commandToCreate = new MediaPreviousCommand(this._publisher, model.Name);
break; break;
case AvailableCommands.VolumeUpCommand:
commandToCreate = new MediaVolumeUpCommand(this._publisher, model.Name);
break;
case AvailableCommands.VolumeDownCommand:
commandToCreate = new MediaVolumeDownCommand(this._publisher, model.Name);
break;
case AvailableCommands.MuteCommand:
commandToCreate = new MediaMuteCommand(this._publisher, model.Name);
break;
case AvailableCommands.KeyCommand: case AvailableCommands.KeyCommand:
commandToCreate = new KeyCommand(this._publisher, (byte)model.KeyCode, model.Name); commandToCreate = new KeyCommand(this._publisher, Convert.ToByte(model.Key, 16), model.Name);
break; break;
default: default:
Log.Logger.Error("Unknown sensortype"); Log.Logger.Error("Unknown sensortype");

@ -63,6 +63,9 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
KeyCommand, KeyCommand,
PlayPauseCommand, PlayPauseCommand,
NextCommand, NextCommand,
PreviousCommand PreviousCommand,
VolumeUpCommand,
VolumeDownCommand,
MuteCommand
} }
} }

@ -183,6 +183,15 @@ namespace hass_workstation_service.Data
case "MediaPreviousCommand": case "MediaPreviousCommand":
command = new MediaPreviousCommand(publisher, configuredCommand.Name, configuredCommand.Id); command = new MediaPreviousCommand(publisher, configuredCommand.Name, configuredCommand.Id);
break; break;
case "MediaVolumeUpCommand":
command = new MediaVolumeUpCommand(publisher, configuredCommand.Name, configuredCommand.Id);
break;
case "MediaVolumeDownCommand":
command = new MediaVolumeDownCommand(publisher, configuredCommand.Name, configuredCommand.Id);
break;
case "MediaMuteCommand":
command = new MediaMuteCommand(publisher, configuredCommand.Name, configuredCommand.Id);
break;
case "KeyCommand": case "KeyCommand":
command = new KeyCommand(publisher, configuredCommand.KeyCode, configuredCommand.Name, configuredCommand.Id); command = new KeyCommand(publisher, configuredCommand.KeyCode, configuredCommand.Name, configuredCommand.Id);
break; break;

@ -15,6 +15,9 @@ namespace hass_workstation_service.Domain.Commands
public const int VK_MEDIA_NEXT_TRACK = 0xB0; public const int VK_MEDIA_NEXT_TRACK = 0xB0;
public const int VK_MEDIA_PLAY_PAUSE = 0xB3; public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
public const int VK_MEDIA_PREV_TRACK = 0xB1; public const int VK_MEDIA_PREV_TRACK = 0xB1;
public const int VK_VOLUME_MUTE = 0xAD;
public const int VK_VOLUME_UP = 0xAF;
public const int VK_VOLUME_DOWN = 0xAE;
public byte KeyCode { get; protected set; } public byte KeyCode { get; protected set; }

@ -0,0 +1,14 @@
using hass_workstation_service.Communication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hass_workstation_service.Domain.Commands
{
public class MediaMuteCommand : KeyCommand
{
public MediaMuteCommand(MqttPublisher publisher, string name = "Mute", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_VOLUME_MUTE, name ?? "Mute", id) { }
}
}

@ -0,0 +1,14 @@
using hass_workstation_service.Communication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hass_workstation_service.Domain.Commands
{
public class MediaVolumeDownCommand : KeyCommand
{
public MediaVolumeDownCommand(MqttPublisher publisher, string name = "VolumeDown", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_VOLUME_DOWN, name ?? "VolumeDown", id) { }
}
}

@ -0,0 +1,14 @@
using hass_workstation_service.Communication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hass_workstation_service.Domain.Commands
{
public class MediaVolumeUpCommand : KeyCommand
{
public MediaVolumeUpCommand(MqttPublisher publisher, string name = "VolumeUp", Guid id = default(Guid)) : base(publisher, KeyCommand.VK_VOLUME_UP, name ?? "VolumeUp", id) { }
}
}
Loading…
Cancel
Save