LoginSignup
0
0

More than 5 years have passed since last update.

Duet Displayを使っていてマウスの座標がうまく取得できない時の対処法

Last updated at Posted at 2015-04-12

oF+Duet Displayで簡易キオスク的なアプリを作っていると、クリック関連イベント(mousePressed,mouseReleased)の座標がうまく取れないことがある。イベント自体は発行されるものの、座標が前の位置から更新されておらず、前の場所をクリックしたことになってしまう。
ドラッグした場合はちゃんとマウス座標を取得できるので、軽くドラッグしてからタップし直すとちゃんと動く。

なんとなく調べたところ、GLUTのマウス周りで問題が起きてるらしいので、直接Cocoaから取得する方法。

void mousePressed(int x, int y, int button){
    cout << "mousePressed : " << x << ", " << y << endl;
    CGEventRef event = CGEventCreate(NULL);
    CGPoint cursor = CGEventGetLocation(event);
    x = cursor.x-ofGetWindowPositionX();
    y = cursor.y-ofGetWindowPositionY();
    cout << "mousePressed(modify) : " << x << ", " << y << endl;
}

CGEventGetLocationで画面内でのマウス座標を取得して、ウィンドウの位置で補正する感じ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0