Server/Actions/ActionCecUserControlPressed.cs
author StephaneLenclud
Fri, 19 Aug 2016 19:28:03 +0200
changeset 245 448e6a616c22
parent 228 6a84d8282226
child 253 2dae7a163fff
permissions -rw-r--r--
Removing Input tab as we don't need to specific features anymore.
     1 using CecSharp;
     2 using SharpLib.Ear;
     3 using System;
     4 using System.Collections.Generic;
     5 using System.Linq;
     6 using System.Runtime.InteropServices;
     7 using System.Runtime.Serialization;
     8 using System.Text;
     9 using System.Threading.Tasks;
    10 
    11 namespace SharpDisplayManager
    12 {
    13     /// <summary>
    14     /// Send a user key press event to the given CEC device.
    15     /// </summary>
    16     [DataContract]
    17     [AttributeObject(Id = "Cec.UserControlPressed", Name = "CEC User Control Pressed", Description = "Send user control code to defined CEC device.")]
    18     public class ActionCecUserControlPressed : ActionCecDevice
    19     {
    20 
    21         public ActionCecUserControlPressed()
    22         {
    23             Wait = true;
    24         }
    25 
    26         [DataMember]
    27         [AttributeObjectProperty(
    28         Id = "Cec.UserControlPressed.Code",
    29         Name = "Code",
    30         Description = "The key code used by this action."
    31         )]
    32         public CecUserControlCode Code { get; set; }
    33 
    34         [DataMember]
    35         [AttributeObjectProperty(
    36         Id = "Cec.UserControlPressed.Wait",
    37         Name = "Wait",
    38         Description = "Wait for that command."
    39         )]
    40         public bool Wait { get; set; }
    41 
    42         /// <summary>
    43         /// 
    44         /// </summary>
    45         /// <returns></returns>
    46         public override string Brief()
    47         {
    48             string brief = Name + ": " + Code.ToString() + " to " + DeviceName;
    49             if (Wait)
    50             {
    51                 brief += " (wait)";
    52             }
    53             return brief;
    54         }
    55 
    56         /// <summary>
    57         /// 
    58         /// </summary>
    59         protected override void DoExecute()
    60         {
    61             if (Cec.Client.Static == null)
    62             {
    63                 Console.WriteLine("WARNING: No CEC client installed.");
    64                 return;
    65             }
    66 
    67             Cec.Client.Static.Lib.SendKeypress(Device, Code, Wait);
    68         }
    69     }
    70 }