Do not display mouse cursor

I am developing a desktop application for Mac where I view a screen using

CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault); 

and display a screenshot. The problem is that I expect it to show the mouse cursor too, but it will not be shown, do I need to enable any settings for this?

I tried before calling this function

 CGDisplayShowCursor(kCGDirectMainDisplay); CGAssociateMouseAndMouseCursorPosition(true); 

but it didn’t work, When I checked using the following

 bool bCursor = CGCursorIsDrawnInFramebuffer(); /* This returns false */ bCursor = CGCursorIsVisible(); /* This returns true */ 

These values ​​say that the cursor was not drawn in framebuffer (), but the cursor is visible, I suppose that I only need to do this, draw the cursor in the framebuffer, but how is this a problem,

Thanks in advance.

+4
source share
1 answer

It seems that the framebuffer is not giving me the mouse pointer, so I draw my own, this is a piece of code, maybe help you guys

 -(CGImageRef)appendMouseCursor:(CGImageRef)pSourceImage{ // get the cursor image NSPoint mouseLoc; mouseLoc = [NSEvent mouseLocation]; //get cur NSLog(@"Mouse location is x=%d,y=%d",(int)mouseLoc.x,(int)mouseLoc.y); // get the mouse image NSImage *overlay = [[[NSCursor arrowCursor] image] copy]; NSLog(@"Mouse location is x=%d,y=%d cursor width = %d, cursor height = %d",(int)mouseLoc.x,(int)mouseLoc.y,(int)[overlay size].width,(int)[overlay size].height); int x = (int)mouseLoc.x; int y = (int)mouseLoc.y; int w = (int)[overlay size].width; int h = (int)[overlay size].height; int org_x = x; int org_y = y; size_t height = CGImageGetHeight(pSourceImage); size_t width = CGImageGetWidth(pSourceImage); int bytesPerRow = CGImageGetBytesPerRow(pSourceImage); unsigned int * imgData = (unsigned int*)malloc(height*bytesPerRow); // have the graphics context now, CGRect bgBoundingBox = CGRectMake (0, 0, width,height); CGContextRef context = CGBitmapContextCreate(imgData, width, height, 8, // 8 bits per component bytesPerRow, CGImageGetColorSpace(pSourceImage), CGImageGetBitmapInfo(pSourceImage)); // first draw the image CGContextDrawImage(context,bgBoundingBox,pSourceImage); // then mouse cursor CGContextDrawImage(context,CGRectMake(0, 0, width,height),pSourceImage); // then mouse cursor CGContextDrawImage(context,CGRectMake(org_x, org_y, w,h),[overlay CGImageForProposedRect: NULL context: NULL hints: NULL] ); // assuming both the image has been drawn then create an Image Ref for that CGImageRef pFinalImage = CGBitmapContextCreateImage(context); CGContextRelease(context); return pFinalImage; /* to be released by the caller */ } 
+6
source

Source: https://habr.com/ru/post/1379635/


All Articles