ofGetMouseX(), ofGetMouseY() only update after clicking

Hi, I ve some problems with some bacic things… :confused:

I´ve loaded a picture and tried to draw it always at the position of the mouse cursor, but the position of the picture only change, while clicking the mouse. I have no idea why… :open_mouth:

Here my code:

float posX, posY; ofImage myImage;


posX = ofGetMouseX();
posY = ofGetMouseY();

myImage.draw(posX-64, posY-64)

I also have tried it without the update()-function, but also with the same (wrong) result.

BG and thank you :slightly_smiling:


It’s very weird.

You can try [ mouseX , mouseY ] instead [ ofGetMouseX() , ofGetMouseY() ] directly.

So. How about this:

    myImage.draw(mouseX-64, mouseY-64)

Additional comment :
You should check that Mouse Signal is actually able in draw().

cout <<"case1 : " << posX << " , " << posY << endl;
cout <<"case2 : " << mouseX << " , " << mouseY << endl;

Thx for the answer!

I´ve tried mouseX and mouseY and also to print the values every frame. Both variables (posX/Y and mouseX/Y) have the same values and only update while clicking on any mousebutton… so the drawing function works correctly, but the variables for position dont change… :confused:

I also want to set the cursor on a specific position with SetCursorPos(), but I cant find this function, I included Windows.h

Ok, I “know” why it is not working. I´m using the Kinect, and downloaded a Kinect-Version. With the “original” version of openFramework is everthing ok :slightly_smiling:

oh! Solution your self while I writing reply . fine.

and, Can I comment that " GetCursorPos() " , If you don’t mind.?

ok. ^^;

This is it (for only windows)

#include "ofApp.h"
#include <Windows.h>

HWND handle = NULL;
void ofApp::setup(){

	//get app windows handle
	handle = WindowFromDC(wglGetCurrentDC());
	cout << handle << endl;

void ofApp::draw(){

	cout << endl;
	cout << endl;
	cout <<"win pos : (" << ofGetWindowPositionX() << " , " << ofGetWindowPositionY() << " )" <<  endl;
	cout << "mouse pos : (" << p.x << " , " << p.y << " )" << endl;
	cout << "relative pos : ( " << p.x - ofGetWindowPositionX() << " , " << p.y - ofGetWindowPositionY() << " )" << endl;

also, this method is able to check out of app windows mouse position.
just get pure desktop screen coordinate from cursor.

and you can also use SetCursorPos(…), It can move mouse position by app.
(forced hook windows user.)

Thanks whatever. :sweat_smile:

1 Like

Thanks for this tip! I´ll try it too :slightly_smiling:

BG Epi