Esempio n. 1
0
 public void BeginWatching(Models.SocketMessageHandler connectionToSendChanges)
 {
     if (ClipboardWatcher?.Enabled == true)
     {
         ClipboardWatcher.Stop();
     }
     ClipboardWatcher          = new System.Timers.Timer(500);
     ClipboardWatcher.Elapsed += (sender, args) =>
     {
         MainWindow.Current.Dispatcher.Invoke(() =>
         {
             try
             {
                 if (!Clipboard.IsCurrent(ClipboardData))
                 {
                     ClipboardData = Clipboard.GetDataObject();
                     var jsonData  = GetTransferData();
                     if (!string.IsNullOrWhiteSpace(jsonData.Format))
                     {
                         connectionToSendChanges.SendJSON(jsonData);
                     }
                 }
             }
             catch
             {
                 if (!connectionToSendChanges.IsConnected)
                 {
                     ClipboardWatcher.Stop();
                 }
             }
         });
     };
     ClipboardWatcher.Start();
 }
Esempio n. 2
0
 protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     clipboardWatcher = new ClipboardWatcher(Handle);
     clipboardWatcher.RegisterClipboardViewer();
     clipboardWatcher.ClipboardChanged += ClipboardWatcher_ClipboardChanged;
 }
Esempio n. 3
0
        public static void Stop()
        {
            context = null;

            OnClipboardChange = null;
            ClipboardWatcher.Stop();
        }
Esempio n. 4
0
 protected override void SetVisibleCore(bool value)
 {
     CreateHandle();
     _instance            = this;
     _nextClipboardViewer = SetClipboardViewer(_instance.Handle);
     base.SetVisibleCore(false);
 }
Esempio n. 5
0
 public static void StopListening()
 {
     _instance.Invoke(new MethodInvoker(() => ChangeClipboardChain(_instance.Handle, _nextClipboardViewer)));
     _instance.Invoke(new MethodInvoker(_instance.Close));
     _instance.Dispose();
     _instance = null;
 }
Esempio n. 6
0
        public MainWindow()
        {
            InitializeComponent();

            KeyboardWatcher.Start();
            KeyboardWatcher.OnKeyInput += (s, e) =>
            {
                Debug.WriteLine(string.Format("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname));
            };

            MouseWatcher.Start();
            MouseWatcher.OnMouseInput += (s, e) =>
            {
                Debug.WriteLine(string.Format("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y));
            };

            ClipboardWatcher.Start();
            ClipboardWatcher.OnClipboardModified += (s, e) =>
            {
                Debug.WriteLine(string.Format("Clipboard updated with data '{0}' of format {1}", e.Data, e.DataFormat.ToString()));
            };

            ApplicationWatcher.Start();
            ApplicationWatcher.OnApplicationWindowChange += (s, e) =>
            {
                Debug.WriteLine(string.Format("Application window of '{0}' with the title '{1}' was {2}", e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event));
            };

            PrintWatcher.Start();
            PrintWatcher.OnPrintEvent += (s, e) =>
            {
                Debug.WriteLine(string.Format("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName, e.EventData.Pages));
            };
        }
Esempio n. 7
0
 public static void Start()
 {
     ClipboardWatcher.Start();
     ClipboardWatcher.OnClipboardChange += (format, data) =>
     {
         OnClipboardChange?.Invoke(format, data);
     };
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press [RETURN] to quit...");

            using (var clipboardWatcher = new ClipboardWatcher())
            {
                clipboardWatcher.ClipboardTextChanged += text => Console.WriteLine(string.Format("Text arrived @ clipboard: {0}", text));
                Console.ReadLine();
            }
        }
Esempio n. 9
0
 public static void Start()
 {
     ClipboardWatcher.Start();
     ClipboardWatcher.OnClipboardChange += (ClipboardFormat format, object data) => {
         if (OnClipboardChange != null)
         {
             OnClipboardChange(format, data);
         }
     };
 }
Esempio n. 10
0
 public static void Stop()
 {
     mInstance.Invoke(new MethodInvoker(() =>
     {
         ChangeClipboardChain(mInstance.Handle, nextClipboardViewer);
     }));
     mInstance.Invoke(new MethodInvoker(mInstance.Close));
     mInstance.Dispose();
     mInstance = null;
 }
Esempio n. 11
0
            // on load: (hide this window)
            protected override void SetVisibleCore(bool value)
            {
                CreateHandle();

                mInstance = this;

                nextClipboardViewer = SetClipboardViewer(mInstance.Handle);

                base.SetVisibleCore(false);
            }
Esempio n. 12
0
            // on load: (hide this window)
            protected override void SetVisibleCore(bool value)
            {
                CreateHandle();

                mInstance = this;

                bool b = User32.AddClipboardFormatListener(mInstance.Handle);

                base.SetVisibleCore(false);
            }
Esempio n. 13
0
 /// <summary>
 /// Start clipboard watching.
 /// </summary>
 public static void Start()
 {
     ClipboardWatcher.Start();
     ClipboardWatcher.OnClipboardChange += (DataObject data, string[] formats) =>
     {
         if (OnClipboardChange != null)
         {
             OnClipboardChange(data, formats);
         }
     };
 }
Esempio n. 14
0
        public static void Start()
        {
            InitializeContext();

            ClipboardWatcher.Start();
            ClipboardWatcher.OnClipboardChange += (ClipboardFormat format, object data) =>
            {
                context.Send(
                    o => OnClipboardChange?.Invoke(format, data), null);
            };
        }
Esempio n. 15
0
        private void ClipboardOpen(object sender, ClipboardEventArgs e)
        {
            if (copied)
            {
                return;
            }

            copied = true;
            Thread.Sleep(150);
            ClipboardWatcher.Stop();
            callback.OnClipboardCopy(Clipboard.GetText(TextDataFormat.Text));
        }
Esempio n. 16
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            ClipboardWatcher.OnClipboardModified += ClipboardWatcher_OnClipboardModified;
            ClipboardWatcher.Start();

            ctxMenuStripNotify.ItemClicked += CtxMenuStripNotify_ItemClicked;
            Clips.ListChanged  += Clips_ListChanged;
            Clips.BeforeRemove += Clips_BeforeRemove;

            dlvClips.DataSource = Clips;
            dlvClips.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Esempio n. 17
0
            // stop listening (dispose form)
            public static void Stop()
            {
                mInstance.Invoke(new MethodInvoker(() =>
                {
                    ChangeClipboardChain(mInstance.Handle, nextClipboardViewer);
                }));
                mInstance.Invoke(new MethodInvoker(mInstance.Close));

                mInstance.Dispose();

                mInstance = null;
            }
Esempio n. 18
0
 public void BeginWatching(Models.SocketMessageHandler connectionToSendChanges)
 {
     try
     {
         if (ClipboardWatcher?.Enabled == true)
         {
             ClipboardWatcher.Stop();
         }
         ClipboardData = Clipboard.GetDataObject();
         Clipboard.SetDataObject(ClipboardData);
         ClipboardWatcher = new System.Timers.Timer(500);
     }
     catch
     {
         return;
     }
     ClipboardWatcher.Elapsed += (sender, args) =>
     {
         if (!Config.Current.IsClipboardShared)
         {
             ClipboardWatcher.Stop();
             return;
         }
         MainWindow.Current.Dispatcher.Invoke(() =>
         {
             try
             {
                 if (!Clipboard.IsCurrent(ClipboardData))
                 {
                     ClipboardData = Clipboard.GetDataObject();
                     var jsonData  = GetTransferData();
                     if (!string.IsNullOrWhiteSpace(jsonData.Format))
                     {
                         connectionToSendChanges.SendJSON(jsonData);
                     }
                 }
             }
             catch (Exception ex)
             {
                 if (connectionToSendChanges?.IsConnected != true)
                 {
                     ClipboardWatcher.Stop();
                 }
                 else
                 {
                     Utilities.WriteToLog(ex);
                 }
             }
         });
     };
     ClipboardWatcher.Start();
 }
Esempio n. 19
0
    private static void Main()
    {
        var watcher   = new ClipboardWatcher(OnChange);
        var component = new Component1();

        component.mOnExit += () =>
        {
            watcher.End();
            Application.Exit();
        };

        Application.Run();
    }
Esempio n. 20
0
        public void OnExit()
        {
            //keyboardMouseSimulator.releaseCtrl();

            ClipboardWatcher.Stop();
            KeyboardWatcher.Stop();
            MouseWatcher.Stop();
            Console.WriteLine("done!");
            Application.Exit();
            try
            {
                Environment.Exit(1);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
        }
Esempio n. 21
0
        void window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowInteropHelper wih = new WindowInteropHelper(window);

            hWndSource       = HwndSource.FromHwnd(wih.Handle);
            clipboardWatcher = new ClipboardWatcher(hWndSource.Handle);
            clipboardWatcher.OnClipboardChanged += new EventHandler(ClipboardChanged);
            clipboardWatcher.SetClipboardHandle();
            hWndSource.AddHook(clipboardWatcher.ReceiveMessage);
            showHotKey = new GlobalHotkey(Modifiers.Win, Keys.Oemtilde, window, true);
            showHotKey.HotkeyPressed += new EventHandler <HotkeyEventArgs>(DoOnShowHotKey);
            if (Settings.Current.WasClosed)
            {
                window.Hide();
            }
        }
Esempio n. 22
0
        // stop listening (dispose form)
        public static void Stop()
        {
            try
            {
                mInstance.Invoke(new MethodInvoker(() =>
                {
                    ChangeClipboardChain(mInstance.Handle, nextClipboardViewer);
                }));
                mInstance.Invoke(new MethodInvoker(mInstance.Close));

                mInstance.Dispose();

                mInstance = null;
            }
            catch (NullReferenceException) { }
        }
Esempio n. 23
0
 static void Stop()
 {
     lock (typeof(ClipboardWatcher))
     {
         try
         {
             if (started && dialog != null)
             {
                 InUiThread(dialog.Close);
                 dialog  = null;
                 started = false;
             }
         }
         catch { }
     }
 }
Esempio n. 24
0
        private void CtxMenuStripNotify_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem != quitToolStripMenuItem)
            {
                // get the full item
                var item = Clips.Where(c => c.Key == (Guid)e.ClickedItem.Tag).FirstOrDefault();

                ClipboardWatcher.Stop();
                Clipboard.SetText(item.Value);
                ClipboardWatcher.Start();

                // remove it from the current position and add to the end (latest)
                Clips.Remove(item);
                Clips.Add(item);
            }
        }
Esempio n. 25
0
                // stop listening (dispose form)
                public static void StopWatcher()
                {
                    if (_instance == null)
                    {
                        return;
                    }

                    _instance.Invoke(new MethodInvoker(() =>
                    {
                        ChangeClipboardChain(_instance.Handle, _nextClipboardViewer);
                    }));

                    _instance.Invoke(new MethodInvoker(_instance.Close));

                    _instance.Dispose();
                    _instance = null;
                }
Esempio n. 26
0
            // stop listening (dispose form)
            public static void Stop()
            {
                if (mInstance == null)
                {
                    return;
                }

                mInstance.Invoke(new MethodInvoker(() =>
                {
                    bool b = User32.RemoveClipboardFormatListener(mInstance.Handle);
                }));
                mInstance.Invoke(new MethodInvoker(mInstance.Close));

                mInstance.Dispose();

                mInstance = null;
            }
Esempio n. 27
0
        public MainWindow()
        {
            InitializeComponent();

            Application.Current.Exit += OnApplicationExit;

            keyboardWatcher = eventHookFactory.GetKeyboardWatcher();
            keyboardWatcher.Start();
            keyboardWatcher.OnKeyInput += (s, e) =>
            {
                Console.WriteLine("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname);
            };

            mouseWatcher = eventHookFactory.GetMouseWatcher();
            mouseWatcher.Start();
            mouseWatcher.OnMouseInput += (s, e) =>
            {
                Console.WriteLine("Mouse event {0} at point {1},{2}", e.Message.ToString(), e.Point.x, e.Point.y);
            };

            clipboardWatcher = eventHookFactory.GetClipboardWatcher();
            clipboardWatcher.Start();
            clipboardWatcher.OnClipboardModified += (s, e) =>
            {
                Console.WriteLine("Clipboard updated with data '{0}' of format {1}", e.Data,
                                  e.DataFormat.ToString());
            };


            applicationWatcher = eventHookFactory.GetApplicationWatcher();
            applicationWatcher.Start();
            applicationWatcher.OnApplicationWindowChange += (s, e) =>
            {
                Console.WriteLine("Application window of '{0}' with the title '{1}' was {2}",
                                  e.ApplicationData.AppName, e.ApplicationData.AppTitle, e.Event);
            };

            printWatcher = eventHookFactory.GetPrintWatcher();
            printWatcher.Start();
            printWatcher.OnPrintEvent += (s, e) =>
            {
                Console.WriteLine("Printer '{0}' currently printing {1} pages.", e.EventData.PrinterName,
                                  e.EventData.Pages);
            };
            eventHookFactory.Dispose();
        }
Esempio n. 28
0
        public MainWindow()
        {
            InitializeComponent();

            SourceInitialized += (sender, e) =>
            {
                cw         = new ClipboardWatcher(this);
                cw.Change += (sender, e) =>
                {
                    if (e.Data.GetDataPresent(DataFormats.Text, true))
                    {
                        var txt = (string)e.Data.GetData(DataFormats.Text);
                        MessageBox.Show(txt);
                    }
                };
                cw.Start();
            };
        }
Esempio n. 29
0
        /// <summary>
        /// On Load of this Form do.
        /// </summary>
        /// <param name="sender">The Sender.</param>
        /// <param name="e">The Event Arguments.</param>
        private void TCPMagic_Load(object sender, EventArgs e)
        {
            // Set MessagBox stuff.
            MessagBox.ListClicks = new EventHandler[] { ButtonAdd_Click, ButtonRemove_Click, ButtonRename_Click, ButtonShow_Click, ButtonUTP_Click, ListBox_SelectedIndexChanged, ListBox_DoubleClick, ProfileSelector_Load };
            MessagBox.TextBack   = backCol;
            MessagBox.TextFore   = foreCol;
            MessagBox.ListIcon   = MessagBox.ProfileIcon;
            MessagBox.Size       = size;

            // Set some default options.
            logMenuItem.Checked = formatMenuItem.Checked = true;

            // Set encoding to display within the combo box.
            comboEncoding.Items.Add("ASCII");
            comboEncoding.Items.Add("UTF8");
            comboEncoding.Items.Add("UTF7");
            comboEncoding.Items.Add("UTF32");
            comboEncoding.Items.Add("Unicode");
            comboEncoding.SelectedItem = "UTF8";

            // Initialize the PS4TCP handler instance.
            ps4TCP = new PS4TCP(rtb, this);

            //Initialize a new instance of the ClipboardWatcher class. By default it is set to watch for text.
            clipboard = new ClipboardWatcher(DataFormats.Text, false);
            clipboard.ContentPresent += Clipboard_ContentPresent;

            // Initialize the settings instance and laod up.
            settings = new Settings();
            LoadSettings();
            LoadColors();

            // Set RichTextBox depending variables.
            actions = new EventHandler[] { ClearContext_Click, CopyContext_Click, CutContext_Click, PasteContext_Click, SaveContext_Click, Save2BinContext_Click, SelectAllContext_Click, KillContext_Click };
            rtb.InitContextMenu(actions);
            rtb.ContextMenu.MenuItems[0].Enabled = rtb.ContextMenu.MenuItems[6].Enabled = rtb.ContextMenu.MenuItems[7].Enabled = killMenuItem.Enabled = false;
            rtb.ContextMenu.MenuItems[1].Enabled = rtb.ContextMenu.MenuItems[2].Enabled = rtb.ContextMenu.MenuItems[4].Enabled = rtb.ContextMenu.MenuItems[5].Enabled = false;
            rtb.SelectionChanged += Rtb_SelectionChanged;
            checkServer.Checked   = true;
            rtb.ReadOnly          = false;
        }
Esempio n. 30
0
 static void Start()
 {
     lock (typeof(ClipboardWatcher))
     {
         if (!started)
         {
             started = true;
             ThreadPool.QueueUserWorkItem(_ =>
             {
                 try
                 {
                     Debug.Assert(dialog == null);
                     dialog            = new ClipboardWatcher();
                     dialog.Activated += delegate
                     {
                         WindowHandle = dialog.Handle;
                     };
                     dialog.ShowDialog();
                 }
                 catch { }
             });
         }
     }
 }
Esempio n. 31
0
        public InputCoreViewModel(InputViewModel parent)
        {
            this._parent   = parent;
            this._provider = new InputAreaSuggestItemProvider();

            CompositeDisposable.Add(
                this._bindingHashtags = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    InputModel.InputCore.BindingHashtags,
                    tag => new BindHashtagViewModel(tag, () => UnbindHashtag(tag)),
                    DispatcherHelper.UIDispatcher));
            CompositeDisposable.Add(_bindingHashtags
                                    .ListenCollectionChanged()
                                    .Subscribe(_ =>
            {
                InputData.BoundTags = _bindingHashtags.Select(h => h.Hashtag).ToArray();
                RaisePropertyChanged(() => IsBindingHashtagExisted);
            }));
            _bindableHashtagCandidates =
                new DispatcherCollection <BindHashtagViewModel>(DispatcherHelper.UIDispatcher);
            CompositeDisposable.Add(_bindableHashtagCandidates
                                    .ListenCollectionChanged()
                                    .Subscribe(_ => RaisePropertyChanged(() => IsBindableHashtagExisted)));

            CompositeDisposable.Add(_draftedInputs =
                                        ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                            InputModel.InputCore.Drafts,
                                            _ =>
                                            new InputDataViewModel(this, _, vm => InputModel.InputCore.Drafts.Remove(vm)),
                                            DispatcherHelper.UIDispatcher));

            CompositeDisposable.Add(_draftedInputs
                                    .ListenCollectionChanged()
                                    .Subscribe(_ =>
            {
                RaisePropertyChanged(() => DraftCount);
                RaisePropertyChanged(() => IsDraftsExisted);
            }));

            // listen setting changed
            CompositeDisposable.Add(
                Setting.SuppressTagBindingInReply.ListenValueChanged(
                    _ => RaisePropertyChanged(() => IsBindHashtagEnabled)));

            // listen text control
            CompositeDisposable.Add(new EventListener <Action <CursorPosition> >(
                                        h => InputModel.SetCursorRequest += h,
                                        h => InputModel.SetCursorRequest -= h,
                                        SetCursor));
            var plistener = new PropertyChangedEventListener(InputModel.InputCore);

            plistener.Add(() => InputModel.InputCore.CurrentInputData, (_, e) => InputDataChanged());
            CompositeDisposable.Add(plistener);

            // create temporary directory and reserve deletion before exit app.
            do
            {
                _tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            } while (Directory.Exists(_tempDir));
            Directory.CreateDirectory(_tempDir);
            App.ApplicationExit += () =>
            {
                try
                {
                    Directory.Delete(this._tempDir, true);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception)
                {
                    // I think that is sign from God that I must not delete that folder if failed.
                }
            };

            // initialize clipboard watcher.
            ClipboardWatcher watcher;

            CompositeDisposable.Add(watcher = new ClipboardWatcher());
            watcher.ClipboardChanged       += (o, e) => RaisePropertyChanged(() => IsClipboardContentImage);
            watcher.StartWatching();
            Setting.DisableGeoLocationService.ValueChanged += this.UpdateGeoLocationService;
            this.UpdateGeoLocationService(Setting.DisableGeoLocationService.Value);
        }
Esempio n. 32
0
 public static void Stop()
 {
     OnClipboardChange = null;
     ClipboardWatcher.StopWatcher();
 }