OpenInput() public method

Opens the current input desktop.
public OpenInput ( ) : bool
return bool
Example #1
0
 private static void WatchDesktop()
 {
     while (true)
     {
         try
         {
             using (var inputDesktop = new Desktop())
             {
                 inputDesktop.OpenInput();
                 if (!inputDesktop.DesktopName.Equals(_lastDesktop))
                 {
                     if (inputDesktop.Show() && Desktop.SetCurrent(inputDesktop))
                     {
                         Console.WriteLine($"Desktop switched from {_lastDesktop} to {inputDesktop.DesktopName} on thread {Desktop.GetCurrentThreadId()}");
                         _lastDesktop      = inputDesktop.DesktopName;
                         _lastDesktopInput = inputDesktop;
                         CurrentDesktop    = inputDesktop;
                     }
                     else
                     {
                         var errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                         Console.WriteLine(errorMessage);
                         _lastDesktopInput?.Close();
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message, ex);
         }
         Thread.Sleep(1000);
     }
 }
Example #2
0
        /// <summary>
        ///     Opens the current input desktop.
        /// </summary>
        /// <returns>If successful, a Desktop object, otherwise, null.</returns>
        public static Desktop OpenInputDesktop()
        {
            // open the desktop.
            var desktop = new Desktop();
            var result  = desktop.OpenInput();

            // somethng went wrong.
            if (!result)
            {
                return(null);
            }

            return(desktop);
        }
Example #3
0
        /// <summary>
        ///     Opens the current input desktop.
        /// </summary>
        /// <returns>If successful, a Desktop object, otherwise, null.</returns>
        public static Desktop OpenInputDesktop()
        {
            // open the desktop.
            var desktop = new Desktop();
            var result = desktop.OpenInput();

            // somethng went wrong.
            if (!result) return null;

            return desktop;
        }