画面上でマウスの位置を設定する必要があります。他の同様の質問では、 を使用することが提案されましたがCGDisplayMoveCursorToPoint(CGDirectDisplayID display, CGPoint point)
、 を取得する方法がわかりませんCGDirectDisplayID
。CGDirectDisplayID
マウスの位置を設定する方法または別の方法を教えてください。
3155 次
6 に答える
3
試してみてくださいCGWarpMouseCursorPosition()
。ディスプレイ ID は必要ありません。
表示 ID が必要な場合は、任意の基準を使用して、 によって返される配列から要素を選択できます[NSScreen screens]
。-deviceDescription
そのNSScreen
オブジェクトを呼び出します。返されたディクショナリから、-objectForKey:
keyで呼び出します@"NSScreenNumber"
。
于 2012-04-21T11:51:42.840 に答える
1
キック用のSwiftバージョンは次のとおりです。
let pt = CGPoint(x: 100, y: 10)
let moveEvent = CGEventCreateMouseEvent(nil, .MouseMoved, pt, .Left)
CGEventPost(.CGSessionEventTap, moveEvent);
于 2016-09-07T03:37:27.523 に答える
1
これを行う方法は次のとおりです。
// coordinate at (10,10) on the screen
CGPoint pt;
pt.x = 10;
pt.y = 10;
CGEventRef moveEvent = CGEventCreateMouseEvent(
NULL, // NULL to create a new event
kCGEventMouseMoved, // what type of event (move)
pt, // screen coordinate for the event
kCGMouseButtonLeft // irrelevant for a move event
);
// post the event and cleanup
CGEventPost(kCGSessionEventTap, moveEvent);
CFRelease(moveEvent);
これにより、カーソルが画面上のポイント (10,10) (左上、Apple メニューの隣) に移動します。
于 2012-04-21T03:49:06.063 に答える