using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runtime.InteropServices; public static class VoiceBotScript { public static void Run(IntPtr windowHandle) { // Here you set the path for saving screenshots string path = (@"C:\ScreenShots\"); // Here you may change image format (Png, Jpeg, Bmp, Tiff, Gif, Icon, Wmf, Emf, Exif) ImageFormat ext = ImageFormat.Png; // If directory not exists call a method CreateDir if (!Directory.Exists(path)) { Dir.CreateDir(path); } // Call a method Capture Capture.GetCapture(path,ext); } } static class Dir { public static void CreateDir(string path) { // Create directory if sufficient permissons. try { Directory.CreateDirectory(path); // Get only name of directory string foldername = Path.GetFileName(Path.GetDirectoryName(path)); BFS.Speech.TextToSpeech("Create directory" + foldername); } // Permission exception catch (UnauthorizedAccessException) { BFS.Speech.TextToSpeech("Insufficient permissions. Can't create the directory"); } } } static class Capture { private static string name, time, extension, filename; public static void GetCapture(string path, ImageFormat ext) { // Get and save fullscreen image Image imgFullScr = ScreenCapture.CaptureDesktop(); // Get and save focused window image Image imgActWnd = ScreenCapture.CaptureActiveWindow(); GetFileName(path, ext); // Create dialog with choice string capture = BFS.Dialog.GetUserInputList("What screenshot you want to do?", new string[] { "FullScreen", "ActiveWindow" }); // The choice of how to save the image. switch (capture) { case "FullScreen": imgFullScr.Save(@filename, ext); BFS.Speech.TextToSpeech("Fullscreen image saved"); break; case "ActiveWindow": imgActWnd.Save(@filename, ext); BFS.Speech.TextToSpeech("Active window image saved"); break; } } private static void GetFileName(string path, ImageFormat ext) { // Get handle focused window IntPtr hWnd = BFS.Window.GetFocusedWindow(); // Get window name from hanle name = BFS.Window.GetText(hWnd); // Convert current time and date to string time = DateTime.Now.ToString("(yyyy-MM-dd@HH.mm.ss)"); // Convert imageformat to string and to lowercase extension = ext.ToString().ToLower(); // Set formatting for saving file filename = (path + name + " " + time + "." + extension); } } static class ScreenCapture { [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] private static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect); [StructLayout(LayoutKind.Sequential)] private struct Rect { public int Left; public int Top; public int Right; public int Bottom; } public static Image CaptureDesktop() { return CaptureWindow(GetDesktopWindow()); } public static Bitmap CaptureActiveWindow() { return CaptureWindow(GetForegroundWindow()); } // Capture desktop or active window // and return it as a bitmap public static Bitmap CaptureWindow(IntPtr hWnd) { Rect rect = new Rect(); GetWindowRect(hWnd, ref rect); Rectangle bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top); Bitmap result = new Bitmap(bounds.Width, bounds.Height); using (Graphics graphics = Graphics.FromImage(result)) { graphics.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size); } return result; } }