-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProgram.cs
99 lines (79 loc) · 2.88 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using NDesk.Options;
using System;
using System.Threading;
using System.Diagnostics;
using System.Windows;
using System.Timers;
using System.Runtime.Remoting.Messaging;
namespace Clippi_B
{
class Program
{
public static void ShowHelp(OptionSet p)
{
Console.WriteLine("Usage:");
p.WriteOptionDescriptions(Console.Out);
}
static void Main(string[] args)
{
Boolean help = false;
Info.Showbanner();
int interval = 5;
int monitor = 480;
var options = new OptionSet(){
{"i|interval=","Intervaltimer in seconds to check if clipboard has contents (default every 5 seconds)",o=> interval = Int32.Parse(o) },
{"m|monitor=","How long this program should be ran in the background in minutes (default 8 hours)",o=> monitor = Int32.Parse(o)},
{"h|?|help","Show Help", o => help = true}
};
try
{
options.Parse(args);
if (help)
{
ShowHelp(options);
return;
}
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
ShowHelp(options);
return;
}
//minutes * 60 (seconds) / interval
int timestorun = (monitor * 60) / interval;
string oldclipboardcontent = "";
for (int i = 0; i < timestorun; i++)
{
Thread StaThread = new Thread(() => {
oldclipboardcontent = Clippi(oldclipboardcontent);
});
StaThread.SetApartmentState(ApartmentState.STA);
StaThread.Start();
Thread.Sleep(interval * 1000);
}
}
public static string Clippi(string previousclipboardtext)
{
Boolean text = false;
string clipboardtext = "";
if(String.IsNullOrEmpty(previousclipboardtext))
previousclipboardtext = "";
try
{
text = Clipboard.ContainsText();
if (text)
{
clipboardtext = Clipboard.GetText(TextDataFormat.Text);
if (clipboardtext != previousclipboardtext)
{ Console.WriteLine("Clipboard contains text! contents:\n" + clipboardtext); }
previousclipboardtext = clipboardtext;
return clipboardtext;
}
}
catch (Exception ex)
{ Console.WriteLine("ERROR:" + ex); }
return "";
}
}
}