Beginner grab screen problem, its possible?

Hi all! I’m trying to grab screen like cmd+shift+3 but each time that I made click with the mouse. I have tried and I arrive to this code. I try also with savescreen of Utils but I don’t arrive. The question is that I want that the program runs in a second plane, so I can navigate in my computer and each time I made a click with the mouse, the program capture the windows (I know that with this code it only capture 300x180px of the window, but its not a problem) Its that possible? I also try (like you can see in the code) to put the code in update lke a read in some post but it doesn’t work.
The mission is grab all the screen changes that I make in one day for a projection, any idea??

#include "testApp.h"  
void testApp::setup(){	   
	snapCounter = 0;  
	bSnapshot = false;  
	memset(snapString, 0, 255);		// clear the string by setting all chars to 0  
void testApp::update(){  
	if (bSnapshot == true){  
		// grab a rectangle at 200,200, width and height of 300,180  
		char fileName[255];  
		sprintf(fileName, "snapshot_%0.3i.png", snapCounter);  
		sprintf(snapString, "saved %s", fileName);  
		bSnapshot = false;  
void testApp::keyPressed  (int key){   
void testApp::keyReleased(int key){   
void testApp::mouseMoved(int x, int y ){  
void testApp::mouseDragged(int x, int y, int button){  
void testApp::mousePressed(int x, int y, int button){  
void testApp::mouseReleased(int x, int y, int button){  
	if(x > 1){   
		bSnapshot = true;  
void testApp::windowResized(int w, int h){  

It’s me again, only one aclaration, now it works, but only when I’m in the program, I take an example of the OF folder, all that I need it’s know how the program can continue working when it is in the background…I don’t know if the explication it’s ok or if it’s not from beginner forum (I’m sure that I’m a beginner but I don’t if the question also are). Sorry for my english.

hi, surely you are doing something in the draw method now? everything in draw want work when the app is for example minimized. try moving everything to update.

Hi Arturo, thank for the reply.
If you see the code that I posted above all is in update, not in draw…I think update works if you realize something like count numbers or parameters but not something that need interaction, like me with my mouse or press any key when the program it’s in the background…it’s only a suposition…i’m right? wich solution can I have?

ah, sorry didn’t understand, yes, you cant receive mouse/key events unless they’re directed to the application. for that you will need to use the api corresponding to your os. which os are you using?

Don’t worry…my english is very bad, I use Mac system but I want use it in different versions, is that a problem? I’m progrmaing the app with a Mac OsX system 10.6

yes, this is totally system dependent, you will need to program different versions for each os. take a look at kyle’s keytweeter:

for some code on how to read keys in windows.

i have some key/mouse loggers for the 3 platforms, but not here. will look for it and post it

Thank Arturo! I will see and try with this link when I arrive at home and I tell you, if you have this loggers that you say in mac sure that this will help me a lot.

Hi again Arturo, I was looking the kyle’s keytweeter and I take this poor conclusions: The program has 2 steps:

  1. An API who is executed with cURL (I think It will be Terminal in my case), this API control each time that he log a key (In my case make click with my mouse)

  2. He use ofxThread addon of theo to do the posting and keylogging asynchronously with the program (In my case, this program will can grab screen, create a name and save the file), all this second step its operated in ofw.

So with that I realise that one of the biggest problem is create a mouse logger that runs on mac (1.5 in my case, no 1.6) ok! I have no idea so I take from google code one keylogger called logkext and started opening and reading the code, I found the file who control the keys but now I’m bloqued. It’s no useful for me because I need a mouse logger that I don’t find and an example to synchronize between Terminal and ofw…do you have idea where I can read or have one to modify?


i don’t have the hard disk where i have the linux and mac key/mouse logger and i’m not going to be back till thursday, but drop me another message by then and will send you what i have.


Ok, thanks! I will continue playing with my keylogger API (For learn more about) and continue working on it, thursday I will send you a message.


Hi Arturo! I write you for know if you have (and if isn’t a problem for you) the mouse events logger for Mac that we have mentioned above.
I discover this days ‘Handling Mouse Events’ of Mac OS Reference Library, I found also NSLeftMouseDown event (I think I need this one) and also I was downloading some open code programs…
Sincerely, I don’t find the clue for make a keylog, I was investigating to log the events and pass it for the Terminal because is the solution that I think is the good one, but I don’t know how pass the events to the terminal and after capture them with OFW…after that I think the rest it will be easy, but the keylog it’s difficult for me to understand.