Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

PabloMartinez's profile on WallpaperFusion.com
For some unknown to me reason, script with the press and release key "PrintScreen or Alt+PrintScreen or Ctrl+PrintScreen" doesn't work for me, then i decided to make own workaround. Yes, this solution with is not optimal and simplest, but it works. :D
This solution allows to save not only the full screen image, but also and the active window. You can choose from the list.

How it works:
  • In the script, change the path on your.
  • If you want, change the format of the saved screenshots.

You can use the code or download a ready profile.

Code

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;
    }
}


Slightly edit code.
• Attachment: Screenshot (English United States).voicebot [24,314 bytes]
Jun 3, 2016 (modified Jun 9, 2016)  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Thanks! I've posted that Macro Script to the repository :)

Edit: The reason that sending the Print Screen key from VoiceBot doesn't work is because VoiceBot sends keystrokes to the focused window, so it doesn't get picked up by the Windows clipboard as the global Print Screen hotkey.
Jun 10, 2016 (modified Jun 10, 2016)  • #2
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)