Exemplo n.º 1
0
        public static ClipboardData Get(IntPtr foregroundWindow)
        {
            ClipboardData dataFromScreen;

            using (WheelOfHistoryController.DisableClipsGrabbingInThisBlock())
            {
                CustomTraceLog log = new CustomTraceLog("Grabb...", false, false, CustomTraceLogAddLinePostProcessingEvent);

                var originalClipboardData = CraftSynth.Win32Clipboard.ClipboardProxy.GrabClipboardDataStripped(false);

                Application.DoEvents();
                CraftSynth.Win32Clipboard.ClipboardProxy.ClearClipboard(log);
                Application.DoEvents();

                if (IntPtr.Zero != foregroundWindow)
                {
                    CraftSynth.BuildingBlocks.WindowsNT.Misc.SetForegroundWindow(foregroundWindow);
                    log.AddLine("foregr ok" + foregroundWindow.ToString());
                }
                else
                {
                    log.AddLine("forgr empty");
                }

                try
                {
                    SendKeys.SendWait("^c");
                }
                catch (Exception ex)
                {
                    Logging.AddExceptionLog(ex);
                    SendKeys.SendWait("^c");
                }
                Application.DoEvents();

                dataFromScreen = CraftSynth.Win32Clipboard.ClipboardProxy.GrabClipboardData(false, log);
                Application.DoEvents();
                Logging.AddActionLog("grab:" + dataFromScreen == null ? "null" : dataFromScreen.Formats.Count.ToString());
                //if (dataFromScreen != null && dataFromScreen.Formats.Count == 0)
                //{
                //	Thread.Sleep(500);
                //	 dataFromScreen = CraftSynth.Win32Clipboard.ClipboardProxy.GrabClipboardData(false, log);
                //	Logging.AddActionLog("grab2:"+dataFromScreen==null?"null":dataFromScreen.Formats.Count.ToString());
                //}
                CraftSynth.Win32Clipboard.ClipboardProxy.RestoreClipboardData(originalClipboardData, false);

                Application.DoEvents();
            }

            return(dataFromScreen);
        }
Exemplo n.º 2
0
        public static void Put(string text)
        {
            using (WheelOfHistoryController.DisableClipsGrabbingInThisBlock())
            {
                var clipboardData = CraftSynth.Win32Clipboard.ClipboardProxy.GrabClipboardDataStripped(false);
                Application.DoEvents();

                Clipboard.SetText(text);
                Application.DoEvents();


                //SendKeys.SendWait("^v");
                //Application.DoEvents();
                try
                {
                    KeyboardSimulator.SimulateCtrlV();
                    Thread.Sleep(100);
                }
                catch (Exception e)
                {
                    try
                    {
                        CraftSynth.BuildingBlocks.WindowsNT.Misc.ThrowApplicationExceptionIfErrorOccurred();
                    }
                    catch (Exception innerE)
                    {
                        e = new Exception(e.Message, innerE);
                    }
                    Logging.AddExceptionLog(e);
                    if (Debugger.IsAttached)
                    {
                        CraftSynth.BuildingBlocks.Common.Misc.BeepInNewThread();
                    }
                }


                CraftSynth.Win32Clipboard.ClipboardProxy.RestoreClipboardData(clipboardData, false);
                Application.DoEvents();
            }
        }