Created
December 6, 2020 13:03
-
-
Save kbutti/46812715dd88cac4d50835028e98246f to your computer and use it in GitHub Desktop.
クリップボードを監視して標準出力に出力してく感じの
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Data; | |
| using System.Drawing; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Windows.Forms; | |
| using System.Runtime.InteropServices; | |
| namespace clipboard_chronicle_main | |
| { | |
| public partial class Form1 : Form | |
| { | |
| [DllImport("user32.dll", SetLastError = true)] | |
| private extern static void AddClipboardFormatListener(IntPtr hwnd); | |
| [DllImport("user32.dll", SetLastError = true)] | |
| private extern static void RemoveClipboardFormatListener(IntPtr hwnd); | |
| public Form1() | |
| { | |
| InitializeComponent(); | |
| } | |
| private void Form1_Load(object sender, EventArgs e) | |
| { | |
| AddClipboardFormatListener(this.Handle); | |
| } | |
| private void Form1_FormClosed(object sender, FormClosedEventArgs e) | |
| { | |
| RemoveClipboardFormatListener(this.Handle); | |
| } | |
| protected override void WndProc(ref Message m) | |
| { | |
| // see WinUser.h | |
| const int WM_CLIPBOARDUPDATE = 0x031D; | |
| switch (m.Msg) | |
| { | |
| case WM_CLIPBOARDUPDATE: | |
| string text = Clipboard.GetText(); | |
| if (text != String.Empty) | |
| { | |
| Console.WriteLine(text); | |
| } | |
| break; | |
| } | |
| base.WndProc(ref m); | |
| } | |
| } | |
| } | |
| // 以下を参考にしました | |
| // | |
| // クリップボードを監視してテキストボックスに追加していく感じの。 | |
| // https://gist.github.com/unarist/6342758 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment