Server/Actions/ActionCecUserControlPressed.cs
author StephaneLenclud
Wed, 27 Jul 2016 15:05:58 +0200
changeset 223 f6272f65d8fc
parent 222 0e8c6c2f4777
child 228 6a84d8282226
permissions -rw-r--r--
Adding action move and test buttons.
     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     [AttributeAction(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         [AttributeActionProperty(
    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         [AttributeActionProperty(
    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         public 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 }