예제 #1
0
        public void CreateProject()
        {
            // kinda losing my sanity
            string FullFileName = Path.Combine(Cappy.FolderName, Cappy.Prefix + Cappy.GetSaveTime() + Cappy.ProjectExtension);

            File.Create(FullFileName).Dispose();

            Cappy.ProjectPath = FullFileName;
        }
예제 #2
0
        public static string GetCapture(int posX, int posY, string buttonClicked)
        {
            string saveTime = Cappy.GetSaveTime();
            string folder   = Cappy.FolderName + @"\Images\";

            string FullFileName  = String.Empty;
            string FocusFileName = String.Empty;
            string buttonAction  = String.Empty;

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            FullFileName  = folder + Cappy.Prefix + Cappy.FieldSeperator + saveTime + Cappy.FieldSeperator + "full" + Cappy.Extension;
            FocusFileName = folder + Cappy.Prefix + Cappy.FieldSeperator + saveTime + Cappy.FieldSeperator + "focus" + Cappy.Extension;

            IntPtr hwnd       = NativeMethods.WindowFromPoint(posX, posY);
            string WindowText = NativeMethods.GetWindowTextByWM(hwnd);

            Bitmap FullCapture = ScreenCapture.GetScreenShot(posX, posY, 0, false);

            FullCapture.Save(FullFileName);
            FullCapture.Dispose();

            Bitmap FocusedCapture = ScreenCapture.GetScreenShot(posX, posY, 1, false);

            FocusedCapture.Save(FocusFileName);
            FocusedCapture.Dispose();

            if (buttonClicked.Equals("Left"))
            {
                buttonAction = "Click";
            }
            else if (buttonClicked.Equals("Right"))
            {
                buttonAction = "Right-click";
            }
            else if (buttonClicked.Equals("Tab") ||
                     buttonClicked.Equals("Escape") ||
                     buttonClicked.Equals("Enter"))
            {
                buttonAction = "Press";
            }

            if (String.IsNullOrEmpty(WindowText))
            {
                WindowText = "<< UNKNOWN >>";
            }

            string CaptureDetails = buttonAction + ";" + buttonClicked + ";" + WindowText + ";" + FullFileName + ";" + FocusFileName + "?";

            return(CaptureDetails);
        }
예제 #3
0
        public static string GetCapture(string buttonClicked)
        {
            // method overloading is cool
            string saveTime = Cappy.GetSaveTime();
            string folder   = Cappy.FolderName + @"\Images\";

            string FileName;

            string buttonAction = String.Empty;

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            FileName = folder + Cappy.Prefix + Cappy.FieldSeperator + saveTime + Cappy.FieldSeperator + "key" + Cappy.Extension;

            // rectangl shid
            Rectangle bounds = new Rectangle();

            NativeMethods.RECT rct;
            IntPtr             hwnd       = NativeMethods.GetForegroundWindow();
            IntPtr             parentHwnd = NativeMethods.GetParent(hwnd);

            if (parentHwnd == IntPtr.Zero)
            {
                // if foreground window is already top level, just use it's hwnd
                NativeMethods.GetWindowRect(hwnd, out rct);

                bounds.X      = rct.Left;
                bounds.Y      = rct.Top;
                bounds.Width  = rct.Right - rct.Left;
                bounds.Height = rct.Bottom - rct.Top;
            }
            else
            {
                // otherwise, get the top level window in the foreground window's hierarchy
                NativeMethods.GetWindowRect(parentHwnd, out rct);

                bounds.X      = rct.Left;
                bounds.Y      = rct.Top;
                bounds.Width  = rct.Right - rct.Left;
                bounds.Height = rct.Bottom - rct.Top;
            }

            Bitmap Capture = ScreenCapture.GetScreenShot(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2), 1, true);

            Capture.Save(FileName);
            Capture.Dispose();

            if (buttonClicked.Equals("Left"))
            {
                buttonAction = "Click";
            }
            else if (buttonClicked.Equals("Right"))
            {
                buttonAction = "Right-click";
            }
            else if (buttonClicked.Equals("Tab") ||
                     buttonClicked.Equals("Escape") ||
                     buttonClicked.Equals("Enter"))
            {
                buttonAction = "Press";
            }

            string CaptureDetails = buttonAction + ";" + buttonClicked + ";" + FileName + "?";

            return(CaptureDetails);
        }
예제 #4
0
        public void BuildDocument(string[] ScriptItems)
        {
            string FullDocFileName = Cappy.FolderName + @"\" + Cappy.Prefix + Cappy.FieldSeperator + Cappy.GetSaveTime() + Cappy.FieldSeperator + Cappy.DocExtension;

            using (DocX document = DocX.Create(FullDocFileName))
            {
                foreach (string ScriptItem in ScriptItems)
                {
                    if (ScriptItem != null)
                    {
                        // instantiate some
                        // TODO: this loop contains alot of copy paste and hackiness because im tired and shit, please clean it up
                        string[] Fields = ScriptItem.Split(';');

                        string ButtonAction  = String.Empty;
                        string ButtonClicked = String.Empty;
                        string WindowText    = String.Empty;
                        string FullFileName  = String.Empty;
                        string FocusFileName = String.Empty;

                        if (Fields.Length == 5)
                        {
                            ButtonAction  = Fields[0];
                            ButtonClicked = Fields[1];
                            WindowText    = Fields[2];
                            FullFileName  = Fields[3];
                            FocusFileName = Fields[4];
                        }
                        else if (Fields.Length == 3)
                        {
                            ButtonAction  = Fields[0];
                            ButtonClicked = Fields[1];
                            FullFileName  = Fields[2];
                        }

                        string ParagraphText;

                        if (Fields.Length == 5)
                        {
                            // because alot of things in windows have weird window names, or you perform more advanced actions on them then click, let's define some things to make our documents nicer
                            if (!String.IsNullOrEmpty(WindowText))
                            {
                                ParagraphText = ButtonAction + " " + WindowText;
                            }
                            else
                            {
                                // if we can't determine what was clicked, resort to this.
                                ParagraphText = ButtonAction + " << FILL IN MISSING TEXT >>";
                            }

                            // create our paragraph to work with
                            Paragraph p = document.InsertParagraph();

                            // get bitmaps of the desired images
                            System.Drawing.Image FullCaptureImage  = GetImage(FullFileName);
                            System.Drawing.Image FocusCaptureImage = GetImage(FocusFileName);

                            // instantiate memory streams for writing our bitmaps to
                            MemoryStream FullCaptureStream  = new MemoryStream();
                            MemoryStream FocusCaptureStream = new MemoryStream();

                            // save our bitmaps into the memory stream
                            FullCaptureImage.Save(FullCaptureStream, FullCaptureImage.RawFormat);
                            FocusCaptureImage.Save(FocusCaptureStream, FocusCaptureImage.RawFormat);

                            // set position in memory stream
                            FullCaptureStream.Seek(0, SeekOrigin.Begin);
                            FocusCaptureStream.Seek(0, SeekOrigin.Begin);

                            // create the base image to work with, and add it to our document object for later
                            Xceed.Document.NET.Image FullCapture  = document.AddImage(FullCaptureStream);
                            Xceed.Document.NET.Image FocusCapture = document.AddImage(FocusCaptureStream);

                            // convert image to picture usable in a document
                            Picture FullCapturePic  = FullCapture.CreatePicture();
                            Picture FocusCapturePic = FocusCapture.CreatePicture();

                            // because screenshots will be a constant size, simply set a scalar to our desired resolution. we can also use this for calculating the focus size.
                            const int imgWidth  = 512;
                            const int imgHeight = 288;

                            // apply aforementioned scalar
                            FullCapturePic.Width  = imgWidth;
                            FullCapturePic.Height = imgHeight;

                            // create focused screenshot size
                            Size focusbbox = new Size(imgWidth, imgHeight);

                            // get the scaled version of focused image
                            Size focusSize = ExpandToBound(FocusCaptureImage.Size, focusbbox);
                            FocusCapturePic.Width  = focusSize.Width;
                            FocusCapturePic.Height = focusSize.Height;

                            // insert bullet list
                            var list = document.AddList(listType: ListItemType.Numbered, continueNumbering: true);
                            document.AddListItem(list, ParagraphText, 0, listType: ListItemType.Numbered);

                            // insert images
                            p.InsertListBeforeSelf(list);
                            p.AppendLine().AppendPicture(FullCapturePic);
                            p.AppendLine(); // space the images
                            p.AppendLine().AppendPicture(FocusCapturePic);
                            p.AppendLine(); // leave a space for writing

                            p.InsertPageBreakAfterSelf();

                            // release unneeded resources
                            FullCaptureImage.Dispose();
                            FullCaptureStream.Dispose();
                            FocusCaptureImage.Dispose();
                            FocusCaptureStream.Dispose();
                        }
                        if (Fields.Length == 3)
                        {
                            ParagraphText = ButtonAction + " " + ButtonClicked;

                            // create our paragraph to work with
                            Paragraph p = document.InsertParagraph();

                            // get bitmaps of the desired images
                            System.Drawing.Image FullCaptureImage = GetImage(FullFileName);

                            // instantiate memory streams for writing our bitmaps to
                            MemoryStream FullCaptureStream = new MemoryStream();

                            // save our bitmaps into the memory stream
                            FullCaptureImage.Save(FullCaptureStream, FullCaptureImage.RawFormat);

                            // set position in memory stream
                            FullCaptureStream.Seek(0, SeekOrigin.Begin);

                            // create the base image to work with, and add it to our document object for later
                            Xceed.Document.NET.Image FullCapture = document.AddImage(FullCaptureStream);

                            // convert image to picture usable in a document
                            Picture FullCapturePic = FullCapture.CreatePicture();

                            // because screenshots will be a constant size, simply set a scalar to our desired resolution. we can also use this for calculating the focus size.
                            const int imgWidth  = 512;
                            const int imgHeight = 288;

                            // apply aforementioned scalar
                            FullCapturePic.Width  = imgWidth;
                            FullCapturePic.Height = imgHeight;

                            // insert bullet list
                            var list = document.AddList(listType: ListItemType.Numbered, continueNumbering: true);
                            document.AddListItem(list, ParagraphText, 0, listType: ListItemType.Numbered);

                            // insert images
                            p.InsertListBeforeSelf(list);
                            p.AppendLine().AppendPicture(FullCapturePic);
                            p.AppendLine(); // space the images

                            // leave a space for writing
                            p.InsertPageBreakAfterSelf();

                            // release unneeded resources
                            FullCaptureImage.Dispose();
                            FullCaptureStream.Dispose();
                        }
                    }
                }
                document.Save();
            }
        }
예제 #5
0
        public Form1()
        {
            // run config
            Cappy.Config();

            // init form
            InitializeComponent();

            // add app exit handler
            Application.ApplicationExit += new EventHandler(OnApplicationExit);

            // create context menu
            this.components   = new System.ComponentModel.Container(); // specifically declare namespace and class, as Container is also a method declared in Novacode
            this.contextMenu1 = new ContextMenu();
            this.menuItem0    = new MenuItem();
            this.menuItem1    = new MenuItem();
            this.menuItem2    = new MenuItem();
            this.menuItem3    = new MenuItem();
            this.menuItem4    = new MenuItem();
            this.menuItem5    = new MenuItem();
            this.menuItem6    = new MenuItem();

            // Initialize contextMenu1
            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem0 });

            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem1 });

            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem2 });

            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem3 });

            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem4 });

            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem5 });

            this.contextMenu1.MenuItems.AddRange(
                new MenuItem[] { this.menuItem6 });

            // Create the NotifyIcon.
            this.notifyIcon1 = new NotifyIcon(this.components);

            // The Icon property sets the icon that will appear
            // in the systray for this application.
            notifyIcon1.Icon            = offIco;
            notifyIcon1.Visible         = true;
            notifyIcon1.BalloonTipTitle = "CappyDoc";

            // The ContextMenu property sets the menu that will
            // appear when the systray icon is right clicked.
            notifyIcon1.ContextMenu = this.contextMenu1;

            // Initialize menuItem0
            this.menuItem0.Index  = 0;
            this.menuItem0.Text   = "Start Record";
            this.menuItem0.Click += new EventHandler(this.menuItem0_Click);

            // Initialize menuItem1
            this.menuItem1.Index  = 1;
            this.menuItem1.Text   = "Stop Record";
            this.menuItem1.Click += new EventHandler(this.menuItem1_Click);

            // Initialize menuItem2
            this.menuItem2.Index  = 2;
            this.menuItem2.Text   = "Create New Project";
            this.menuItem2.Click += new EventHandler(this.menuItem2_Click);

            // Initialize menuItem3
            this.menuItem3.Index  = 3;
            this.menuItem3.Text   = "Open Project";
            this.menuItem3.Click += new EventHandler(this.menuItem3_Click);

            // Initialize menuItem4
            this.menuItem4.Index  = 4;
            this.menuItem4.Text   = "Build Current Project";
            this.menuItem4.Click += new EventHandler(this.menuItem4_Click);

            // Initialize menuItem5
            this.menuItem5.Index  = 5;
            this.menuItem5.Text   = "Config Menu";
            this.menuItem5.Click += new EventHandler(this.menuItem5_Click);

            // Initialize menuItem6
            this.menuItem6.Index  = 6;
            this.menuItem6.Text   = "Exit";
            this.menuItem6.Click += new EventHandler(this.menuItem6_Click);

            // make sure stuff is greyed out
            menuItem0.Enabled = true;
            menuItem1.Enabled = false;
            menuItem4.Enabled = true;
        }