Screen recording of a region around the mouse ready-to-use code sample:
This sample code demonstrates how to use Screen Capturing SDK to record video from the dynamic region around the mouse. The region is defined by the width and height. This method works as a virtual camera that follows to the mouse cursor.
1) Visual Basic .NET
Create new VB.NET Console project in Visual Studio. Click Project | Add Reference.. and add the reference to Bytescout Screen Capturing Lib on the COM tab and click OK. Then use the code snippet below:
Imports System.Threading
Imports System.Diagnostics
Imports BytescoutScreenCapturingLib ' import bytescout screen capturer activex object
Module Module1
Sub Main()
' create capturer class
Dim capturer As New CapturerClass()
' set capturing area to the region type (to capture from given region on the screen)
capturer.CapturingType = CaptureAreaType.catMouse
' output video filename
capturer.OutputFileName = "RegionAroundMouseCaptured.avi"
' set width and height of the rectangle around the mouse to capture video from
capturer.CaptureRectWidth = 320
capturer.CaptureRectHeight = 240
' start capturing
capturer.Run()
' wait for 15 seconds
Thread.Sleep(15000)
' stop capturing and flush AVI video file into the disk
capturer.Stop()
' open the output video
Process.Start("RegionAroundMouseCaptured.avi")
End Sub
End Module
2) Visual C# .NET
Create new C# Console project in Visual Studio. Click Project | Add Reference.. and add the reference to Bytescout Screen Capturing Lib on the COM tab and click OK. Then use the code snippet below:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;
using BytescoutScreenCapturingLib; // import bytescout screen capturing activex object
namespace SimpleCaptureCSharp
{
class Program
{
static void Main(string[] args)
{
CapturerClass capturer = new CapturerClass(); // create new screen capturer object
capturer.CapturingType = CaptureAreaType.catMouse; // set capturing area type to catScreen to capture whole screen
capturer.OutputFileName = "EntireScreenCaptured.avi"; // set output video filename
// set width and height of the region around the mouse
capturer.CaptureRectWidth = 320
capturer.CaptureRectHeight = 240
// set output video width and height
capturer.OutputWidth = 320;
capturer.OutputHeight = 240;
capturer.Run(); // run screen video capturing
Thread.Sleep(15000); // wait for 15 seconds
capturer.Stop(); // stop video capturing
Process.Start("EntireScreenCaptured.avi");
}
}
}
3) Visual Basic 6 and VBScript (VBS)
' create video capturer activex object
Set capturer = CreateObject("BytescoutScreenCapturing.Capturer")
' set output video file name
capturer.OutputFileName = "RegionAroundMouseCaptured.avi"
' set capturing type to the caMouse =2 to capture the region around the mouse curosr. You can also set to caRegion = 0 (to record from the given rectangle on screen) or to caScreen = 3 (to capture entire screen)
capturer.CapturingType = 2
' set width of the rectangle to capture from
capturer.CaptureRectWidth = 320
' set height of the rectangle to capture from
capturer.CaptureRectHeight = 240
MsgBox "Script will record 320x240 region around the mouse cursor for 10 seconds. Output video will go to CaptureScreenVbs.avi"
' run video capturing
capturer.Run()
' wait for 10 seconds (10000 msec)
WScript.Sleep(10000)
' stop capturing
capturer.Stop()
' destroy Capturer object so the video will be saved into the disk
Set capturer = Nothing