Forum Discussion
- Julia_KSmartBear Alumni (Retired)
Hello Ashish,
To take a picture of a mouse cursor, you can use the Picture method or the Desktop.PictureUnderMouse property.
For example, the following code uses the Picture method to make a screenshot of a mouse cursor and posts it to the test log:
function CaptureCursor()
{
// Obtains the coordinates of the mouse pointer
X = Sys.Desktop.MouseX;
Y = Sys.Desktop.MouseY;
// Captures a rectangle area of the desktop including the mouse cursor
pics = Sys.Desktop.Picture(X-20, Y-20, 40, 40, true);
// Posts the captured image to the test log
Log.Picture(pics);
}I hope, this information helps you. Please let us know if you have additional questions.
Good luck. - Ashishp_1ContributorDear Julia,
Many thanks for your reply.
Answer you have given similar to requirement that I want but not exactly.
Actually, I want cursor image, I don't want any background of that cursor.I want exact cursor image.
Thanks
Ashish - Julia_KSmartBear Alumni (Retired)
Hello Ashish,
Unfortunately, TestComplete does not provide any straightforward means for capturing mouse cursor images without a background.
As a workaround, you can determine the cursor state ("Arrow", "Busy", "Hand" and etc.) instead of capturing the cursor image. In the Get a cursor state article of the TestComplete How To section, you can view the sample script that demonstrates how to obtain the current state of the mouse cursor.Besides, you mentioned that you would like to obtain the mouse cursor every time it changes. Tracking the mouse cursor state during the test run may be not an easy task, so, probably, you should better get the mouse cursor state only at the moments when you expect it to change (for example, after moving the mouse cursor to the needed position).
Please let us know whether this information helps.
Good luck. - Ashishp_1ContributorDear Julia,
Thanks for your reply.
Actually, I want to check mouse cursor image.Means I want to check whether it is arrow, hand,etc.
The application that I am testing has different cursor images that are not exist in XP.Please check image attached.
As images not exist in XP, then link that you suggested ...http://smartbear.com/support/viewarticle/17632/ is not helpful.
I can take image of cursor, as you suggested but it comes with background. But any mis-matched background will make my code fail.
I tried with code of ...
var pid = Win32API.GetWindowThreadProcessId(TargetWindow.Handle, null);
var tid = Win32API.GetCurrentThreadId();
Win32API.AttachThreadInput(pid, tid, true);
var crsr = Win32API.GetCursor();
But each time crsr gives different value, for different machines with same XP.
Do you have any strong code or any suggestion ?
Waiting for your reply...
- Julia_KSmartBear Alumni (Retired)
Hello Ashish,
Please specify whether your tested application is recognized as Open by TestComplete, and with what programming language and IDE it was developed. The cursor state may be obtained via native properties of the application's objects. To learn how to determine whether your application is Open, please see the Open Applications - Overview Help topic.
I tried with code of ...
var pid = Win32API.GetWindowThreadProcessId(TargetWindow.Handle, null); var tid = Win32API.GetCurrentThreadId(); Win32API.AttachThreadInput(pid, tid, true); var crsr = Win32API.GetCursor(); But each time crsr gives different value, for different machines with same XP.Does GetCursor return different values only for cursors in your tested application or for all cursors including Windows native cursors?
Also, please note that to get the cursor state, you can try using the following workaround:
1. Create a Regions collection in your project and add images of all cursors used in your application to the collection. Make sure that those images have a solid background. For more information on the Regions collection and on how to add images to it, please see the About Regions Collection and Adding Images to the Regions Collection Help topics.
2. Get a screenshot of the cursor whose state you want to check using the PictureUnderMouse property or the Picture method.
3. Iterate through the cursor images stored in the Regions collection and compare each of them (excluding their background by enabling the Transparency mode) with the screenshot. To compare images, you can use the Regions.Compare, Regions.Find, Regions.FindRegion and Region.Check methods. All these methods have the Transparent parameter. When this parameter is set to true, TestComplete treats the color of the baseline image's top-left pixel as transparent and excludes all pixels that have the same color from the comparison. For more information on the transparency mode, please see the "Transparent" Color section in the How Image Comparison Works Help topic.
For example, the following code obtains a cursor screenshot, iterates through the Regions collection and uses the Regions.Find method to check whether the screenshot contains the cursor image stored by the current collection item. If it finds a match, it posts the name of the item to the test log:
function GetCursor()
{
// Obtains the image of the mouse cursor
X = Sys.Desktop.MouseX;
Y = Sys.Desktop.MouseY;
var pic = Sys.Desktop.Picture(X-10, Y-10, 40, 40);
// Iterates through the Regions collection
count = Regions.Count();
for (var i = 0; i < count; i++)
{
// Searches for the image stored by the current collection item within the obtained image
// The Transparent parameter is set to true
if (Regions.Find(pic, Regions.GetPicture(i), 0 , 0, true) != null)
{
Log.Message(Regions.NameByIndex(i));
break;
}
}
}
Please let us know whether this information is useful and whether you have any additional questions.
Thank you. - Ashishp_1ContributorDear Julia,
Many many thanks for helped me.
It works.
Related Content
- 3 months ago
- 10 years ago
- 10 years ago
Recent Discussions
- 12 hours ago