Hello,
I am trying to create an application that when the color of a pixel on screen changes to another one (that I know what it is) it does something, doesn't really matter to the question what it does.
Anyway, I am using this:
CGImageRef window283x420 = CGWindowListCreateImage(NSMakeRect(284, 420, 1, 1), kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
NSBitmapImageRep *cannonOne = [[NSBitmapImageRep alloc] initWithCGImage:window283x420];
Then, the color I am expecting it to change to here:
NSColor *color = [NSColor colorWithCalibratedRed:0.521569 green:0.380392 blue:0.231373 alpha:1];
And am comparing the colors here:
while (![color isEqualToColor:[cannonOne colorAtX:0 y:0]]) {
CGImageRef window283x420 = CGWindowListCreateImage(NSMakeRect(284, 420, 1, 1), kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
NSBitmapImageRep *cannonOne = [[NSBitmapImageRep alloc] initWithCGImage:window283x420];
if ([color isEqualToColor:[cannonOne colorAtX:0 y:0]]) {
I know the while/if part could be done better, but it should work just fine and not worrying about optimizing the app until it actually works lol.
Now, if for example the color of the pixel doesn't actually change fast (like the color stays like that for a bit) it works perfectly. If it is like a pixel with a color that moves around and reaches 283*420 but doesn't stay there for long (like 0.1s) (as described in the example above) it doesn't work.
The time it stays there shouldn't be a problem, as my app is checking the pixel really fast, as seen in the debug here:
2010-01-04 22:12:58.230 appname[2372:a0f] Checked
2010-01-04 22:12:58.231 appname[2372:a0f] Checked
Any ideas? :)